Skip to content

Instantly share code, notes, and snippets.

@anjan011
anjan011 / snippet-php-output-stream.php
Last active November 9, 2015 06:55
An example showing usage of php output stream to perform some file operation directly to browser like fputcsv()
<?php
/*********************************************************************
* By: Anjan @ Nov 09, 2015 12:16 PM
*********************************************************************
* Generate a CSV file and send output directly to browser
*
* This example shows the use of php output stream to perform some
* file operation directly to browser itself
*********************************************************************/
@anjan011
anjan011 / function-formatted-time-difference.php
Last active November 9, 2015 06:55
A function to convert difference between timestamps in seconds into human readable format
<?php
/**
* Converts a time difference in seconds to human readable format.
*
* This function takes a time difference in seconds and converts it into human readable format
* by breaking the difference into time units like year, month, day, hour, minute and seconds.
* Example: [4820] => [1 hour 20 minutes 20 seconds]. The difference is always considered a
* positive number or 0.
*
@anjan011
anjan011 / function-array-value.php
Last active November 9, 2015 06:54
A function to fetch value from any array using a key or key path
<?php
/**
* Get array value.
*
* It takes the array and a key name or a key path to access element in single or
* multi-dimensional array. If value is not found, default value is returned.
*
* @param array $array The array to conduct the search on
* @param string $key The Key name or key path (a/b/c/d)
@anjan011
anjan011 / css-clearfix-by-overflow.css
Last active November 11, 2015 11:25
css - clearfix using overflow
/**
* Clearfix using overflow. This will present scrollbars through,
* if the cobtainer has fixed height but content exceeds the height
*/
.clearfix {
overflow: auto;
}
@anjan011
anjan011 / css-vertical-align-by-transform.css
Last active November 11, 2015 11:25
css - vertical align using css tansform
/**
* Vertical alignment inside a parent container with fixd height.
* Will not work without fixed height. Of course goes without saying
* that browser must support css3 transform.
*
* see: http://caniuse.com/#search=transform
*/
.valign-top {
@anjan011
anjan011 / php-get-vimeo-video-id-from-url.php
Created November 11, 2015 14:39
php - get vimeo video id from url
<?php
/**
* Get Vimeo video id from url
*
* Supported url formats -
*
* https://vimeo.com/11111111
* http://vimeo.com/11111111
@anjan011
anjan011 / php-vimeo-video-thumbnail-url.php
Created November 11, 2015 15:19
php - get vimeo video thumbnail image url
<?php
/**
* Gets the thumbnail url for a vimeo video using the video id. This only works for public videos.
*
* @param string $id The video id.
* @param string $thumbType Thumbnail image size. supported sizes: small, medium (default) and large.
*
* @return string|bool
@anjan011
anjan011 / is-valid-rgba-color.js
Created November 14, 2015 02:44
Is valid RGBA color?
/**
* Is the given string a valid RGBA color?
*
* @param colorString
*
* @returns {boolean}
*/
function isValidRgbaColorFormat(colorString) {
@anjan011
anjan011 / is-valid-rgba-color.php
Last active November 14, 2015 03:05
php - Is valid RGBA color?
<?php
/**
* Is Valid RGBA color?
*
* @param $colorString
*
* @return bool
@anjan011
anjan011 / regex-rgba-color-validation.reg
Created November 14, 2015 03:04
RegEx - RGBA color validation
^rgba\(([0]*[0-9]{1,2}|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])\s*,\s*([0]*[0-9]{1,2}|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])\s*,\s*([0]*[0-9]{1,2}|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])\s*,\s*([0-9]*\.?[0-9]+)\)$