Skip to content

Instantly share code, notes, and snippets.

View theskumar's full-sized avatar

Saurabh Kumar theskumar

View GitHub Profile
@theskumar
theskumar / gist:3427715
Created August 22, 2012 17:22
js: split_to_array()
function split_to_array (body, chunklen) {
// * example 1: chunk_split('Hello world!', 1);
// * returns 1: 'H*e*l*l*o* *w*o*r*l*d*!*'
// * example 2: chunk_split('Hello world!', 10, '*');
// * returns 2: '["Hello worl","d!"]'
chunklen = parseInt(chunklen, 10) || body.length;
if (chunklen < 1) {
return false;
}
@theskumar
theskumar / gist:3427413
Created August 22, 2012 16:51
js: chunk_split()
function chunk_split (body, chunklen, end) {
// http://kevin.vanzonneveld.net
// + original by: Paulo Freitas
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Theriault
// * example 1: chunk_split('Hello world!', 1, '*');
// * returns 1: 'H*e*l*l*o* *w*o*r*l*d*!*'
// * example 2: chunk_split('Hello world!', 10, '*');
// * returns 2: 'Hello worl*d!*'
@theskumar
theskumar / gist:3423710
Created August 22, 2012 08:16
js: sort_by function
// reusable sort functions, and sort by any field
// UsagesSort by price high to low
// homes.sort(sort_by('price', true, parseInt));
// Sort by city, case-insensitive, A-Z
// homes.sort(sort_by('city', false, function(a){return a.toUpperCase()}));
var sort_by = function(field, reverse, primer){
var key = function (x) {return primer ? primer(x[field]) : x[field];};
return function (a,b) {
var A = key(a), B = key(b);
@theskumar
theskumar / ga: page scroll
Created August 2, 2012 16:54
Google analytics script for tracking page scroll
// Google Analystics Script: Track page scroll
// All you need is to add where _gaq defined:
// https://github.com/h5bp/html5-boilerplate/wiki/ga-augments
$(function(){
var isDuplicateScrollEvent,
scrollTimeStart = new Date,
$window = $(window),
$document = $(document),
scrollPercent;
@theskumar
theskumar / Preferences.sublime-settings
Created July 2, 2012 10:35
sublime: user settings
{
"font_size": 12,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"draw_white_space": "all"
}
@theskumar
theskumar / list_countries.txt
Created April 22, 2012 17:07
Complete list of countries in world
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria
@theskumar
theskumar / .gitignore
Created April 22, 2012 05:38
csharp .gitignore file
[Oo]bj
[Bb]in
*.user
*.suo
*.[Cc]ache
*.bak
*.ncb
*.log
*.DS_Store
[Tt]humbs.db
@theskumar
theskumar / paragraph-width-fix.css
Created March 27, 2012 06:32
css: paragraph min width with fluid elements
p:before {
content: "";
width: 10em;
display: block;
overflow: hidden;
/* For Demonstration */
border: 1px solid green;
}
@theskumar
theskumar / gist:1998923
Created March 8, 2012 05:32
javacript - async load
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//third-party.com/resource.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
@theskumar
theskumar / sample.php
Created March 2, 2012 14:25
Docblock Comment standards
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Short description for file
*
* Long description for file (if any)...
*
* PHP version 5