Skip to content

Instantly share code, notes, and snippets.

View jdalton's full-sized avatar
🫓

John-David Dalton jdalton

🫓
View GitHub Profile
var assert = require('assert')
, subclass = function(type, proto){
// make sure we are extending a global constructor
// accepted: [Boolean, Number, String, Array, Object, Function, RegExp, Date]
if(!global[type.name] || global[type.name].name != type.name) throw new Error();
var constructor = proto.constructor,
keys = Object.keys(proto),
Obj = process.binding('evals').Script.runInNewContext('x = '+type.name), // eval ftw
@mathiasbynens
mathiasbynens / appify
Created November 12, 2010 13:46 — forked from subtleGradient/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
@csnover
csnover / README.md
Created February 21, 2011 01:11
Gyazo script
  1. Change $path and $uri as necessary in gyazo.php and upload it to your server
  2. Change HOST and CGI as necessary in script and use it to replace Gyazo.app/Contents/Resources/script (right-click -> Show Package Contents to get there)
  3. Continue along as usual
js> isNaN(null);
false
js> null > -1;
true
js> null < 1;
true
js> null > 0;
false
js> null < 0;
false
@devongovett
devongovett / gist:1037265
Created June 21, 2011 04:47
jsondb + msgpack
var arr = [],
obj = {'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]};
for(var i = 0; i < 5000; i++)
arr.push(obj);
// jsondb(arr) looks something like this:
// ["abcdef", "qqq", "19", [1, 13, [1, 2, 3, 4]], [1, 13, [1, 2, 3, 4]]...]
> JSON.stringify(arr).length //original
@devongovett
devongovett / gist:1039559
Created June 22, 2011 05:27
JSONDB implementation
###
# JSONDB - a compressed JSON format
# By Devon Govett
# Originally proposed by Peter Michaux - http://michaux.ca/articles/json-db-a-compressed-json-format
#
# jsondb.pack converts an array of objects with the same keys (i.e. from a database)
# and flattens them into a single array, which is much smaller than the pure json
# representation where the keys are repeated for each item in the array.
# Combine with JSON.stringify to send compressed JSON data over the network.
#
@davidaurelio
davidaurelio / hastouch.html
Created September 6, 2011 17:10
Checking for touch support
<!doctype html>
<title>has touch?</title>
<h1>Has this device touch? </h1>
<script>
var isTouch = (function(){
try{
var event = document.createEvent("TouchEvent"); // Should throw an error if not supported
return !!event.initTouchEvent; // Check for existance of initialization method
}catch(error){
return false;
innerWidth / innerHeight tests @ http://sandbox.thewikies.com/orientation/
--------------------------------------------------------------------------------
Tested (14 devices, 28 browsers):
Droid 2 Global Android 2.2
iPhone 4 iOS5 (Safari, Opera Mini)
Motorola Atrix Android 2.3.4 (Stock browser, Dolphin, Skyfire, Opera Mini, Firefox)
Samsung Galaxy S9000 Android 2.3 (Webkit, Opera Mobile)
Samsung Galaxy Y Android 2.3.5
@paulirish
paulirish / rAF.js
Last active March 22, 2024 00:00
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@slevithan
slevithan / xregexp-lookbehind2.js
Created April 14, 2012 21:06
Simulating lookbehind in JavaScript (take 2)
// Simulating infinite-length leading lookbehind in JavaScript. Uses XRegExp.
// Captures within lookbehind are not included in match results. Lazy
// repetition in lookbehind may lead to unexpected results.
(function (XRegExp) {
function prepareLb(lb) {
// Allow mode modifier before lookbehind
var parts = /^((?:\(\?[\w$]+\))?)\(\?<([=!])([\s\S]*)\)$/.exec(lb);
return {