Skip to content

Instantly share code, notes, and snippets.

@Kami
Kami / gist:824099
Created February 12, 2011 20:41
Benchmark results (PyPy & NodeJS)
Intel Core 2 Quad E6700 @ 3.00
8 GB ram
Ubuntu 10.10
100k iterations
CPython 2.6.6
100.508443832
101.226439953
@aih
aih / parseAndModifyHtml.js
Created May 8, 2011 17:27 — forked from clarkdave/parseAndModifyHtml.js
Using node.js to parse HTML with jsdom and modify it with jQuery
/**
* npm install jsdom
* npm install jquery
*/
var html = "<!doctype html><html><body><h1>Hello world!</h1></body></html>";
/* parse the html and create a dom window */
var window = require('jsdom').jsdom(html, null, {
// standard options: disable loading other assets
@caseyjustus
caseyjustus / median.js
Created August 23, 2011 19:34
calculate the median of an array with javascript
function median(values) {
values.sort( function(a,b) {return a - b;} );
var half = Math.floor(values.length/2);
if(values.length % 2)
return values[half];
else
return (values[half-1] + values[half]) / 2.0;
@dbainbridge
dbainbridge / sessionsStringFix.js
Created April 3, 2012 00:48
node-inspector full string output fix
// Replace refToObject in node-inspector's lib/sessions.js file to get rid of the 80 character limit on strings outputted from the console or tool tip.
// The Scope Variables panel will still show maximum of 80 characters along with the "(length: x)" suffix
function refToObject(ref) {
var desc = '',
name,
kids = ref.properties ? ref.properties.length : false;
switch (ref.type) {
case 'object':
name = /#<an?\s(\w+)>/.exec(ref.text);
@cowboy
cowboy / 1.before.js
Created June 25, 2012 17:46
grunt: an example of building task targets dynamically
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
min: {
ariaAccessibility: {
src: ['src/javascripts/jquery.selectBoxIt.ariaAccessibility.js'],
dest: 'src/javascripts/jquery.selectBoxIt.ariaAccessibility.min.js'
},
@lakenen
lakenen / detectanimation.js
Created June 28, 2012 17:17
JavaScript animated GIF detection!
function isAnimatedGif(src, cb) {
var request = new XMLHttpRequest();
request.open('GET', src, true);
request.responseType = 'arraybuffer';
request.addEventListener('load', function () {
var arr = new Uint8Array(request.response),
i, len, length = arr.length, frames = 0;
// make sure it's a gif (GIF8)
if (arr[0] !== 0x47 || arr[1] !== 0x49 ||
@rawsyntax
rawsyntax / config
Created July 11, 2012 16:43
faster ssh
Host *
# don't try to authenticate with Kerberos
GSSAPIAuthentication no
GSSAPIKeyExchange no
# persist the ssh connection for 5 minutes
# subsequent ssh connections respond faster because its reusing an existing connection
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
ControlPersist 5m
@jrtipton
jrtipton / metrobone.js
Created July 27, 2012 16:20
Make a Backbone.Collection behave like a WinJS.Binding.List (for e.g. WinJS.UI.ListView)
// Metrobone.js 0.0.1
//
// J.R. Tipton @jrtipton
// Metrobone is a wimpy little utility library for
// making Backbone.js integrate with WinJS controls
// (for Windows 8 development) a little easier.
//
// Two basic ways to use this overly verbose little
// guy:
//
@Chrisedmo
Chrisedmo / Mountain Lion tweaks
Created July 30, 2012 14:30
Mountain Lion tweaks (under the hood)
# ~/.osx — http://mths.be/osx
###############################################################################
# General UI/UX #
###############################################################################
# Set computer name (as done via System Preferences → Sharing)
scutil --set ComputerName "MathBook Pro"
scutil --set HostName "MathBook Pro"
scutil --set LocalHostName "MathBook-Pro"
@adtaylor
adtaylor / UMD_jQuery_plugin.coffee
Created September 3, 2012 11:32
This is an UMD CoffeeScript implementation of Twitter Bootstrap's approach to jQuery plugin development
# ============================================================
# PluginName v0.0.0
# http://URL
# ============================================================
# Copyright 2012 The Beans Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#