Tutorials - Page 2 of 5

CSS type selectors – define style by element name

The CSS type selector matches element by node name (e.g. div, h1. h2). This can be used to specify CSS style based on element type. read more

CSS pseudo class :visited – style for visited links

CSS :visited pseudo-class applies once the link has been visited by the user Example – use :visited to apply style to visited links This example read more

CSS pseudo class :link – style for unvisited links

CSS :link pseudo-class applies to links that have not yet been visited. Example – use :link to apply style to unvisited links This example displays read more

CSS pseudo class :focus

The :focus pseudo-class applies while an element has the focus. There can be various ways to get focus on an element. Some of these are: read more

CSS pseudo class :active

The :active pseudo-class applies while an element is being activated (e.g. clicked) by the user. For example, between the times the user presses the mouse read more

CSS pseudo class :hover

The :hover pseudo-class applies while the user takes mouse on an element. Note that user may not click on it. Using :hover one can change read more

CSS calc function for numeric values

CSS calc() function allows expressions with addition (+), subtraction (-), multiplication (*), and division (/) to be used as component values. It can be used read more

jQuery – load a script with cache enabled

jQuery method jQuery.getScript() can be used as a shorthand to load a script given its url. This by default disables cache by appending extra random read more

jQuery – check if element is visible in viewport ofter scroll

To check if an element is visible in window viewport after vertical scrolling the following approach can be used using jQuery. Note that this approach read more

CSS general sibling selector

Sometimes we need to define css style for general sibling elements. These may not be adjacent but should have same container parent. It can be read more

CSS – drop cap effect

CSS drop cap effect can be achieved by making first letter of bigger size (keeping line height not so large) and the applying float:left on read more

CSS – how to do first letter capital and bigger

CSS first letter can be made capital and bigger using pseudo element ::first-letter. Here is sample html/css code:

CSS ::first-letter pseudo element

The ::first-letter pseudo-element represents the first letter of an element, if it is not preceded by any other content (img, or inline tables). If an read more

CSS ::first-line pseudo element

The ::first-line pseudo-element describes the contents of the first formatted line of an element. Example – ::first-line

CSS color value currentColor

CSS property color can have a special value currentColor. Its computed value is same as the computer value of color property. One possible use case read more

CSS color

CSS property color describes the foreground color of an element’s text content. In addition it is used to provide a potential indirect value (currentColor) for read more

CSS color values

CSS3 color values are used in many CSS properties like color, background-color, etc. CSS3 color values can be specified in many ways. Here is the read more

PHP regex – match any digit

Php regex can use digit shorthand (\d) to match a digit (0-9). To match any non digit character, regex shorthand \D (uppercase backslash D) can read more

How to detach Chrome developer tools window

Chrome developer tools is very useful in debugging Javascript and CSS in Chrome browser. Sometimes it is useful to detach the developer tools window. Here read more

WordPress – query to dump all posts with featured image

Sometimes we need to dump all post with featured images along with post title and image title. Here is mysql query which lists all posts read more

Chrome – view javascript errors

It is useful to view Javascript errors in Chrome for debugging purpose. Chrome developer tools console can be used to view Javascript errors as shown read more

Apache – list loaded modules on Ubuntu

To list loaded module in Apache on Ubuntu linux, command line tool apachectl can be used. Here is an example. $ apachectl -M Loaded Modules: read more

PHP regex – match word character (letter, number or underscore)

Php regex can use word shorthand \w (lowercase backslash w) to match a word character. It matches with any of the following: letters (a-z,A-Z) Numbers read more

Create circle and oval in CSS

CSS circle and oval can be created using border-radius on a div. For circle the horizontal and vertical radius of each corner is same, whereas read more

How to create CSS triangles or arrow heads

CSS triangles (arrow heads) in various directions (up, down, left, right) can be created using a combination of thick CSS borders (visible and transparent) on read more

CSS automatic table row numbering

CSS3 counters can be used to number table rows automatically. We need to maintain a counter per row and display it using ::before on first read more

CSS automatic nested numbering for headings

CSS counters are variables maintained by CSS whose values may be incremented by CSS rules to track how many times they are used. Here is read more

CSS counters – automatic numbering before h2

CSS counters are variables maintained by CSS whose values may be incremented by CSS rules to track how many times they are used. Here is read more

Linux/Unix history with date and time

It is useful to run history command with date and time along with each command. Here are instructions on how to do it on Linux/Unix. read more

AngularJS ng-model

The ngModel directive binds an input, select, textarea to a property on the scope using NgModelController. One can also bind same property on multiple input read more

jQuery – read and modify iframe content

Sometime we need to read and modify same domain iframe content using jQuery. Here is code snippet which will modify the content of an iframe.

Javascript – get computed style of an element

To get computed style of an element the following approaches can be taken: Vanilla javascript: window.getComputedStyle(element) jQuery: .css(propName) Example – computed style using Javascript Example read more

CSS universal selector

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 animation shorthand property

CSS animation shorthand property is a comma-separated list of animation definitions, each of which combines animation properties into a single component value. Note that individual read more

CSS animation-play-state

CSS animation-play-state property defines whether the animation is running or paused. When a paused animation is resumed, it restarts from the current value instead of read more

CSS animation-fill-mode

CSS animation-fill-mode property defines what values are applied by the animation outside its execution time window. These two periods are considered outside animation: During delay read more

CSS animation-direction

CSS animation-animation-direction property defines whether or not the animation should play in reverse on some or all cycles. When an animation is played in reverse read more

CSS animation-iteration-count

CSS animation-iteration-count property specifies the number of times an animation cycle is played. It can be a number or infinite. In case animation-name has multiple read more

CSS animation-delay

CSS animation-delay property defines when the animation will start. It allows an animation to begin execution some time after it is applied. In case animation-name read more

CSS animation-timing-function

CSS animation-timing-function property describes how the animation will progress over one cycle of its duration. e.g. ease, linear, etc. In case animation-name has multiple values, read more

CSS animation-duration

CSS animation-duration property defines the length of time that an animation takes to complete one cycle. Few points to noe about animation-duration: It cannot be read more

CSS animation-name

CSS property animation-name defines a list of animations that apply to an element. Each name is used to select the keyframe at-rule that provides the read more

CSS text-transform – capitalize, uppercase and lowercase text

CSS property text-transform controls capitalization effects of an element’s text Example – text-transform

CSS text-decoration – underline, overline and strikeout text

CSS property text-decoration describes decorations that are added to the text of an element using the element’s color. Few points to note about text-decoration Underlines, read more

CSS text-indent – indent text in a block

CSS property text-indent specifies the indentation of the first line of text in a block container. Few points to note about text-indent In case of read more

Jenkins – how to delete old builds

Jenkins supports deleting old builds for a project by days or maxium number of builds to keeps. This is useful to keep disk usage under read more

HTML attribute contenteditable – make an element editable

HTML attribute contenteditable makes an element editable. Few things to note about attribute contenteditable Its value can be empty string, true or false. Empty string read more

CSS word-spacing – additional space between words

CSS property word-spacing indicates inter-word space in addition to the default space between words. Word spacing is also influenced by justification (see the text-align property) read more

CSS letter-spacing – additional spacing between adjacent chars

CSS property letter-spacing specifies additional spacing between adjacent characters. Depending on the justification rules in effect (see text-align), user agents may further increase or decrease read more

CSS adjacent sibling selector

Sometime we need to define css style for adjacent sibling elements. It can be defined by using syntax E1 + E2. It will match when read more

CSS text-align – align text left, right or justify

CSS property text-align specifies how the inline-level content of a block is aligned along the inline axis. Note that text-align will also affect inline and read more

Vim – show line numbers

Vim can show and hide line numbers in editor. Here are Vim commands for it. Show line numbers in vim After [ESC] enter the following read more

CSS word-break – specify line breaking rules between letters

CSS property word-break specifies line breaking rules between letters. Note that this different from word-wrap which applies when word does not fit in line box. read more

CSS word-wrap/overflow-wrap – specify if a word can break anywhere

CSS property word-wrap (or overflow-wrap) specifies whether the Browser may break within a word to prevent overflow when an unbreakable string is too long to read more

Recursive grep and excluding directory

Recursive grep is pretty handy way to searching a pattern in a directory recursively. Sometimes it is useful to exclude a specific directory (or multiple read more

CSS3 animation overview

CSS property animation along with @keyframw definition can be used to implement animation on properties in CSS. The behaviour of these keyframe animations can be read more

HTML5 drag and drop – move an element to dropzone

HTML5 Drag and Drop interfaces enable applications to use drag and drop (using mouse) features in web browser. It involves dragging an element and dropping read more

CSS visibility – hide an element keeping its space

CSS property visibility specifies whether the boxes generated by an element are rendered. Invisible boxes still affect layout. One can set the css display property read more

HTML pre tag tutorial

HTML pre tag (<pre>) represents a block of preformatted text. By default pre tag does not collapse white spaces, and uses monospaced (fixed-width) font like read more

CSS text-overflow – truncate text with three dots

CSS property text-overflow specifies rendering when inline content overflows its line box edge in its block container element (“the block”) that has overflow other than read more

AngularJS – implement tabs using ng-switch

Angularjs ng-switch directive is used to conditionally swap DOM structure on your template based on a scope expression. ng-switch usage Example – horizontal tabs using read more

Python find length of string or list using len()

Python len can be used to return length of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or read more

AngularJS – include inline template

Angularjs ng-include can be used to include internal or external (separate url) templates. This tutorial will cover including inline template using ng-include. ng-include usage Example read more

AngularJS – include url template

Angularjs ng-include can be used to include inline or external (url) templates. This tutorial will cover including url template using ng-include. ng-include usage Template used read more

CSS border-style tutorial and examples

CSS border-style property specify the line style of a box’s border (solid, double, dashed, etc.). Few points to note: When four values are specified this read more

CSS border-color – define color of four borders

The border-color property sets the color of the four borders. Few points to note: When four values are specified this is the order: border-top-color, border-right-color, read more

CSS border-width – set element border width of four sides

The border-width properties specify the width of the border area of an element. Few points to note: When four values are specified this is the read more

CSS list-style – shorthand for list marker type, image and position

CSS list-style property is a shorthand notation for setting the three properties list-style-type, list-style-image and list-style-position at the same place in the style sheet. Example read more

CSS list-style-image – use image as marker in list

The property list-style-image sets the image that will be used as the list item marker. When list-style-image set and image is available, it will replace read more

CSS list-style-position – specify if list markers will be outside or inside

CSS list-style-position property specifies the position of the marker box with respect to the principal block box. outside: The marker box is outside the principal read more

CSS list-style-type – specify marker (disc, square, numeric, etc.) for a list

CSS list-style-type property is used to describe type of list item marker in a list. Its initial value is disc. The value of list-style-type can read more

CSS white-space – collaping and wrapping of whitespaces and newlines

CSS whitespace property is used to describe how whitespace inside the element is handled. This property specifies two things: Whether and how white space inside read more

HTML ol tag

HTML ol tag (<ol>) can be used to create ordered list. It can contain multiple list items using tag li (<li>) and it can be read more

WordPress mysql query to get all posts with a specific custom field

Handy mysql query to get all posts with a specific custom field. We’ll query post_type=page for the purpose of this tutorial. You will have to read more

HTML li tag

HTML li tag (<li>) can be used to create a list item. It can be used either in unordered list – ul (<ul>) or in read more

HTML ul tag

HTML ul tag (<ul>) can be used to create unordered list. It can contain multiple list items using tag li (<li>) and it can be read more

HTML5 audio tag

HTML5 audio tag (<audio>) can be used to play an audio in HTML page. When multiple sources are specified, browser uses the first recognized format. read more

React Overview

React is a Javascript library for building user interfaces. Lots of people use React as the V in MVC (Model View Controller). React can work read more

CSS transform – skew (skewX and skewY)

Using CSS3 property transform, elements can be translated, rotated, scaled and skewed in two or three dimensional space. This tutorial will covered skewing an element read more

Scale an element using css transform

Using CSS3 property transform, elements can be translated, rotated, scaled and skewed in two or three dimensional space. This tutorial will covered scaling an element read more

Rotate an element using css transform

Using CSS3 property transform, elements can be translated, rotated, scaled and skewed in two or three dimensional space. This tutorial will covered rotating an element read more

CSS – align div in center vertically

To place a div (or any block level element) of unknown size containing text, in center of its parent vertically, the following approach can be read more

CSS transform – translateX and translateY

Using CSS3 property transform, elements can be translated, rotated, scaled and skewed in two or three dimensional space. This tutorial will covered translating an element read more

CSS all – shorthand to reset all properties

CSS property all is a css shorthand to reset all properties to their initial or inherited values. Note that it is not supported in IE. read more

CSS unset value examples

If CSS property value is unset, then if it is an inherited property, this is treated as inherit, and if it is not, this is read more

CSS inherit value examples

CSS inherit value is used to set a css property value to its parent element value. It can be used during debugging (e.g. In Chrome read more

CSS initial value examples

CSS initial value is used to reset a css property to its user-agent value. It can be used during debugging (e.g. In Chrome developer tools) read more

WordPress – add content filter after shortcode execution

Sometimes we need to add content filter in wordpress which should execute after all the shortcodes. The shortcodes in wordpress are executed by filter do_shortcode read more

node-sass quick start tutorial on Linux and Mac

Sass (Syntactically Awesome Stylesheets) is a style sheet language which brings programming features like variables, etc. to css. It makes maintaining and modifications in css read more

Python re search vs match

Python re.match() checks for a match only at the beginning of the string, while re.search() checks for a match anywhere in the string. Re search read more

Python re (regex) match examples

Python regular expression module (re) can be used to check a string begins with a pattern using re.match(). Note that it is different from re.search() read more

CSS – style for element having two classes (both)

Sometime we need to define css style for elements having two or multiple clasess (all of them). It can defined by using syntax .class1.class2 (or read more

CSS max-height – limit maximum height of an element

CSS max-height property is used to set maximum height of a box element. Few points to note about max-height It cannot be negative. If max-height read more

CSS min-height – set minimum height of an element

CSS min-height property is used to set minimum height of a box element. Few points to note about min-height It cannot be negative. If min-height read more

Composer – quick start guide on Linux and Mac

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) read more

CSS max-width – limit maximum wodth of an element

CSS max-width property is used to set maximum width of a box element. Few points to note about max-width It cannot be negative. If max-width read more

CSS min-width – set minimum width of an element

CSS min-width property is used to set minimum width of a box element. Few points to note about min-width It cannot be negative. If min-width read more

Install redis on Mac

Redis is an open source, in-memory data structure store, used as database, cache and message broker. It is one of the most popular key-value nosql read more

Install rabbitmq on Ubuntu Linux

RabbitMQ is an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP). It is written in the Erlang programming language. Here read more

jQuery toggleClass() examples

jQuery toggleClass can be used to toggle a class (add or remove depending upon current state) in an element (or set of matched elements). In read more

HTML5 label tag examples

Label element (<label>) represents a caption and can be used with one form input element. There are two ways to associate a label to an read more

Monitor apache using mod_status on Ubuntu

Apache installation on Ubuntu Linux automatically installs mod_status also. mod_status can be used to view server activities and performance from a web interface. Here are read more

PHP sort associative array using custom compare function

PHP associative array can be sorted using custom user compare function while maintaining index association using uasort. The function is passed two values and it read more

CSS placeholder style

CSS input and textarea ::placeholder pseudo element can be used to add a placeholder text in input element. The text is set using input element read more

HTML5 – input placeholder

HTML5 input tag’s placeholder attribute can be used to add a placeholder text (hint which disappears automatically) in input element. Before HTML5 people used to read more

WordPress – customize facebook plugin opengraph meta tags

If you are using facebook plugin in workdpress, it adds opengraph meta tags in wordpress posts. At times we want to remove or customize some read more

Svn – how to view older version of a file

Sometime we need to view an older version of a file in SVN. Here are two approaches which can be used. Using svn cat To read more

Polymer custom element tag – hello world tutorial

Polymer is a web components library and can be used to create custom elements. The library works on all major browsers (using polyfills) even if read more

How to install polymer

Polymer can be installed on Linux (or Mac) using bower on command line. It generates web component and polymer javascript files which can be included read more

How to install casperjs on Ubuntu Linux

CasperJS on Ubuntu linux can be installed using apt-get or node npm. We’ll use npm to install casperjs in this tutorial. Here are the steps read more

How to install casperjs on Mac

CasperJS on Mac can be installed using Brew or node npm. We’ll use npm to install casperjs in this tutorial. Here are the steps to read more

How to install phantomjs on Ubuntu Linux

Phantomjs on Ubuntu linux can be installed using apt-get or node npm. It can also be downloaded from phantomjs site. We’ll use npm to install read more

How to install phantomjs on Mac

Phantomjs on Mac can be installed using Brew or node npm. It can also be downloaded from phantomjs site. We’ll use npm to install phantomjs read more

bower – installation and quick start guide

Bower is a package manager for web front end frameworks, libraries, assets and utilities. Bower can manage components that contain HTML, CSS, JavaScript, fonts and read more

How to install node (node.js) on Mac

Installing node on Mac require brew (Homebrew). If you have not installed it, you can follow Brew installation guide. Here are the steps to install read more

HTML import

HTML import is part of web component framework and its specification is in Draft stage. HTML import can be used to import another html document read more

PHP – associative array value in double quoted string

To print associative array value in double quoted string in php, the following syntax using curly braces can be used. {$arr[‘key1’]} Note that curly braces read more

CSS – !important examples

CSS annotation !important will override all other styles (irrespective if specificity). Note that using annotation !important is discouraged and should be avoided. Here are some read more

AngularJS format date using date filter

Angularjs filter can be used in angular js expression using pipe. Here is an example of AngularJS inbuilt filter date to format Javascript Date to read more

AngularJS – display html without escaping using ng-bind-html

AngularJS ng-bind-html directive can be used to insert html into an element. Here is sample usage: Few points to note: One need to include ngSanitize read more

CSS – margin collapsing

In CSS adjoining vertical margins of two or more boxes (these may or may not be siblings), can combine to form a single margin. These read more

AngularJS controller ajax examples

Angularjs basic ajax example to display value returned from ajax server call. We’ll use controller, template and $http for this tutorial. Angularjs Ajax GET example read more

CSS resize – make block element resizable by user

CSS (CSS3) property resize can be used to make a div (or other block level element) resizable by clicking and dragging bottom right corner of read more

Mac – how to always show scroll bar

Mac by default show scroll bars automatically based on mouse pointer. This setting can be changed to always show scroll bars. Note that this settings read more

CSS overflow – visible, hidden and scroll for overflowing content

CSS overflow property decides how to display content if it goes beyond the boundaries of a block (e.g. when inside div). Note that overflow applies read more

Javascript local and global variables

Javascript variables can be local or global scoped depending upon how the are declared. In HTML all global scoped variables becomes part of window object. read more

CSS – align div in center horizontally

Div (when a block level element) or any other block level element can be aligned in center of its container using property margin-left:auto and margin-right:auto. read more

CSS – align text in center horizontally

Text can be aligned in center of a div or any other block level element using CSS property text-align:center. Note that this property applies of read more

Javascript prototype examples

Javascript function can be used to define classes. Inside classes, member properties (containing functions, objects, etc.) can be defined either as member variables in constructor read more

Javascript – implement class using function

Javascript classes can be created using function. Here a function can be instantiated using new keyword. The member variables and methods in function can be read more

Are Javascript functions objects?

A Javascript function is also an object of type function. So it can be used as an object and can have member variables. Also note read more

WordPress – prevent access to php files in wp-includes

Most wordpress php files are in directory wp-includes in wordpress root directory. This can be used by hackers to try to access these directly. This read more

CSS – inline-block and baseline alignment

When we use display:inline-block to place elements next to each other, by default their baseline is aligned to to parent baseline unless vertical-align property of read more

CSS – align multiple divs horizontally

To align div horizontally, one solution is to use css float property. But a better solution is to to use CSS display:inline-block on all divs read more

CSS float – floating left, right and clearing

CSS float property decides if an element should float left or right. It can take two value – float:left or float:right. Elements after a floating read more

CSS line-height – set minimum height of line box

On block level elements, the line-height property specifies the minimum height of line boxes within the element. Comment on inheritance In case font value is read more

Javascript onscroll event handler with throttling

Javascript onscroll event handler is called on every onscroll event. At times we want to ensure that it is not called again before a certain read more

Javascript onscroll event handler

Javascript onscroll event handler can be attach to any DOM element. Attaching it to document is a typical use case. But it can be attached read more

Linux – list only directories

Sometimes we need to list only directories on Linux (or any other unix). Here are some approaches. List directories using ls and shell wildcard $ read more

Javascript sleep implementation

Javascript does not have any sleep function. At times (e.g. to simulate a specific situation) we may need to sleep or delay the code for read more

Javascript – run a function at regular interval

Javascript setInterval can be used to make repeated calls to a function or code with fixed interval. If there is a possibility that function logic read more

Javascript settimeout example

Javascript setTimeout can be used to scheduled a function or code to run at a specified delay. This is pretty powerful API and can be read more

React component ajax example

React ajax calls can be done in componentDidMount. Once we get the result, we can use setState to re-render the component. In case component can read more

React basic clock example using setInterval

To create a basic clock in React, we can use setInterval in componentDidMount and optionally clear it in componentWillUnmount if relevant. You may also want read more

CSS border – define border properties of an element

CSS border property can be used to define border properties of an element. Few points to note: To inherit border from parent, value inherit can read more

Javascript how to stop event propagation

Javascript/HTML event can be handled by more than one dom elements and after one handler, it propagate to next element. API Event.stopPropagation() can be used read more

Javascript event bubble vs capture

Javascript/HTML events can propagate in two ways in DOM API. This is relevant when more than one element are listening on same event. Event propagation read more

CSS opacity – set opacity level of an element

CSS (CSS3) property can be used to set the opacity level of an element. It can have a value from 0.0 to 1.0 (default is read more

Chrome – how to add custom http request headers

At times we may need to add custom headers to a request for debugging purpose. e.g. You may want to display debugging messages when specific read more

HTML form file upload hello world

HTML forms can have file type as input field to update and send files to server. To be able to handle file upload, it need read more

jQuery encode string to html entities

jQuery .text() method sets text for an element (after taking care of html entities) and .html() gets the html for a dom element. Combining these read more

jQuery how to load a url into an element

jQuery .load() can be used to make an Ajax call (GET or POST) and load the results into an element by settings result into its read more

CSS attribute presence and value selectors

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

How to trigger click using jQuery or Javascript

Sometime we need to manually trigger a click event on an element (e.g. button). Here are Javascript and jQuery code snippets for this. This is read more

jQuery post form data using ajax

Javascript code snippet to submit a form using POST to server and process returned data. Here when submit button is clicked we serialize whole form read more

Ubuntu – check if a service is upstart based

Ubuntu Linux (version 14) uses upstart to manage processes. But not all services are converted to upstart. Some are using sysv init. Also note that read more

Install nginx and php in docker ubuntu container

Docker can be used to install nginx and php5 (php-mpm) in a ubuntu container. We’ll cover docker running on Mac and Ubuntu Linux for the read more

Docker managing images – command line cheat sheet

Docker images are needed to create and run a container. These are be pulled from remote docker repository or can also be created locally. Here read more

Docker – how to rerun a container with different flags

In case you want to rerun a running container with different flags (e.g. -p port1:port2), you can follow these steps. Stop the container and commit read more

Ubuntu – how to find boot autostart status of a service

There are two types of services on Ubuntu Linux (Ubuntu version 14). One are upstart based and others based on sysv init. To check if read more

Ubuntu – how to auto start services on boot using update-rc.d (sysv init)

Utility update-rc.d is part of sysv init (package sysv-rc) on Ubuntu Linux. It can be used to manage services at boot time. It can be read more

How to find docker host ip on Mac

Docker runs a separate Docker host (small footprint Linux VM) on Mac which is different from main machine. So any port which maps to container read more

PHP how to get current url

PHP $_SERVER is an array containing information such as headers, paths, and script locations. To get current url we can use $_SERVER[‘REQUEST_URI’] and $_SERVER[‘HTTP_HOST’]. Here read more

React – list of all factory methods of React.DOM

React has many factory methods for inbuilt components like div, span, etc. Here is javascript code snippet which can be used to dump all methods read more

node – how to find source file location of a module

To find the file location for a node module require(‘module’)._resolveFilename can be used. Here is quick code snippet and its outcome. file = require(‘module’)._resolveFilename(‘react’) console.log(“react read more

node – how to fix cannot find module error

Node script when run in limited environment (e.g. php exe, cron, etc.) can throw cannot find module error. The error may look like this: throw read more

node – how to find version of installed package

To find the version of a node package one can use npm list (optionally -g for global). Another option is to use javascript code and read more

Javascript – print all methods of an object

To print all methods of an object, we can use Object.getOwnPropertyNames and check if the corresponding value is a function. The Object.getOwnPropertyNames() method returns an read more

React component tutorial with click handler – javascript version

This tutorial is javascript version is React component tuorial with click handler – jsx version. It is recommended that you visit that tutorial before reading read more

React javascript render hello world

React render can be written purely in Javascript without jsx. For JSX version of this tutorial you can visit React jsx hello world. Here is read more

React.render vs ReactDOM.render – which one should be used?

Question: I see some React tutorials using React.render and some using ReactDOM.render. Which one should be used? React introduced react-dom package in version 0.14 which read more

React – JSXTransformer vs babel – which one should be used?

Question: I see tutorials using JSXTransformer and babel in various articles. Which one should be used? React was using JSXTransformer to compile and transform jsx read more

Python xrange examples

Python xrange can be used to generate a sequence of numbers with desired start number and gap. It is often used in for loops. It read more

Python range examples

Python range can be used to generate a range of numbers with desired start number and gap. It is often used in for loops. Usage: read more

Javascript arrow function examples

Arrow (=>) function expressions are shorter syntax compared to function expressions. Arrow functions are always anonymous. Here are some commonly used usage syntax patterns. singleParam read more

Ubuntu docker – storage driver aufs not supported error

In case you get the following error in docker service start log (/var/log/upstart/docker.log) on Ubuntu Linux (14.04), [graphdriver] prior storage driver “aufs” failed: driver not read more

Javascript – call vs apply

Javascript call() and apply() can be used to invoke a function. They are mostly same. The only difference is in apply arguments are passed as read more

React component tutorial with click handler – jsx version

A basic React components implement a render method that takes input data and returns what to display. For the purpose of this tutorial, it will read more

Javascript – create array from 0 to N-1 in nodejs

In Javascript to create an array of number from 0 to n-1, we can use spread operator. It is part of ECMAScript (version 6). Currently read more

React – How to fix SyntaxError – Adjacent JSX elements must be wrapped in an enclosing tag

React element can return only one element. In case you have the following code, you will get “Adjacent JSX elements must be wrapped in an read more

React jsx hello world with offline transformation

React JSX code can be compiled offline to transform into javascript code. This eliminates need to include babel code in browser. To see how it read more

ReactJS – convert jsx to javascript using babel cli

React JSX code can be offline transformed into javascript code using babel compiler command line tool. You may also want to visit React JSX quick read more

React jsx hello world

JSX is a JavaScript syntax extension that looks similar to XML. It is used by React code and it is optional to use JSX. Everything read more

PHP array map example

PHP array map applies the callback function to one or more arrays. In callback we can use a function or anonymous function. Here are some read more

Css position property – static, relative, absolute and fixed positioning

CSS position property decides how an element will be places in document. It can have 4 values static (default), relative, absolute and fixed. Understanding position read more

css z-index – ordering of overlapping elements

CSS z-index property decides the ordering of elements when they overlap. Higher z-index mean it is closer to you and hence with appear accordingly. Few read more

Python itertools imap examples

Python itertools imap is efficient way of mapping and looping over a large iterable. Here is the usage for imap: itertools.imap(function, *iterables) The function should read more

Python itertools ifilter examples

Python itertools.ifilter is efficient way of filtering and looping over a large iterable. Here is the usage for ifilter: itertools.ifilter(function, iterable) The function should take read more

Install ffmpeg on Ubuntu Linux

Ubuntu Linux (14.04) does not have ffmpeg in default package source repositories. ffmpeg can be installed using mc3man ppa (personal package archive) using the following read more

WordPress – query to dump all categories

WordPress mysql query to dump all categories (id, slug, name, description, count) SELECT wp_terms.term_id, wp_terms.slug, wp_terms.name, wp_term_taxonomy.description, wp_term_taxonomy.count FROM wp_term_taxonomy join wp_terms on (wp_term_taxonomy.term_id = read more

WordPress – query to dump all tags

WordPress mysql query to display all tags (id, slug, name, description, count) SELECT wp_terms.term_id, wp_terms.slug, wp_terms.name, wp_term_taxonomy.description, wp_term_taxonomy.count FROM wp_term_taxonomy join wp_terms on (wp_term_taxonomy.term_id = read more

HTML5 – video tag

HTML5 video tag (<video>) can be used to play a vide in HTML page. Here are some examples of video tag using webm and mp4 read more

Command line – scale a video using ffmpeg

Command line utility ffmpeg can be used to scale a video to a specific widht and height. Here are some examples. Resize to given width read more

Mac – how to convert mp4 to webm

Command line utility ffmpeg can be used to convert mp4 video to webm format on Mac or Linux. Here are quick steps for Mac. First read more

Python re (regex) replace examples

Python regular expression module can be used to replace a pattern in a string using re.sub. Basic usage of re.sub is: re.sub(pattern, repl, string, count=0, read more

Javascript/jQuery – disable right click

Right click can be disable by attaching a even listener to contextmenu event. It can be done using jQuery or vanilla Javascript. disable right click read more

Ubuntu – find where will a package be installed from

Ubuntu apt-cache policy can be used to find the sources of a package and their order. This can be helpful in case we are downloading/installing read more

Python re (regex) search examples

Python regular expression module (re) can be used to find presence of a pattern in a string using re.search. Basic usage of re.search is: re.search(pattern, read more

Python etl petl – read table from csv file

Python elt library petl can be used to perform extract/load – reading/writing tables from files and databases. In this tutorial we’ll read a table in read more

Python file read write examples

Reading and writing files in python is very common use case. Here are some examples: Write to file using “with open()” Here file gets closed read more