Skip to content

Instantly share code, notes, and snippets.

View dhigginbotham's full-sized avatar
😸
happycat

David Higginbotham dhigginbotham

😸
happycat
View GitHub Profile
@mbostock
mbostock / .block
Last active February 9, 2016 01:57
Merging Counties
license: gpl-3.0
@tj
tj / example.js
Created July 31, 2013 18:48
console.api()
function params(fn) {
var str = fn.toString();
var sig = str.match(/\(([^)]*)\)/)[1];
if (!sig) return [];
return sig.split(', ');
}
console.api = function(obj){
console.log();
var proto = Object.getPrototypeOf(obj);
@brettz9
brettz9 / Array.prototype.slice.html
Last active February 18, 2021 06:54
(NOTE: This has been since improved to handle negative values at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice#Streamlining_cross-browser_behavior ); Polyfill for "fixing" IE's lack of support (IE < 9) for applying slice on host objects like NamedNodeMap, NodeList, and HTMLCollection (technically, s…
<!DOCTYPE html>
<body id="body" class="abc"><script src="Array.prototype.slice.js"></script><script src="testing-Array.prototype.slice.js"></script>
</body>

Readline example

readline = require "readline"
rl = readline.createInterface
  input:  process.stdin
  output: process.stdout

Example of named functions

You could use named functions to better read callbacks instead of deeply nested

@MrDHat
MrDHat / EventEmmiter.js
Last active December 19, 2015 15:48
A Pub/Sub API (Originally written for Gaia)
this.EventEmmiter = (function() {
var events = {};
var UUID = -1;
// Function to publish/trigger events
function trigger(evt, args) {
if (!events[evt]) {
return false;
#define HTTP_STATUS_100 "100 Continue"
#define HTTP_STATUS_101 "101 Switching Protocols"
#define HTTP_STATUS_102 "102 Processing"
#define HTTP_STATUS_200 "200 OK"
#define HTTP_STATUS_201 "201 Created"
#define HTTP_STATUS_202 "202 Accepted"
#define HTTP_STATUS_203 "203 Non-Authoritative Information"
#define HTTP_STATUS_204 "204 No Content"
#define HTTP_STATUS_205 "205 Reset Content"
#define HTTP_STATUS_206 "206 Partial Content"
var car_options = 0x5; // binary 0101
var LEATHER_SEATS = 0x1; // 0001
var TURBO = 0x2; // 0010
var HID_LIGHTS = 0x4; // 0100
var SPORT_KIT = 0x8; // 1000
var daves_car = LEATHER_SEATS | HID_LIGHTS | SPORT_KIT; // 0001 | 0100 | 1000 => 1011 // 1 + 4 + 8 = 13
@machty
machty / new-router-examples.md
Last active April 16, 2020 22:03
How to do cool stuff with the new Router API
@mweibel
mweibel / passport-mock.js
Last active May 14, 2024 09:32
Mock passport.js with an own strategy
/**
* Author: Michael Weibel <michael.weibel@gmail.com>
* License: MIT
*/
var passport = require('passport')
, StrategyMock = require('./strategy-mock');
module.exports = function(app, options) {
// create your verify function on your own -- should do similar things as
@6eDesign
6eDesign / gist:5199580
Last active December 15, 2015 04:09
This delay function is neat. Useful for events which can fire repeatedly such as the window re-size. If the delay function is called again before the supplied 'ms' parameter, another timer is started (In other words: the browser only executes your window-just-changed-size function after the window has been re-sized and remained that size for a c…
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
var checkIfMobile = function() {