WordPress – query to find term_taxonomy_id from tag name
Mysql query – Find term_taxonomy_id for a tag name Use the following query to find term_taxonomy_id for a tag name after replacing “PHP” with the read more
WordPress – query to find all posts for a category
Find term_taxonomy_id for a category name Use the following query to find term_taxonomy_id for a category name after replacing “Tutorials” with the category you want read more
Apache – how to remove php extension from url
Remove php extension from a specific url To remove php extension from a url (e.g. /foo/bar.php) the following Apache rewrite rule can be used: RewriteRule read more
Mysql – how to copy a table
Cloning table with indexes/triggers and data First create new table with same structure. We’ll use wordpress table wp_posts for the purpose of this tutorial. mysql> read more
PHP json_encode string online
This form can be used to encode a string using php json_encode function. Note that outcome will be enclosed in quotes (“”).
WordPress – get wpdb class method names
get wpdb class method names using get_class_methods Here is the outcome from above code:
PHP – get class name and file name from an object
PHP – get class name of an object get_class with object as arguments returns its class name. PHP – get filename from class name Here read more
Javascript array forEach
Few notes on Javascript array forEach Array arr is passed to function as local variable a Array arr is also available in function here as read more
Javascript check if variable is defined
Code snippet to check if a given javascript variable is defined. This also covers a variable having null value and non existing entry in an read more
Javascript syntax check online
Javascript syntax check – check if syntax of given javascript code is valid and see errors online. Sample javascript code Valid javascript code example var read more
Rsync – using dryrun to list changed files
Use rsync dryrun (-n) with -i (or –itemize-changes) to list changed files. $ rsync -n -i -a ./dir1 ./destdir/ cd+++++++ dir1/ >f+++++++ dir1/file1.php >f+++++++ dir1/file2.php read more
Javascript for-in loop to iterate over keys of javascript object
for in loop over javascript associative array for in loop over javascript DOM object
Python – dictionary get key with default
Get dictionary key with default if not found using method get() This is better approach in most cases. Get dictionary key using square brackets ([]) read more
Mysql – get total queries since beginning
Total queries on mysql prompt: mysql> SHOW STATUS like “Queries”; +—————+——–+ | Variable_name | Value | +—————+——–+ | Queries | 278583 | +—————+——–+ 1 row read more
WordPress – get posts/pages with missing meta key
Get post_type page with missing meta_key Get post_type post with missing meta_key
PHP beginning and end of string regex examples
Php regex can use caret (^) for matching from beginning of string and dollar ($) for end of line. Here are some examples using preg_replace. read more
PHP remove non printable characters from a string
Regex to remove non printable characters from a string Space is first printable char and tilde (~) is last printable ascii char. We replace any read more
Ascii printable characters
ASCII printable characters – octal, hexadecimal, decimal values of printable ascii characters. printable ascii characters
PHP – take last n characters of a string
Take last 3 characters when string is big enough Take last 3 characters when string is smaller than 3 chars
PHP array foreach – code snippets
PHP array – foreach loop on values PHP array – foreach loop on index,values PHP array – foreach loop for modification PHP associative array – read more
Curl with download/upload rate limit – code snippets
Curl with rate limit (both download and upload bandwidth) to 1 KBps (1 kilobytes per second) $ curl –limit-rate 1K https://infoheap.com/ > out.html // or read more
document querySelector examples
Javascript querySelector() and querySelectorAll() can be used to get DOM element based on given CSS selector. These works on document and element objects both. querySelector() read more
Bash – local and global variables
Bash functions can have local variables. This can protect the accidental modification of global variables when function is called inline within same shell. Here are read more
Python lint (syntax check) online
Python lint check – check if syntax of given python code is valid and see errors online. Sample python code Valid python code using print read more
Php lint (syntax check) online
Php lint check – check if syntax of given php code is valid and see errors online. Sample valid php code Simple php code using read more
Php look ahead and look behind regex examples
Look ahead and look behind can be very useful to match a pattern which is followed, not followed, preceded or preceded by a certain pattern. read more
How to do svn log of entire repository
svn log can be used to show the log messages for a set of revision(s) and/or path(s). Here are some ways to do svn log read more
python print examples
Here are some examples you can print strings or variables in python on stdout. Print a string with newline in the end By default python read more
Python for loop examples
Frequently used python for loop examples. For loop to iterate over a list Iterate on each element of a list Iterate on each index, element read more
php preg_match – greedy and lazy regex examples
Php preg_match (preg_replace) can have greedy (default) or lazy regular expressions. Lazy match is done as soon as a valid match is found. Greedy match read more
bash – how to use regex in if condition
Bash built in double square brackets can be used for regex match in if condition. This can be pretty powerful and can be used in read more