Skip to content

Instantly share code, notes, and snippets.

View danbeam's full-sized avatar
🚲

Dan Beam danbeam

🚲
  • Los Angeles, CA
View GitHub Profile
# lets you do echo 'lol' | todata
# or cat filename | todata
# and it'll spit out a nice data URI
todata() {
if [ ! -t 0 ]; then
php -r "echo 'data:text/plain;base64,'.base64_encode(file_get_contents('php://stdin')); }" && echo;
fi
}
untiny() {
for U in $*; do
curl -I $U 2>/dev/null | grep ^Location | cut -d' ' -f2;
done;
}
nuke() {
local prompt="?";
until [[ "^[YyNn]" =~ "$prompt" ]]; do
echo -n "Are you really sure? (y/n) ";
read prompt;
done;
if [[ "^[Yy]" =~ "$prompt" ]]; then
prompt="?";
until [[ "^[YyNn]" =~ "$prompt" ]]; do
echo -n "Like REALLY sure? (y/n) ";
# find the most popular author with svn blame
svnauthor() {
local FILE;
local AUTH;
local PERCENT;
local BIGGEST;
local WRITTEN;
local TOTAL;
for FILE in $*; do
SVN_ST=$(svn st $FILE 2>&1);
@danbeam
danbeam / Got tired of writing these
Created May 19, 2011 21:31
edit-reload-profile.sh
# reload this profile
reloadprofile() {
[ -x ~/.bash_profile ] && . ~/.bash_profile;
}
# edit this profile
editprofile() {
$EDITOR ~/.bash_profile;
}
flab =
function () {
var s = Array.prototype.slice,
a = [s.call(arguments)],
b = function () {
b._calls = a
a.push(s.call(arguments))
return b
}
b.toString = function () {
@danbeam
danbeam / gist:1013629
Created June 8, 2011 01:55
make-money.html
<!doctype html>
<html>
<body>
<ol>
<li>Work at Yahoo!</li>
<li>???</li>
<li>PROFIT!!!</li>
</ol>
</body>
</html>
@danbeam
danbeam / get-css21-color-min-candidates.js
Created June 9, 2011 09:16
Get the colors that can be optimized on the w3's CSS2.1 color page
// on http://www.w3.org/TR/CSS21/syndata.html
Array.prototype.forEach.call(document.querySelectorAll('span.colorsquare'), function(square) {
var name = square.childNodes[0].innerText,
hex = square.childNodes[1].data.trim();
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
hex = '#' + hex[1]+hex[3]+hex[5];
}
if (hex.length > name.length) {
console.log(hex, '->', name);
}
@danbeam
danbeam / get-css3-color-min-candidates.js
Created June 9, 2011 09:11
Get the colors that can be optimized on the w3's CSS3 color page
// on http://www.w3.org/TR/css3-color/
Array.prototype.forEach.call(document.querySelectorAll('table.colortable')[1].querySelectorAll('td:not(.c)'), function(td) {
var name = td.innerText,
hex = td.nextSibling.innerText;
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
hex = '#' + hex[1]+hex[3]+hex[5];
}
if (hex.length > name.length) {
console.log(hex, '->', name);
}
@danbeam
danbeam / make-min.sh
Created June 14, 2011 23:36
Only $19 if you order today!
#!/bin/bash
DIR=${1:-.};
if [ -z "$YUI" -o ! -r "$YUI" ]; then
echo "You need the path to YUI Compressor as env var \$YUI";
exit 1;
fi
for CSS in `find $DIR -type f -name *.css`; do