Skip to content

Instantly share code, notes, and snippets.

Gagan Bansal gagan-bansal

Block or report user

Report or block gagan-bansal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nirvanatikku
nirvanatikku / css_inline_transformer.js
Created Dec 2, 2016
JavaScript CSS Inline Style Transformer (convert CSS + HTML into HTML with inline styles)
View css_inline_transformer.js
/**
* CSS Inline Transform v0.1
* http://tikku.com/css-inline-transformer-simplified
*
* Copyright 2010-2012, Nirvana Tikku
* Dual licensed under the MIT or GPL Version 2 licenses.
* https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt
*
* This tool leverages the jQuery library.
*
@cgmartin
cgmartin / logging-middleware.js
Created May 24, 2015
Morgan JSON log format example
View logging-middleware.js
'use strict';
var morgan = require('morgan');
var os = require('os');
morgan.token('conversation-id', function getConversationId(req) {
return req.conversationId;
});
morgan.token('session-id', function getSessionId(req) {
return req.sessionId;
@MarZab
MarZab / ngrams.js
Created Apr 13, 2015
JavaScript Implementation of N-Gram Text Categorisation based on paper by William B. Cavnar and John M. Trenkle
View ngrams.js
'use strict';
/*
N-Gram-Based Text Categorisation
Implementation by marko@zabreznik.net
28.3.2015 All rights reserved.
Based on the paper by:
William B. Cavnar and John M. Trenkle
Environmental Research Institute of Michigan
@joshua-barnett
joshua-barnett / pan-zoom-image.js
Last active Oct 16, 2018
A simple way of panning and zooming an image using Hammer.js.
View pan-zoom-image.js
// <img id="myimage" src="http://placecage/1280/720">
var image = document.getElementById('myimage');
var mc = new Hammer.Manager(image);
var pinch = new Hammer.Pinch();
var pan = new Hammer.Pan();
pinch.recognizeWith(pan);
@iwek
iwek / csv-to-json.js
Last active May 29, 2020
CSV to JSON Conversion in JavaScript
View csv-to-json.js
//var csv is the CSV file with headers
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
@mudge
mudge / eventemitter.js
Last active May 29, 2020
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
View eventemitter.js
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@jbub
jbub / squash-commits.sh
Created Jun 12, 2013
git squash last two commits into one
View squash-commits.sh
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
@pazguille
pazguille / exports.js
Last active Oct 11, 2015
Exports your library - support AMD / CommonJS
View exports.js
// @see http://addyosmani.com/writing-modular-js/
// library was previously defined
// AMD suppport
if (typeof window.define === 'function' && window.define.amd !== undefined) {
window.define('library', [], function () {
return library;
});
// CommonJS suppport
} else if (typeof module !== 'undefined' && module.exports !== undefined) {
View avoid-jquery-when-possible.md

Avoid jQuery When Possible

jQuery does good jobs when you're dealing with browser compatibility. But we're living in an age that fewer and fewer people use old-school browsers such as IE <= 7. With the growing of DOM APIs in modern browsers (including IE 8), most functions that jQuery provides are built-in natively.

When targeting only modern browsers, it is better to avoid using jQuery's backward-compatible features. Instead, use the native DOM API, which will make your web page run much faster than you might think (native C / C++ implementaion v.s. JavaScript).

If you're making a web page for iOS (e.g. UIWebView), you should use native DOM APIs because mobile Safari is not that old-school web browser; it supports lots of native DOM APIs.

If you're making a Chrome Extension, you should always use native APIs, not only because Chrome has almost the latest DOM APIs available, but this can also avoid performance issue and unnecessary memory occupation (each jQuery-driven extension needs a separate

@rochacbruno
rochacbruno / haversine.py
Created Jun 6, 2012
Calculate distance between latitude longitude pairs with Python
View haversine.py
#!/usr/bin/env python
# Haversine formula example in Python
# Author: Wayne Dyck
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
You can’t perform that action at this time.