Skip to content

Instantly share code, notes, and snippets.

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
* Copyright 2010-2012, Nirvana Tikku
* Dual licensed under the MIT or GPL Version 2 licenses.
* This tool leverages the jQuery library.
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 / 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
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 / 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();
iwek / csv-to-json.js
Last active Mar 10, 2021
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 / eventemitter.js
Last active Apr 7, 2021
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 /
Created Jun 12, 2013
git squash last two commits into one
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 / exports.js
Last active Oct 11, 2015
Exports your library - support AMD / CommonJS
View exports.js
// @see
// 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) {
tkrueger / load-generator.js
Created Aug 28, 2012
generate and measure CPU load with node.js
View load-generator.js
#!/usr/bin/env node
var shouldRun = true;
var desiredLoadFactor = .5;
function blockCpuFor(ms) {
var now = new Date().getTime();
var result = 0

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