Skip to content

Instantly share code, notes, and snippets.

View dandean's full-sized avatar
🌧️
It's raining.

Dan Dean dandean

🌧️
It's raining.
View GitHub Profile
@dandean
dandean / stripey-warning.css
Created March 21, 2013 18:31
Some stripey CSS shit.
div[data-preference="card-management"]:before {
content:"";
display: block;
position: absolute;
left: 0;
top: 61px;
width: 100%;
height: 6px;
-webkit-background-size: 50px 50px, 100%;
::-webkit-scrollbar {
-webkit-appearance: none;
width: 7px;
}
::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: rgba(0,0,0,.5);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}
@dandean
dandean / test.sh
Created February 7, 2013 17:46
Check that a program exists before executing it in a shell script
# http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
hash foo 2>/dev/null || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }

What is the best way to inject a value into the middle of arguments?

  1. Would prefer it to be a one liner
  2. Need it to be really fast!

JSPerf here: http://jsperf.com/inject-into-arguments

Of the two below "slice-and-concat.js" is 12% faster in Chrome.

@dandean
dandean / hash_converter.rb
Created October 3, 2012 05:48 — forked from timruffles/hash_converter.rb
rails hash formatter - hash/json to/from camel case and underscores
module HashConverter
class << self
def to_underscore hash
convert hash, :underscore
end
def to_camel_case hash
convert hash, :camelize, :lower
end
def convert obj, *method
case obj
@dandean
dandean / DenbyMustache.js
Created September 9, 2012 04:57
Denby extended with Mustache rendering support
var Denby = require('denby');
var Mustache = require('mustache');
/**
* new DenbyMustache(options)
* - options (Object): Configuration options.
*
* See [DenbyMustache#options] and [Denby#options] for more information.
**/
function DenbyMustache(options) {
document.addEventListener('keydown', function(e) {
window.lol = window.lol || 0;
window.lol++;
console.log(lol);
}, false);
@dandean
dandean / pre-commit
Created March 23, 2012 18:15
pre-commit hook for stripping trailing whitespace
#!/bin/sh
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Find files with trailing whitespace
for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' | sed -E 's/:[0-9]+:.*//' | uniq` ; do
@dandean
dandean / portland.craigslist.org.js
Created February 28, 2012 01:03
Remove the burbs
// Removes craigslist listings for portland suburbs
$('blockquote font[size="-1"]').each(function(i, element) {
var text = element.textContent.trim();
if (text.match(/Gresham|Beaverton|Troutdale|Wilsonville|Sellwood|WOODLAND/i)) {
$(element.parentNode).hide();
}
});
@dandean
dandean / modulr-node-test.js
Created December 13, 2011 08:04
modulr-node search paths
// 1. Collect our modules, using the specified directories...
require('modulr').build('client',
{
isPackageAware: true,
paths: ['.','./node_modules'],
},
function(e, result) {
if (e) {
throw e;
}