January 2016

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

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

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