Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / object.keys.js
Created December 5, 2013 08:45
Object.keys pollyfill
Object.keys = function (obj) {
var keys = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
keys.push(key);
}
}
return keys;
};
@dannycroft
dannycroft / chunk.lodash.js
Created November 25, 2013 19:28
Lodash / Underscore method for breaking data sets into smaller sets (chunks)
/**
* Lodash / Underscore method for breaking data sets into smaller sets (chunks)
*
* @arguments
*
* collection: Array / Object
* chuckSize: Number
*
* @example
*
@dannycroft
dannycroft / exclude-node-modules
Last active February 27, 2019 18:25
Exclude node_modules out of Sublime Text 2 searches
// Add the following to your preferences file
"folder_exclude_patterns":[".git","node_modules"]
@dannycroft
dannycroft / throttle
Created February 5, 2013 12:42
Network throttling for OSX
#!/bin/bash
#
# Throttles your Mac OS X internet connection on one port.
# Handy for testing
set -e
RATE=15KByte/s
PORT=80
PIPE_NUMBER=1
#!/bin/sh
(( ${#} > 0 )) || {
echo 'DISCLAIMER: USE THIS SCRIPT AT YOUR OWN RISK!'
echo 'THE AUTHOR TAKES NO RESPONSIBILITY FOR THE RESULTS OF THIS SCRIPT.'
echo "Disclaimer aside, this worked for the author, for what that's worth."
echo 'Press Control-C to quit now.'
read
echo 'Re-running the script with sudo.'
echo 'You may be prompted for a password.'
sudo ${0} sudo
@dannycroft
dannycroft / farce.js
Created October 12, 2012 09:23
Simple dollar selector method
function $(selector) {
try {
return Array.prototype.slice.call(
document.querySelectorAll(selector));
} catch(e){}
return jQuery(selector); //Fallback on another framework
}
@dannycroft
dannycroft / launch_sublime_from_terminal.markdown
Created August 6, 2012 20:25 — forked from artero/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@dannycroft
dannycroft / gist:3237084
Created August 2, 2012 13:24
Show Optimizely Settings
(function(){
// Return if the page hasn't loaded
if (document.readyState !== "complete") { alert("Please wait for the page to load"); return; };
// Return if Optimizely isn't available
if (typeof window.optimizely !== "object") { alert("Optimizely isn't available"); return; }
// Collect and assign optimizely data
var data = window.optimizely.data;
@dannycroft
dannycroft / gist:2968193
Created June 21, 2012 20:01
Enable Safari Debug menu
defaults write com.apple.Safari IncludeInternalDebugMenu 1
casperjs test ~/Desktop/unit_tests/duckduck.js