Skip to content

Instantly share code, notes, and snippets.

@ajcrites
ajcrites / gist:5264800
Last active December 15, 2015 13:08
Image explanation
span {
display: inline-block;
background: url(IMAGE);
width: 156px;
height: 154px;
border: 1px solid blue;
}
@ajcrites
ajcrites / gist:5868194
Created June 26, 2013 15:07
DOMNodeList from `xpath::query` weird parents
<?php
$nodes = <<<HTML
<div>
div
<p> ... </p>
</div>
HTML;
$dom = new DOMDocument;
$dom->loadHTML($nodes);
@ajcrites
ajcrites / gist:6249540
Created August 16, 2013 12:39
Example of synchronous vs. asynchronous JS
// Old, bad, antiquated way
var value = db.synchronousRead("SELECT value");
emit(value);
// Good, asynchronous way
db.asynchronousRead("SELECT value").done(function (value) {
emit(value);
});
@ajcrites
ajcrites / gist:6249591
Created August 16, 2013 12:49
Parallel vs. serial independent node operations
// Serial, naive implementation
// one and two are not dependent on each other
db.read("SELECT ONE").done(function (one) {
db.read("SELECT TWO").done(function (two) {
emit(one, two);
});
});
// Parallel
var async = require("async");
export PS1='\[\e[01;32m\]andrew\[\e[01;3$(($RANDOM % 8))m\]@\[\e[01;32m\]home \[\e[01;31m\]\w \[\e[01;33m\]$\[\e[0m\] '
randomize_prompt_color () {
git=$(git_prompt_info)
if [ -n "$git" ]; then
git="$git "
fi
PROMPT="%{$fg_bold[green]%}%n%F{$((RANDOM % 8))}@%{$fg[magenta]%}%m %{$fg_bold[cyan]%}%~ %{$fg_bold[blue]%}$git%{$fg_bold[red]%}%(!.#.\$) %{$reset_color%}"
if [ -n "$VIRTUAL_ENV" ]; then
PROMPT="(pyvenv: $(basename $VIRTUAL_ENV)) $PROMPT"
fi
}
@ajcrites
ajcrites / reqParams.js
Last active December 22, 2015 20:29 — forked from L1fescape/reqParams.js
function required(params) {
return function (req, res, cb) {
params.every(function (elem) { return req.body.hasOwnProperty(elem); })
&& cb()
|| res.send(400);
};
};
/**
* Sample route
@ajcrites
ajcrites / gist:6939254
Last active December 25, 2015 07:29
Valid in JavaScript but not JSON
// quotes around keys are not required
( {key: "value"} );
// many JS parsers allow a trailing comma in a list
( [{"name": "value"},] )
/* syntax errors */
{"k": "v"}
function () {}()
/* valid */
( {"k":"v"} )
( function () {}() )
$.getJSON().done(function (json) {
$.parseJSON(json);
});