Tutorials

Find used ports by an app on Android using Adb

This article will cover steps to find used ports (on destination side) by an app on Android using adb command. We will use pixel-2 for read more

Install Android 8 on Pixel 2

This article will cover steps to install Android 8 on Pixel 2. The similar steps can also be used to install other Android versions in read more

Find top processes by memory/cpu on Android using Adb

This article will cover steps to find top processes by memory/cpu on Android using Adb. We will use pixel-2 for this article. But any other read more

Root Android pixel 2 using Magisk and boot image patching

Steps to root an Android Pixel 2 phone using Magisk and boot.img patching. Unlock bootloader Enable debug mode in Android if not done already Reboot read more

How to extract number from a string – google sheets

Sample usage to remove string prefix and extract remaining number in suffix.  The outcome will be

Linux iptables – Nat port forwarding using PREROUTING

One can use iptables to forward a specific port to another port using NAT PREROUTING chain. This can be used to make a server available read more

Install google camera on Asus m1 max pro

Google camera can be installed on Asus m1 max pro after enabling camera2api. The below steps are assuming you have a Mac machine with adb read more

Root Pixel 2 with Android Pie using TWRP and Magisk

The below steps are assuming you have a Mac machine with adb and fastboot tools and developer option and usb debugging is enabled on your read more

Android – install android 8, 9 from OTA images on pixel 2

The below steps are assuming you have a Mac machine with adb and fastboot tools installed and developer option and usb debugging is enabled on read more

Linux – number of cpus (lscpu)

Command lscpu to find number of cpus on linux $ lscpu lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 32 On-line read more

Android – enable system ui tuner

System ui tuner can be enable to Android Marshmallow, Nougat or Orio. It lets us customize more system ui settings on Android e.g. status bar read more

Python iterate dictionary

Iterate Python dictionary (associative arrays) Using keys It is not memory efficient for large dictionaries. Using values It is not memory efficient for large dictionaries. read more

Android – Show top processes using adb

To show top 5 processes by cpu $ adb shell top -m 5 -s cpu Sample outcome User 16%, System 3%, IOW 0%, IRQ 0% read more

WordPress – disable theme and plugin editing

Allowing theme editing from web can be prone to spam. To disable theme and plugin editor, add the following to wp-config.php define( ‘DISALLOW_FILE_EDIT’, true ); read more

Chrome enable webgl on old macbooks

Steps to enable WebGL on old MAcbook (e.g. later 2011) Visit chrome://settings and make sure under advanced settings > System > Use hardware available when read more

Mysql find slave lag

Command to find slave lag (on mysql slave): $ mysql -u root –password=PASSWORD -e “show slave status\G” | grep Seconds_Behind_Master Seconds_Behind_Master: 0

Git detached head

Create a detached head situation $ git branch * master $ git log –oneline 55fff69 v3 1fd2aa6 file1 $ git checkout 1fd2aa6 Note: checking out read more

Git – rename local branch

Git – rename local branch $ git branch -m oldname newname

Git display local HEAD location

Display HEAD pointer $ cat .git/HEAD ref: refs/heads/foo1 Display HEAD pointer (detached head case) $ cat .git/HEAD 1fd2aa6a8ff7205c91fde3d9557c6d67eeaf4eb1

Git display info of last commit (HEAD) in one line

Display last commit info from head in one line $ git log –pretty=format:”%h|%an|%ad|%s” -1 97d79ec|Dave Methvin|Mon Nov 9 17:49:01 2015 -0500|Dimensions: Empty sets should return read more

Git – display specific length commit hash

Display last commit from head to with specific commit hash length $ git log –pretty=format:”%h” –abbrev=7 -1 97d79ec

Git – Check if a hash is valid

Use git show and check for exit status $ git show -s 97d79ecf6b6 commit 97d79ecf6b6c5cc3c1485eb3c46e12986a978f57 Author: Dave Methvin Date: Mon Nov 9 17:49:01 2015 -0500 read more

Git show details of a commit hash

show a commit details (without file diff) $ git show -s 97d79ecf6b6 commit 97d79ecf6b6c5cc3c1485eb3c46e12986a978f57 Author: Dave Methvin Date: Mon Nov 9 17:49:01 2015 -0500 Dimensions: read more

Git log with file names

git log with name $ git log –name-status … git log with name (one entry) $ git log –name-status -1 commit fbf829b7245f7d76ea02a44ab0a62427214b7575 Author: Timmy Willison read more

PHP print number to two decimal places

Print a number/float in php to two decimal places:

PHP elapsed time

Find elapsed time in php using microtime.

Git delete branch

Delete local branch $ git branch -d BRANCHNAME ## list branches $ git branch

Git create branch

Create branch without switching $ git branch NEWBRANCHNAME ## list branches $ git branch Create branch and switch to it $ git checkout -b NEWBRANCHNAME read more

Linux find – ignore case in name

When using linux find, -iname can be used to match name pattern and ignore case (case insensitive). $ fine . -iname “pattern” Example Find all read more

find – exclude directory or file pattern

To exclude directory or file pattern when using find on command line one can use ! -name “pattern_to_exclude” Example To exclude a directory using its read more

Mac – hide and unhide a file or directory

Mac command line utility chflags can be used t unhide or hide a hidden folder or file on Mac. A hidden folder will start appearing read more

jQuery – add text to existing div

jQuery .append() can be used to add text to an div. The text can contains tags inside it.

jQuery sliding effect – slideUp, slideDown, slideToggle

jQuery slideDown, slideUp, slideToggle can be used to display, hide or toggle and element in sliding motion. .slideDown( [duration ] [, complete_callback ] ) .slideDown( read more

Javascript – textarea and text input select all

Javascript object.select() can bse used to select full text in textarea and text put fields in HTML. Example – select all in textarea Example – read more

CSS bottom

CSS bottom property decides the bottom offset (bottom edge of element offset from bottom edge of container) for positioned elements. An element is considered positioned read more

CSS right

CSS right property decides the right offset (right edge of element offset from right edge of container) for positioned elements. An element is considered positioned read more

CSS top

CSS top property decides the top offset for positioned elements. An element is considered positioned if its position property has value other than static. Few read more

CSS left

CSS left property decides the left offset for positioned elements. An element is considered positioned if its position property has value other than static. Few read more

CSS – place a div in bottom right corner of browser

To place a div in bottom right corner of browser or iframe, we can use position:fixed along with right and bottom property value assigned to read more

Javascript – declare and invoke anonymous function at the same time

Javascript can declare anonymous function and call it at the same time using the following syntax: (function (arg1, arg2, …) { }) (arg1, arg2, …); read more

Mysql – get size of all databases

Mysql contains size of all tables in information_schema.TABLES table. The following query can be used to get size of all databases on a mysql server: read more

Display keys added to ssh-agent using ssh-add

To display keys added to ssh-agent using ssh-add, run the following commands. Lists fingerprints of all identities currently represented by the agent $ ssh-add -l read more

Mysql – display row count and size of tables

Mysql SHOW TABLE STATUS command can be used to display information about all or specified tables in mysql db. Here are some examples: Show status read more

CSS – round toggle switch using checkbox and label

Css round toggle switch can be implemented using html checkbox and a label tag which appears after it. The high level approach steps are: We read more

HTML input checkbox

HTML input tag with type=checkbox can be used to create check box in html. It can also be nested in label tag. When inside label read more

Ruby gem – handy reference

Ruby gem is a package manager for the Ruby programming language. Here are some gem handy commands on Mac or Linux. Install a package $ read more

Install sass on Mac or Linux using ruby gem

Sass can be installed on Mac or Linux using ruby gem. To install sass follow these steps. Install sass gem $ sudo gem install sass read more

Use netcat (nc) to listen on tcp or udp port

Netcat (nc) can be use as a mini server which can listen to either tcp or udp port on Mac or Linux. nc – listen read more

CSS – enlarge image on hover

CSS transform:scale(2, 2) can be used on hover to resize (double) an image (horozontally and vertically). We can use any scale factor. Here is an read more

CSS background image example

The background-image property sets the background image of an element.

CSS background-color

The background-color property sets the background color of an element. The color is drawn behind any background images. Example – background-color

wget handy commands

Here are some handy wget commands wget with username and password In case a url requires simple web auth, one can use the following wget read more

CSS flexbox – align div vertically and horizontally in center

CSS flexbox can be used to align a div in center of container div both vertically and horizontally. Use the flexbox with following properties: justify-content: read more

jQuery – text input field – change keyup and paste events

jQuery can be used to handle these events on an input text field. change (when text input field changes and loses focus) $(‘input#field1’).on(‘change’, function(evt) { read more

CSS flexbox – display flex and inline-flex

CSS property display can be used to define flex box container. It can have two values: display: flex; display: inline-flex; Syntax: Example – display:flex and read more

CSS flex – shorthand for flex-grow, flex-shrink and flex-basis

CSS flex is the shorthand property for flex-grow, flex-shrink and flex-basis. flex-shrink and flex-basis are optional. Its default value is 1 0 auto. Syntax: Example read more

CSS flex-basis

CSS flex-basis define the initial base size of the flex-item. Note that the final size of flex-item will depend upon flex-grow and flex-shrink values. Syntax: read more

CSS align-self – override align-items for flex-item

CSS align-self property can be used to override align-items value (defined at flexbox level) for a specific flex-item. Syntax: Example – align-self This example uses read more

CSS flex-shrink – shrink flex item if needed

CSS flex-shrink property lets a flex item to shrink if needed. Its initial value is 1. That mean by default flex items will shrink. It read more

CSS flex-grow – grow flex item if needed

CSS flex-grow property lets a flex item to grow if needed. Its initial value is 0. That mean by default flex item does not grow. read more

CSS order – flex items ordering

Flex items are, by default, displayed in the same order as they appear in the source document. The order property can be used to change read more

CSS align-content – packing multiple flex lines

The align-content property aligns a flex container’s lines within the flex container when there is extra space in the cross-axis. This property has no effect read more

CSS align-items – flexbox items vertical alignment

The align-items property can be used to align flex items in vertical diretion. It is flex container property. Syntax: align-items values flex-start flex-end center baseline read more

CSS justify-content – flexbox children aligment

The justify-content property aligns flex items along the main axis of the current line of the flex container. It is flex container property. Syntax: justify-content read more

CSS flex-flow – flex direction and wrap shorthand

The flex-flow property is a shorthand for setting the flex-direction and flex-wrap properties. It is flex container property. The default value is row nowrap. Syntax: read more

CSS flex-wrap

The flex-wrap property controls whether the flex container is single-line or multi-line. It is flex container property. Syntax: Example – flex-wrap

CSS flex-direction – flexbox container ordering and orientation

The contents of a flex container can be laid out in any direction and in any order using flex-direction. It is flex container property. Syntax: read more

Javascript – Number function

The Number JavaScript object is a wrapper object allowing you to work with numerical values. A Number object is created using the Number() constructor. It read more

Javascript – parseInt

The parseInt() function parses a string argument and returns an integer of the specified radix (default 10). In case the string starts with a valid read more

Javascript – check if string is number

The isNaN() function determines whether a value is NaN (Not-A-Number) or not. Note that parseInt approach may not work with strings having valid number prefix. read more

jQuery ui slider and input text box – two way binding

jQuery ui can be used to create a slider with updated value getting displayed in an input text box and any update in text box read more

jQuery ui slider and input text box – one way binding

jQuery ui can be used to create a slider with updated value also getting displayed. Syntax: Example – slider and input text box – one read more

CSS box-shadow

CSS (CSS3) box-shadow property attaches one or more drop-shadows to the box. CSS property box-shadow Few points to note: blur radius spread distance and color read more

CSS text-shadow

CSS3 text-shadow accepts a comma-separated list of shadow effects to be applied to the text of the element. CSS property text-shadow blur-radius and color are read more

CSS3 Gradient examples

A gradient is an image that smoothly fades from one color to another. These are commonly used for subtle shading in background images, buttons, and read more

Chrome – disable notifications from a site accepted earlier

In case you have accepted to get notifications from a site, it can be disabled later. These are the steps Click on Chrome settings from read more

Linux Systemd/Systemctl quick start guide

Systemd is an init system used by new Linux distributions like Ubuntu 15 and Centos 7. It intends to replace Sysv init (Ubuntu, Centos, etc) read more

Centos/RHEL – find package for a file

Centos/RHEL Linux yum command line tool can be used to find which package a file belongs to. Fine packages based filename To find package which read more

AngularJS ng-list example

AngularJS ng-list directive can be used in text input and it converts between a delimited string and an array of strings. The default delimiter is read more

Centos – save and restore iptables

Linux command iptables can be used to make changes to Linux iptables. By default these changes are not reboot-safe and will get lost on reboot. read more

Vagarant quick start guide on Mac

Vagrant is an excellent tool to create and configure lightweight, reproducible, and portable development environments. Here is a quick start guide to use vagrant on read more

Mac – show volume icon on menu bar

To show volume icon on Mac top menu bar follow these steps: Open system preferences by using spoltlight search. Click on sound icon Select sound read more

Linux iptables and ip6tables examples

Linux iptables is a user-space application program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different read more

AngularJS ng-if vs ng-hide/ng-show

Angular ng-if directive removes or recreates a portion of the DOM tree based on an expression (true or false). On the other hand ng-show (or read more

AngularJS ng-href example

AngularJS directive ng-href can be used to use a template to create href. Directly using it in href can make the link broken before Angular read more

AngularJS ng-hide – conditionally hide an element

AngularJS directive ng-hide hides an element if the expression ng-hide evaluates to true. Under the hood it adds or removes class ng-hide to the element. read more

AngularJS ng-focus example

AngularJS ng-focus expression is evaluated when an element (window, input, select, textarea, a) gets focus.

AngularJS ng-disabled – conditionally disable an element

AngularJS directive ng-disabled sets the disabled attribute on the element if the expression ng-disabled evaluates to true.

AngularJS ng-cloak examples

AngularJS ng-cloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your read more

AngularJS ng-class-even and ng-class-odd example

AngularJS directives ng-class-even and ng-class-odd work like ng-class except that when these are used with ng-repeat, these apply to even and odd rows.

AngularJS ng-class example

AngularJS ng-class directive allows you to dynamically set CSS classes on an element using an expression. The expression can be of one of these three read more

AngularJS ng-checked example

AngularJS ng-checked sets the checked attribute on the element, if the expression inside ng-checked is true.

AngularJS ng-change example

AngularJS ng-change expression is evaluated when the user changes the input.

AngularJS ng-blur example

AngularJS ng-blur expression is evaluated when an element (window, input, select, textarea, a) loses focus.

AngularJS ng-bind-template example

AngularJS ng-bind-template attribute take a template string and can contain multiple {{ }} expressions.

AngularJS ng-bind example

AngularJS ng-bind attribute tells Angular to replace the text content of the specified HTML element with the value of a given expression. It also updates read more

AngularJS ng-dblclick examples

Example1 AngularJS ng-gblclick example to increment a variable on every double click. Example2 AngularJS ng-dblclick example to increment a variable on every double click. This read more

AngularJS ng-click examples

Example1 AngularJS ng-click example to increment a variable on every click. Example2 AngularJS ng-click example to increment a variable on every click. This time use read more

Chrome – remove an accepted certificate

Steps to remove an accepted certificate (e.g. a self signed certificate) from Chrome browser. Click on Chrome settings. On settings page click on advanced settings read more

Rsync – exclude specific file extension

To exclude a specific file extension (say .class) we can use –exclude “*.class” (or –exclude=”*.class”). Note that it can be repeated multiple time. $ rsync read more

Git – show log of one user’s commits

git log –author=pattern can be used to show log of all users matching a specific pattern. $ git log –author=Ram $ git log –author=”R.*m” // read more

Git – checkout remote branch

To checkout remote branch and track it from its remote origin $ git fetch $ git branch -v -a ##List available remote branches $ git read more

Ubuntu – reload iptables rules during boot

Steps to load iptable rules automatically on Ubuntu Linux using package iptables-persistent. Install iptables-persistent $ sudo apt-get install iptables-persistent When asked during installation should it read more

Mac – print java home on command line

To print Java (JVM) home path on command line the following command (jave_home) can be used as shown below: $ /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home To display all read more

Remove passphrase from ssh private key

To remove passphrase from an existing key, we can use ssh-keygen with -p option. Here is an example which changes passphrase of private rsa key read more

How to check if an ssh key has passphrase

To check if an ssh key has passphrase, one can look for the presence of ENCRYPTED string in the private key. Here is an example read more

Use netcat (nc) to check if a remote port is reachable

Netcat (nc) can be use to check if a remote port is reachable and client can connect to it. The following commands were tried on read more

Linux – ssh agent forwarding when using bastion host

When using a bastion host (or Jumpbox) to connection to production server using ssh private keys, ssh agent forward can be used. The main advantage read more

Linux – find listening ports

Sometimes it is useful to find what ports a machine is listening to. Here are some use cases: Display listening ports $ netstat -l Display read more

Chrome – copy any request as cURL including headers

Chrome developer tools has a pretty handy feature to copy any GET/POST request in network tab to cURL. This also copies all headers involved in read more

Mac – how to change desktop icons size

Mac desktop icons size can be increased or decreased using Desktop view options. There are steps: Click anywhere on blank Desktop area. Click on View read more

Python clone/copy array

Python cloning an array (list) using slice operator.

CSS padding inside a box

CSS padding property specify the width of the padding area of a box. padding values padding property can be used to specify padding-top, padding-right, padding-bottom, read more

CSS margin area of a box

CSS margin property specify the width of the margin area of a box. margin values margin property can be used to specify margin-top, margin-right, margin-bottom, read more

Javascript – remove first item from array

Javascript code to remove first item from array using arr.shift() Remove first item from array

Javascript – prepend item to array

Javascript code to prepend an item at the beginning of array using arr.unshift() Prepend one value to array

Javascript – remove last item from array

Javascript code to remove last item from array using arr.pop() Append one value

Javascript – append item to array

Javascript code to append one or multiple values at the end of array Append one value Append multiple values

CSS font-family

CSS font-family is a list of font family names from which first value is used if present otherwise next value and so on. Here is read more

CSS font-size

The CSS font-size property sets the font size of an html element. Example – font-size

CSS font-weight

The CSS font-weight property selects the weight of the font. The keyword normal is synonymous with 400, and bold is synonymous with 700. Values from read more

CSS font-variant

The CSS font-variant property can be used to select small-caps variation within font family. In a small-caps font the lower case letters look similar to read more

CSS font-style

The CSS font-style property selects between normal (sometimes referred to as “roman” or “upright”), italic and oblique faces within a font family. Example – font-style

CSS font shorthand property

The CSS font property is a shorthand property for setting font-style, font-variant, font-weight, font-size, line-height and font-family. font values Few points to note: First three read more

CSS pointer-events – disable click on an element

CSS property pointer-events can be used enable/disable (default is enabled) mouse events on an element. If pointer-events is none for an element, the click event read more

CSS generated content for ::after and ::before

CSS property content is used with the ::before and ::after pseudo-elements to generate content in a document. Example – display url after a tag text read more

CSS clip

CSS property clip (clipped region) defines what portion of an element’s border box is visible. The clip property applies only to absolutely positioned (position=absolute, fixed) read more

Test site css, javascript, html in old IEs

We frequently need to test css, javascript and HTML in old IE (internet explorer) browsers on Windows. This can be done using IE11 developer tools read more

Linux du – find disk usage of directories or files

Linux du command can be used to find disk usage of files and directories. Here are some handy du commands on Ubuntu Linux (or any read more

CSS clearfix – clear float automatically using ::after

A clearfix class is a way for an element to automatically clear left and right float on its child elements. This eliminates the need to read more

Make an element draggable using Vanilla Javascript

Javascript event handler mousedown and mousemove can be used to make an element draggable without using any other library. This can be made to work read more

Linux – how to create swap partition

Step to create swap partition on Ubuntu Linux. It should work on any other Linux also. Create storage file (say 4GB) using fallocate for swap read more

Linux – how to create a large file like 1GB

Sometimes we need a large file with any content on Linux. This may be needs for benchmarking and testing purpose. Here are some ways to read more

Rsync – show progress and transfer rate

Rsync can be used to sync directories and files from one machine to another. Sometime we want to see the progress and transfer speed. For read more

Linux/Unix – find inode number of a file

To find the inode number of a file on Linux/Unix the following approaches can be used. Find inode using ls $ ls -i file1.txt 412882 read more

Linux/Unix – truncate a large log file without deleting it

Sometimes we need to truncate (make it size 0) a large opened file by a running process (e.h. php error log, apache error logs, custom read more

HTML – is closing li tag required?

HTML li tag can be used inside ul or ol tags. Its closing tag is optional and it makes html more readable and less verbose. read more

CSS box-sizing – impact on padding and border

CSS box-sizing decides if specified width, height, etc. will apply to content area of an element or to whole element including padding and border. Example read more

Linux – command to check swap size

Swap space is the area on a hard disk which is part of the Virtual Memory. Swap space temporarily holds memory pages that are inactive. read more

AngularJS animattion using ng-class

Angular ngAnimate can be used to create animation effect using animation aware directives. Usage: Example – animate with ng-class This example uses ng-class to toggle read more

Python merge two lists (arrays)

To merge two (or more) lists (arrays) the operator plus (+) can be used. It will append items of 2nd list to first list and read more

AngularJS ng-if – conditional dom tree

Angular ng-if directive removes or recreates a portion of the DOM tree based on an expression (true or false). Usage: Example – ng-if without animation read more

CSS transition-delay

The CSS transition-delay property defines when the transition will start. It delays the transition from when it is applied. Example – transition-delay

CSS transition-timing-function

The CSS transition-timing-function property describes how the intermediate values used during a transition will be calculated. In order words it describes transition effects like ease, read more

CSS transition-duration

The CSS transition-duration property defines the length of time that a transition takes. Example – transition-duration

CSS transition-property

The CSS transition-property property specifies the name of the CSS property to which the transition is applied. Example – transition-property

CSS transition – animation effect when properties change

CSS property transition can be used to create animation effect when other specified properties change. This can only be applied on animatable properties. Few points read more

jQuery – how to get version info

to get jQuery version info the variable jQuery.fn.jquery (or $.fn.jquery if $ is being used for jQuery object) can be used. Some examples. jQuery version read more

jQuery ui – make an element draggable

jQuery ui can be used to make an element draggable/movable by mouse drag. Note that it does not work with touch events. Syntax: // After read more

Javascript parse json string

JSON.parse() can be used to parse a given json string into javascript value (array, string, etc.) Here are some examples Example – parse json containing read more

Javascript convert array to json string

JSON.stringify() can be used to convert a given javascript value to json strng. Usage: JSON.stringify(value[, replacer[, space]]) Here are some examples Example – JSON.stringify() default read more

Python rstrip – remove training spaces and newline

Python rstrip can be used to removed trailing whitespaces (spaces, newlines, tabs, etc.) from a string. It Usage newstring = s.rstrip([chars]) If chars string is read more

AngularJS ng-init

The ng-init directive allows you to evaluate an expression in the current scope. This can be used to initialize model values. Usage: Example Initialize date read more

AngularJS – dynamic css using ng-style

Angularjs ng-style directive can be used to define inline style attribute which can define dynamic style values using variables. Usage: Note that expression evals to read more

Python string to int

Python string can be converted to int using int(strval). Note that it will throw ValueError for invalid string. Here is a quick example to convert read more

Python int to string

Python int (or any other data type like float) needs to be converted to string before we can do concatenation operation using plus (+). It read more

Python dictionary basics

Python dictionary (associative arrays) – some basic operations. Initialize dictionary Check if a key exists access value for a key list length/size using len() len() read more

Python type – find type of a variable

Python in-built function type() can be use to find type of any variable or value. Example – type() of string variable Example – type() of read more

Python initialize large list with same value

To initialize a large list with same value (all items having same value), the following syntax can be used. a = [val] * num_items Example

Python array slice

Slicing a list (array) in python is very handy way to get a sub list of an array. Its syntax is ## slice from start read more

Python list/array – remove an item

To remove an item from python list method pop([i]) can be used. Remove last item Remove first item Remove ith item

Python list – append or prepend a value

Appending or prepending a value to a list in Python. Append value Prepend value

Python list (array) basics

Python list (or array) – some basic operations. Initialize list access ith item access last item list length/size using len() Note than len() can also read more

Python string contains check

To check if a string is part of another string (case sensitive) we can use these approaches Using in operator Using string find() method ## read more

Python string lowercase and uppercase

To convert a string to lowercase of uppercase following code can be used: s_lower = s.lower() s_upper = s.upper() string lowercase example string uppercase example

Mac – make spotlight search faster

Mac spotlight search is one of the most frequently used tool on Mac. It searches various folders on Mac and shows results. Here are steps read more

HTML5 script async – how to load script asynchronously

HTML5 script async attribute can be used to load a script asynchronously. with async one can also use onload attribute to attach any javascript code read more

jQuery – get javascript object

jQuery when applied on a css selector, returns a wrapper object which contains 0 or more javascript objects. To get the javascript object from it, read more

CSS3 cursors – change cursor on an element

CSS property cursor specifies the type of mouse cursor to be displayed on the element. Example css cursor

CSS outline-width

CSS outline-width property specify the width of an element’s outline (2px, 2em, etc.). Example css outline-width

CSS outline-style

CSS outline-style property specify the line style of an element’s outline (solid, double, dashed, etc.). Example css outline-style

CSS outline-color

The outline-color property sets the color of the outline. Note that the outline-color value invert if not supported, then initial value of color is taken. read more

CSS outline – create outline around an element

CSS outline property can be used to create outlines around visual objects such as buttons, active form fields, image maps, etc. It it different from read more

jQuery – get checkbox value and checked state

jQuery can be used to access checkbox value using jQuery.attr(“value”) and it checked state using jQuery.prop(“checked”). Note that we can not use jQuery.attr() for checked read more

jQuery – find select element selectedIndex, value and text

jQuery code to access select element’s selected index, selected value and selected option node text.

CSS selector specificity

When two selectors have same style, then one with higher specificity wins. In case they have same specificity, the one which come later, wins. Specificity read more

Linux/Unix – How to go to previous directory

To go to previous working directory is Linux is a frequently occurring need. These are two ways to achieve it: Using dash (-) $ cd read more

Use universal selector to get all DOM nodes in vanilla Javascript

The universal selector (*), matches the name of any element type. It matches any single element in the document tree. Some ways it can be read more

CSS :nth-last-of-type

CSS :nth-last-of-type(an+b) pseudo class represent all sibling elements of same type whose sibling position is obtained by putting n=0,1,2,3… and so on counting from last. read more

CSS :nth-last-child

CSS :nth-last-child(an+b) pseudo class represent all sibling elements whose sibling position is obtained by putting n=0,1,2,3… and so on from last. Note that sibling can read more

CSS :not – negation pseudo-class

Css negation pseudo-class, :not(X) can be used on any simple selector. It will match element which are not selected by selector X. Example – css read more

CSS :empty – define style for empty element

Css :empty pseudo-class represents an element that has no children at all. Few cases <p></p> is considered empty <div>hello</div> is not considered empty Example – read more

CSS :only-of-type – define style of only child a type

Css :only-of-type pseudo class represents an element that has a parent element and whose parent element has no other element children of same type. Example read more

CSS :only-child – define style if element if only child

Css :only-child pseudo class represents an element that has a parent element and whose parent element has no other element children. Example – css :only-child read more

CSS :nth-of-type

CSS :nth-of-type(an+b) pseudo class represent all sibling elements of same type whose sibling position (starting from 1) is obtained by putting n=0,1,2,3… and so on. read more

Css :nth-child

CSS :nth-child(an+b) pseudo class represent all sibling elements whose sibling position (starting from 1) is obtained by putting n=0,1,2,3… and so on. Note that sibling read more

CSS :root

The :root pseudo-class represents an element that is the root of the document. In case of HTML, it is html element. Example – css :root read more

CSS :checked – style for selected checkbox and radio

The :checked pseudo-class represents elements (checkbox and radio) that are in an selected (checked) state. Example – css :checked checkbox element This example highlights span read more

CSS :enabled :disabled – style of enable and disabled elements

The :enabled pseudo-class represents elements (input, textarea, button, etc.) that are in an enabled state. Such elements have a corresponding disabled state also. Similarly :disabled read more

CSS pseudo class :lang

The :lang pseudo-class can used to select elements based on language. Example – css :lang This example show french language content in different color.

CSS pseudo class :target

The :target pseudo-class applies to an element which has id matching with fragment identifier (string after hash). e.g. in url http://example.com/html/top.html#section1 section1 is fragment/anchor identifier. read more

Android lollipop – add the clock widget to home screen

To add clock widget (analog or digital) on Android Lollipop, these steps can be followed. For Android other versions, instructions are slightly different. Touch an read more

CSS id selectors – define style by element id

The CSS id selector matches element having a specific id attribute This can be used to specify CSS style based on element id. Note that read more

CSS class selectors – define style by class name

The CSS class selector matches element having a specific class name as one of the classes in attribute class. This can be used to specify read more

Javascript – string ends with check

ECMAScript 6 String.prototype.endsWith() method can be used to check if a string ends with a suffix. But it is not yet supported by all browsers. read more

Javascript – string starts with check

ECMAScript 6 String.prototype.startsWith() method can be used to check if a string starts with something. But it is not yet supported by all browsers. Another read more

Python if-else and if-elif-else

Python if else statements can be expressed on two ways Simple if-else statement if-elif-else statement with one or more occurrences of elif. if else example read more

jQuery – get class list of DOM element

jQuery code snippet to get class list of an element. We are using jQuery attr(“class”) to get the class list as string and then splitting read more

jQuery – create iframe with content

Sometimes we need to create inline iframe with content generate from jQuery/Javascript. This iframe will not have src attribute. One use case is to run read more

CSS attribute substring selectors

CSS attribute selector can be used to select DOM elements based on matching substring of attribute values. We can use attribute substring selectors in multiple read more