CSS border radius and round corners examples
CSS3 border-radius property can be used to make corners round of a block element. Border radius can have upto 4 values. Here is how a read more
Run nginx in docker container
Docker can be used to run nginx in a container. We’ll use Ubuntu Linux (14.04.2) for the purpose of this tutorial. This tutorial assumes that read more
Chrome extension tutorial – access active page dom
This Chrome extension tutorial will cover building a basic hello world chrome extension where clicking on extension icon will open a popup window containing active read more
CSS ::before and ::after examples
CSS pseudo element ::before and ::after (CSS 2 syntax :before and :after) can be used to place some content before or after an element. Most read more
How to get docker container IP
Docker inspect can be used to get information including IP address about a container using its id or name. $ docker inspect [container_name_or_id] To get read more
Docker container – handy commands
Some handy command to work with containers. We’ll assume a docker image ubuntu is available on current machine. Run interactive shell (or any other command) read more
Linux – how to remove user from a group
To remove a user from a group on Linux, one can use gpasswd or deluser. Here are sample commands. Using gpasswd To remove user1 from read more
Docker how to add a user to group docker on Linux
It is a good idea to add a user to docker group. In case user is not added to docker group, you may see the read more
Docker quick start guide on Ubuntu
Docker is an open-source project that automates the deployment of applications inside software containers. Here is Docker quick start guide on Ubuntu Linux. We’ll use read more
How to resubmit robots.txt to Google
An error in robots.txt can cause Google to stop crawling a section of your site. In such case it is good to update and resubmit read more
Command line – top IP list from apache access log
Linux (or Unix) command line utilities like awk, sort, uniq, can be used to analyze apache log to get interesting stats. One use case is read more
Create gmail filter from search
In case you get lot of emails, its useful to create gmail filters to apply labels automatically and optionally archive matching emails. Gmail search can read more
Chrome extension tutorial – hello world
Chrome extension is very powerful feature of Chrome browser and an extension can be very useful for performing various activities on a web page. This read more
Chrome – how to access pre-release features
If you want to access pre-release features of Google Chrome, you can download Chrome Canary which is usually few versions ahead of stable Google Chrome. read more
View http headers in Chrome
Chrome developer tools can be used to view browser HTTP request and response headers when browser loads a page or makes AJAX calls. Here are read more
PHP – how to use function static variable as cache
PHP function static variable exists only in a local function scope but it does not lose its value after function execution. It can be used read more
Chrome extensions – how to enable developer mode
If you are building Chrome extensions and want to load extensions from directories, you need to enable Chrome developer mode for extensions. Here are quick read more
Bash – how to find last command exit status code
When writing bash scripts or running something on command line, last command exit code status is stored in environment variable $?. It can also be read more
Bash – how to redirect stderr to stdout or file
On Linux or Unix, error from a command (stderr) can be redirected to stdout or a file. These are the file descriptor id used on read more
PHP remove trailing whitespaces and newline
PHP has inbuilt function rtrim to remove specific or all trailing whitespaces from end of php string. preg_replace can also be used for this purpose. read more
PHP execute command and capture shell exit status
PHP exec and shell_exec can be used to execute a shell command on server side. exec also populates shell exit return status in one of read more
How to do grep without regex (fixed string)
Linux (or Unix) grep without any options does a regex grep on input stream. To disable regex either one can use grep -F or fgrep. read more
Python map examples
Python map is very useful built-in python function to achieve complex stuff over a list in very short and elegant way. Note that map applies read more
AngularJS controller basic clock example
Angularjs basic controller clock example to display date and update it every second. We’ll use controller, template and $timeout. We used AngularJS $timeout here. If read more
AngularJS simple controller tutorial to increment a value
Angularjs basic controller example to initialize a number in view, and then increment it on button click. We’ll use controller, template and ng-click directive. The read more
PHP regex – whitespace shorthand (\s) regex examples
PHP regex whitespace shorthand \s can be used to match whitespace characters. These are the characters it will match. Char Dec val Oct val tab read more
HTML5 shadow dom example
HTML5 shadow dom is part of Web components. It is currently in draft stage and supported by Chrome. It can also be compared with react read more
HTML5 template tag hello world tutorial
HTML5 template tag can be used to define template in html and instantiate it when needed. The instantiated template can be inserted in any DOM read more
Javascript – how to view text inside DOM element
Javascript DOM method textContent can be used to get the text content inside a DOM. This can be useful to obtain content from a web read more
Javascript – DOM appendChild example
Javascript DOM method appendChild can be used to append a child to existing DOM element. For example it can be used to append an Image, read more
CORS – cross origin request tutorial and example in PHP
CORS (cross origin resource sharing) can be used to make AJAX requests to different origins. Here are some points to note: CORS un-aware browser will read more
PHP – call a function with arguments in array examples
PHP call_user_func_array() can be used to call a function with arguments in an array. This gives us the flexibility to pass variable number of arguments. read more
PHP – get function arguments examples
PHP func_get_args(), func_get_arg() and func_num_args() can be used to retrieve php function arguments inside a function. This may be useful in debugging. Here are code read more
Javascript DOMContentLoaded listener example
DOMContentLoaded event is fired when document DOM is ready and before images, etc. are loaded. It is similar to jQuery $(document).ready(). Here is code snippet read more
Javascript – ready vs on load event handler example
HTML document ready event is called before image assets, etc. are loaded on the page. window onload handler is called once all assets have been read more
PHP – get calling file name and line number using debug_backtrace
Sometime it is useful to log the calling filename and line number details of the calling file/function in php. One common use case if to read more
Javascript – img onload examples
Sometime we need to call a function after an image has been loaded. We can attach onload even handler on image either in html itself read more
Multiple onload handlers using vanilla Javascipt
Attaching a function to windows on load event can be done in multiple ways using plain vanilla Javascript. One option is to use wondow.onload where read more
Javascript – use querySelector to set dom element html
Javascript querySelector can be used to select and set html of a dom element using css selectors. This can be done with jQuery also. But read more
Python value in array (list) check
In Python we frequently need to check if a value is in an array (list) or not. Python x in list can be used for read more
Python string split examples
Python has in-built string split function which can be used to split a string on any delimiter and return a python list (array). If no read more
Python string quick start tutorial
Python built-in data type string is very frequently used in any python program. Here are some examples of using strings to get started with. Print read more
Linux – find and delete files older than 30 days
Often we need to delete old file on Linux or Unix which are old (say 30 days or more). Here are some commands which can read more
Gmail – how to find large size emails
Gmail can get full very soon with heavy file attachments being very common these days. In case your need to clean your gmail mailbox, easiest read more
PHP check if key exists in array
Checking if a key exists in an array and possibly has a non empty value are frequently used when writing php code. Accessing value of read more
PHP check if string contains something
Checking if a string contains a substring is very frequently occuring use case in PHP code. PHP functions strpos or stripos (case insensitive version) can read more
robots.txt disallow all example
Sometime we need to block all robots from crawling a web site. This can be needed if you have a stage or sandbox website for read more
PHP – check if a value is in array
Checking if a value exists in array is frequently used in php. PHP in_array() can be used for this check. By default it does not read more
How to use wildcard in robots.txt
By default Disallow entry in robots.txt is based on url prefix. To block every url beginning with /foo/ the following robots.txt can be used. User-agent: read more
WordPress mysql query to get all posts with a missing custom field
Handy mysql query to get all posts with a missing custom field. We’ll query post_type=page for the purpose of this tutorial. You will have to read more
PHP – split string examples
Splitting a string/text at a delimiter is very common use case in php. One can either use php explode (split on a fixed delimiter) or read more
Chrome – how to find a plugin directory location on Mac
It may be useful to look at Chrome plugin code at times for debugging purpose. Chrome plugins are stored in the following directory (for user read more
PHP regex – word boundary examples
Php regex can use word boundary character (\b) to match a word boundary. Beginning of string if following by a word character will also match read more
Perl command line – replace multi line comments
Perl command line one liner can be used to replace text in a file using regular expressions (regex). It is very powerful approach for automating read more
AngularJS hello world example
Angularjs is a web application framework which has gained lot of popularity in mobile and single page applications. It uses directive ng-app to represent root read more
Css :last-of-type selector – last child element of type
Css :last-of-type pseudo class apply to an element if it is last sibling among its parent’s direct child elements of same type. Here is an read more
Css :last-child selector – last child element
Css :last-child pseudo class apply to an element if it is last sibling in all direct child elements of its parent. It can be used read more
Docker quick start guide on Mac
Docker is an open-source project that automates the deployment of applications inside software containers. Here is Docker quick start guide on Mac. Install docker toolbox read more
Css :first-of-type selector – first child element of type
Css :first-of-type pseudo class apply to an element if it is first sibling among its parent’s direct child elements of same type. Here is an read more
Css :first-child selector – first child element
Css :first-child pseudo class apply to an element if it is first sibling in all direct child elements of its parent. Here are some examples. read more
Css :nth-child vs :nth-of-type
Css :nth-child and :nth-of-type pseudo classes look very similar initially. But these are slightly different. Few points to explain the difference: :nth-child considers all sibling read more
Python filter vs ifilter
Python filter is very handy python built-in function to filter iterables (e.g. lists) in python. But it returns a list which may consume huge memory read more
Jenkins – how to setup build cron
Jenkins supports setting build triggers using Jenkins crons. This way build will run at regular interval and possibly Jenkins can send email on failure. Here read more
Mysql how to dump schema of all databases
It is a good idea to frequently take schema dump of all your databases. This may be useful in case there is some accidental change. read more
Python filter list/iterable examples
Python filter is very useful built-in python function to achieve complex stuff over a list in very short and elegant way. Note that filter applies read more
Jenkins execute shell – how to continue on error
In case can you are using Jenkins shell commands to run tests and are running multiple commands, by default Jenkins exits the comment one shell read more
Selenium Phantomjs – check browser errors using pytest
Checking browser errors (including Javascript errors) is an important use case in testing a website. Javascript errors are hard to QA and can cause bad read more
Javascript – iterate over function arguments
Sometimes it is useful to iterate over function arguments programmatically. Function arguments can be access using arguments variable. Here is code snippet for this. Note read more
Jenkins – how to setup build failure email
Getting email of a build failure is a common use case in Jenkins. We would want to get notified whenever any build fails and when read more
PHP – Regex OR (alternation) examples using pipe
Regex OR (alternation) in php can be matched using pipe (|) match character. This is very frequently used in regular expressions. Following are some ways read more
Python selenium – print browser log (including javascript errors) with phantomjs
It is useful to find out javascript errors in a page automatically. This can help in site quality test automation. Here is selenium code snippet read more
Bash – how to compare file timestamps
Sometimes we need to perform some action if a file is newer than other file. This can be used to recreate generated file if source read more
PHP – How to log custom data in apache access log
Apache lets you log a specific apache sub process environment variable in access log. PHP lets you set apache sub process env variable using apache_setenv. read more
Linux – find files containing specific text
Handy command on Linux/Mac to find all files matching a pattern containing a specific text. This will also print file name. $ find . -type read more
Jenkins how to clone a project
Sometimes we need to create a replica of a project or project with similar configuration in Jenkins. This helps in avoiding entering project configuration data read more
PHP – preg_replace back reference (in replacement text) examples
Sometimes we need to use back reference in PHP preg_replace to put back the matched pattern. One example can be if you want to append read more
Css source map example using gulp-sourcemaps
If you are concatenating multiple css files into once css file, it is useful to have sourcemap in your combined css file in development environment. read more
Gulp quick start tutorial
Gulp is a toolkit to automate tasks primarily in web development workflow. It can automate things like css/js minification, concatenation, etc. Here is quick tutorial read more
LXC (Linux Containers) – quick start tutorial on Ubuntu
LXC (Linux Containers) is an operating-system-level virtualization environment for running multiple isolated Linux systems (containers) on a single Linux control host. Here is a quick read more
jQuery – find total number of DOM elements
To get total DOM elements including children use the following code (this includes root html element also) $(‘*’).length To get all DOM elements in body read more
WordPress – how to exclude specific tag posts from a tag archive page
WordPress will display all posts on a tag archive page which are tagged with that tag. Sometimes we want to exclude posts of more specific read more
How to disable spellcheck in textarea
It is a good idea to disable spell check in textarea element if it is not meant for pure english text. To disable spell check read more
Vim – how to change current character case to uppercase or lowercase
It is often required to toggle the case of current character in Vim. Vim has lot of other powerful commands related to changing case of read more
PHP – how to catch errors using set_error_handler
PHP set_error_handler can catch various type of php errors in a specific portion of the code. To restore the previous error hander one can call read more
awk sum examples
Here are some awk examples to sum an integer column from a file or stdin (standard input) stream. Data used in these examples Awk sum read more
awk – if condition examples
Awk is pretty powerful command line utility to filter lines from a stream. Here are some awk if condition examples. Data used in these examples: read more
Dig – list all dns records
To list all DNS records of a domain name use the following dig command (after replacing microsoft.com with desired domain) $ dig microsoft.com any ;; read more
Svn – how to diff last committed change
To see the diff of last committed change follow these steps: Find last revision id $ svn update $ svn log -l 1 r4546 | read more
Svn – short diff without context
Using svn command line option Use the following diff command to avoid diff context $ svn diff –diff-cmd=diff -x -U0 Option -x passes option -U0 read more
Bash – add a number to a variable
To add a number to a variable in bash, there are many approaches. Some of these are: Declare variable as integer Once a variable is read more
Vim – highlight and move to matching bracket
To find and move to matching bracket (curly, square or round) use the following command inside vim once you are in one of the brackets. read more
How to override priority and change frequency in Yoast xml sitemap
It is important to maintain healthy xml sitemap for your site. In case you are using Yoast SEO plugin to generate xml sitemap for a read more
WordPress – customize posts per page for tag, category and date archive pages
The following code can be used to have separate value of posts per page for various archive pages (category, tag, date, author, etc.)
Php regex delimiter examples
PHP requires regex patterns to have valid delimiters around it. Some languages may not require delimiters (e.g. python). To make code more readable, sometimes we read more
Svn – how to edit log message for a committed change
Command to edit a committed revision Example command for revision r4448 $ svn propedit svn:log –revprop -r r4448 hook setup for allowing editing log message read more
WordPress – customize category and tag links
In case you need to create a custom link for category or tag, the you can term_link filter. This can be useful in case you read more
Svn log of all files in a directory
Sometime we need to see svn log of all files in a directory (including all files in all its subdirectories). Here are some approaches. Using read more
PHP – convert array to associative array
Convert using array_flip() This works if we need index as value. Using foreach iterator In case we need to set associative array value using array read more
PHP – how to initialize static variables
Sometimes we need to populate static variables in php (e.g. populating associative arrays from existing arrays). Easiest way is to define a static function (e.g. read more
Bash associative array tutorial
Bash associative arrays are supported in bash version 4. Here is a quick start tutorial for using bash associative arrays. Declare and initialize associative array read more
WordPress – query to find term_taxonomy_id from category name
Mysql query – Find term_taxonomy_id from category name Use the following query to find term_taxonomy_id for a category name after replacing “Tutorial” with the category read more
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
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
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
Bash – how to run custom commands at script exit
Bash scripts can trap EXIT signal and run clean up commands before exit. This is useful if a user kills a script or the script read more
How to display a div in browser window center
To display a div in browser window center we can use css position value fixed. The left and top value of fixed position are relative read more
Install and setup Jenkins on Ubuntu Linux
Jenkins is an open source continuous integration (CI) tool written in java. It can be used to run (on-demand or periodic) build and test jobs read more
Gmail – how to send email from different address
Gmail can be used to send email as different address. It can be handy if you want to use your primary account to receive and read more
How to display auto fade out message using jQuery
Sometimes we need to display a message and then fade it out. jQuery fadeOut will make an element fadeOut (by animating css property opacity) will read more
Bash – how to get main program and current file dir location
Get main program directory location In case you have a program main.sh in /opt/tmp which includes utils.sh from /opt/tmp/dir1, then this code will return /opt/tmp read more
Javascript – catch errors using window.onerror
Javascript errors can be caught using window.onerror event handler. Whenever a javascript error occurs browser calls this function. In this tutorial we’ll write error handler read more
NodeJS – npm beginner tutorial
Npm (Node package manager) is used to install/uninstall and manage node packages. Here are some common commands when using npm on command line on Linux read more
How to install Imagemagick on Ubuntu Linux
Use apt-get to install imagemagick $ sudo apt-get install imagemagick List binaries in imagemagick $ dpkg -L imagemagick | grep bin /usr/bin /usr/bin/conjure.im6 /usr/bin/composite.im6 /usr/bin/import.im6 read more
Python selenium – execute javascript code
Selenium code in python can execute custom Javascript and also return values from webdriver (PhantomJS, Firefox, Chrome. etc.) context. Here is sample code which counts read more
Bash – how to use functions – quick tutorial
Using functions in bash is fairly useful to organise and reuse code. Here is quick beginner tutorial with examples on using bash functions. Declaring functions read more
How to install node.js on Ubuntu Linux
Update node source $ curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash – Check which nodejs will be installed $ apt-cache policy nodejs nodejs: Installed: (none) read more
How to install Imagemagick on Mac
Use brew to get information on latest imagemagick version $ brew info imagemagick imagemagick: stable 6.9.2-8 (bottled), HEAD Tools and libraries to manipulate images in read more
Mac brew – how to find latest available package without installing
Find available packages on Mac using brew $ brew search [package name] $ brew search lua lua lua51 luabind luajit homebrew/emacs/lua-mode homebrew/nginx/lua-nginx-module homebrew/versions/lua53 Get info read more
Mac – how to change default location for screenshots
Mac screenshots are saved on Desktop by default. It can cause Desktop to get cluttered very fast. Here are the steps to change default screenshot read more
Python pytest – using selenium with PhantomJS
Here is quick tutorial to use python selenium with PhantomJS as driver. We will fetch a page and assert that page title has certain keyword. read more
Mac – how to take screenshots
Mac supports full screen, window and a specific selection for taking screenshots. You can either store screenshot in a file on Desktop or in clipboard. read more
PHP echo – comma (,) vs dot (.) performance benchmarks
PHP echo allow comma (,) for concatenating various values in addition to dot (.). This works only for echo though. It is sometimes discussed comma read more
Bash – how to check if a variable is set
To check if a variable is set or empty, we can use couple of approaches. One approach is to use empty string check (if [ read more
Bash – iterate over array
These are few ways of iterating on bash arrays to read and or modify array’s elements in bash on Linux or Mac. Here are some read more
Can global variables be modified in bash function?
Global variables can be accessed in bash function without declaring anything and when these are modified the behaviour depend on whether function is called in read more
Install Amazon EC2 api tools on Ubuntu Linux
Amazon EC2 api tools have fairly handy utilities to get information and perform various AWS tasks on your instance. Here are quick steps to install read more
Bash – set default value if a variable is empty
There are multiple ways to check if a variable is empty and then set it to some default value. Shell parameter expansion gives us an read more
How to setup password less git push for github
You can use user and password based authentication to push git changes to GitHub. But it is cumbersome to type user and password with every read more
How to create ssh public/private keys on command line
Command line utility ssh-keygen can be used to generate rsa or dsa public and private keys. By default it generates rsa keys. Here are commands read more
Generate ssh public key from private key on command line
In case you have lost your ssh public key, you can re-generate it from the private key you have. Here is the command to generate read more
CSS – how to align image and text in center vertically
We frequently need to center text and images when we are writing HTML/CSS. This can be done by using vertical-align:middle property on the child element read more
Mac – how to copy, alias, move using drag/drop and mouse pointer indicators for these
We frequently use drag and drop on Mac for copying, creating alias/shortcut or moving files from one folder to another. Mac shows very good mouse read more
Bash – variables in double quotes vs without quotes
Bash variables without double quotes can give surprising results. The special characters inside a variable when not double quoted, gets interpreted by bash. Few points read more
Bash – newline and other escape character in string
To have newline (\n) and other escape characters in bash strings, we can use $’string’ syntax (ANSI-C Quoting). $’string’ expands to string, with backslash-escaped characters read more
Bash – append text to a variable
Variable in string approach Use curly braces {} around variable (${VARNAME}) in case text begins with alphanumeric character. Concatenate variable with string Use =+ operator read more
Why and how to use Amazon route53 as DNS
Using Amazon route53 has a huge advantage that it offers a TTL of as low as 60 seconds. This means changing IP for your domain read more
Mac VirtualBox – enable copy paster from/to Windows 10
If you are running Windows 10 inside VirtualBox, you may want to enable copy/paster from windows and vice versa. This tutorial should work on any read more
Javascript – dump all handlers on window object
DOM window object has many javascript event handlers attached to it. It may be handy to dump and view all of these. Here is code read more
Curl – how to hide progress bar
Curl by default shows progress bar. To hide it -s option can be used. We can also add -S to show errors when -s option read more
Bash – how to stop at error
To stop a bash script at first error use set -e. To undo it use set +e.
Linux – sending mail from command using mailutils
Linux command line tools to send mails are very handy for sending mails from bash scripts. As an example you can send daily php error read more
How to view wordpress current version
If you want view the version of currently installed wordpress for a site, here are few approaches. View version using dashboard glance section If you read more
How to debug :hover in Chrome
At times we need to force hover state when we are debugging CSS in style inspector in Chrome developers tools. Chrome supports forcing a certain read more
PHP – convert dos newline to unix format
Files or strings in DOS format may have \r (carriage return) along with \n (newline). This may appear as ^M in some editors. Here is read more
HTML table with alternate color rows
We often need to display a table with alternate rows having different colors. We can do it either using CSS3 nth-child selector or using jQuery. read more
PHP – assign multi lines string to a variable
PHP supports Heredoc and Newdoc syntax. It is a convenient way to assign multiple lines string to a variable. This makes code more readable. Here read more
How to run windows 10 on Mac using VirtualBox
Windows 10 can be run in Mac using Virtualbox and Windows 10 OS trial image available from Microsoft’s site. Here are the steps to install read more
PHP – print array in one line
At times for large array values we want to log them in one line for better readability. Logging an array in one line is also read more
PHP – empty() vs isset() vs is_null() vs boolean check
PHP isset() and empty() are frequently used to check the values of variables. In some cases is_null is also used. Here is a table covering read more
Jquery – change table cells color based on value
It is sometimes useful to change color of table cells based on values for better presentation and readability. Here is quick code snippet to do read more
Mac – open Finder from terminal – quick tip
Often we want to open Finder window when we are working on Terminal. Here are few scenarios to open Finder window from command line terminal read more
Imagemagick – how to create animation on command line
Imagemagick is very powerful tool to process images on command line. If you have multiple images, you can use imagemagick convert utility on Mac or read more
PHP check if a filename is valid
Sometimes we need to check if a filename contains special character etc. One possible approach is to check for alphanumeric characters and few more characters read more
Mac – how to take timed screenshot
At times we need to take timed screenshots on Mac. Here are two approaches we can use to take timed screenshot on Mac. Screenshot using read more
Ubuntu – find file to package
Ubuntu dpkg-query can be used to find package name given a file name, its full path or partial name. Note that it does not follow read more
Mac Finder – how to search system hidden files
System files are hidden on Mac and they don’t show up in Finder search results by default. In case you end up searching stuff which read more
Bash – pass all arguments from one script to another
When writing a wrapper bash script, we often need to pass all arguments passed to the wrapper scrip to another script. Here is quick bash read more
WordPress – how to create custom tag cloud
WordPress has support for displaying tag cloud using wp_tag_cloud. It displays tag cloud and has support for including and excluding tags and specifying mininum and read more
Mac – search files on command line using mdfind
Mac spotlight and finder are great way to find files on Mac. But Mac also has command line utility mdfind (utility to query meta data) read more
How to enable telnet program on Windows 10
Windows does not have telnet program enabled by default. Telnet is a handy tool to check if a port is up or not at any read more
How to run a program as administrator on windows 10
Sometime we need to run a program as administrator to be able to perform root privileged tasks. e.g. Editing the windows hosts file is only read more
How to find python package’s file location
Here is simple python code snippet to see the file location of a python package on command line: $ python -c “import urllib2; print urllib2.__file__;” read more
How to auto forward gmail from one account to another
In case you have multiple gmail accounts you can forward email from one account to another. You can also choose to keep the forwarded email read more
PhantomJS – how to skip Google analytics code when fetching a web page
PhantomJS can be used to test websites and for automating various tasks. When testing a website in production, it may not be a good idea read more
WordPress mysql query to get all custom keys and values for a post
Handy mysql query to get all custom keys and values for a post in wordpress. SELECT wp_postmeta.* FROM wp_postmeta JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id read more
Curl – follow redirects
Curl is fairly handy command line utility to fetch a web page. It can also be used to automate various tasks in bash shell scripts. read more
How to crop an image using imagemagick convert
Imagemagick convert is pretty handy tool to manipulate images and can be used to crop an image. This can be useful in automation and also read more
How to check if a user has password on Linux
Any user created on Linux may or may not have a password. Linux stores passwords in encrypted format in /etc/shadow. Here is quick command line read more
Linux – providing sudo access to a users – some best practices
Giving sudo to a user is frequently occurring activity on Linux. Here are some scenarios and best practices for providing sudo to users on Linux. read more
WordPress how to check if a post is being viewed by admin
In WordPress you may want to do certain things only when admin user is viewing a post. Here is quick code snippet to know if read more
How to print javascript object to log
Often we need to print a javascript object to console log or somewhere else for debugging purpose. These are some handy ways to dump javascript read more
Phantomjs – how to check what resources are being requested by a page
Phantomjs lets you add hooks when it fetches a web page. Here is code snippet which can be used to print all resources phantomjs fetches read more
Bash check if file begins with a string
Bash code to check if file begins with a string Note the presence of double square brackets ([[ ]]) Bash code to check if file read more
Get file size in bytes on Linux
Sometime we need to get file size for the purpose of automation in bash shell script. Here are few ways to get a size of read more
Bash shell – check if file or directory exists
Bash code snippet to check if file exists FILE=/etc/passwd if [ -f $FILE ] ; then echo “$FILE exists and is regular file” else echo read more
How to compress screenshot images using imagemagick convert
Imagemagick convert can be used to compress and screenshot images by changing unique colors, image depth etc. Here are some ways to compress images created read more
Find image unique colors and bit depth using imagemagick identify
Print image unique colors and bit depth $ identify -format “UniqueColors: %k, BitDepth:%q\n” img1.png UniqueColors: 1694, BitDepth:16 Note that when can compress an image with read more