Skip to content

Instantly share code, notes, and snippets.

@icodeforlove
icodeforlove / gist:4179410
Created November 30, 2012 23:20
bash_profile functions for additional repo info
parse_git_branch() {
slashes=${PWD//[^\/]/}
directory="$PWD"
path=false
if [ -d ".git" ]; then
path="."
else
for (( n=${#slashes}; n>0; --n )) do
test -e "$directory/.git" && path="$directory"
@icodeforlove
icodeforlove / PromiseStack.js
Last active December 11, 2015 22:29
add a few features kind of like async's forEachLimit but for what.js
// example:
//
// var promises = new PromiseStack();
//
// for (var i = 0; i < 10; i++) promises.push(/* a promise */, /* args... */);
//
// promises.limit(
// 4,
// function () {
// console.log('success');
<html>
<head>
<meta property="og:video" content="http://www.youtube.com/v/rRoy6I4gKWU?version=3&amp;autohide=1">
<meta property="og:video:type" content="application/x-shockwave-flash">
<meta property="og:video:width" content="1280">
<meta property="og:video:height" content="720">
</head>
</html>
@icodeforlove
icodeforlove / doesCommandExist.js
Created April 12, 2013 17:59
node system command check
var spawn = require('child_process').spawn;
function doesCommandExist (command, callback) {
var child = spawn('type', [command]);
child.on('close', function (code) {
callback(!code);
});
}
@icodeforlove
icodeforlove / log-stylesheets.js
Last active December 21, 2015 02:18
logs out all stylesheets in chrome
Array.prototype.slice.call(document.styleSheets).forEach(function (stylesheet, index, array) {
if (!stylesheet.rules) return;
console.groupCollapsed("Stylesheet #%s", index);
Array.prototype.slice.call(stylesheet.rules).forEach(function (rule, index, array) {
var properties = rule.cssText.match(/\{\s+?(.+)\s+?\}/);
if (rule.type === 1) {
console.log('%s%c %s', rule.selectorText, 'font-weight: normal; color: #999', properties ? properties[1] : '');
@icodeforlove
icodeforlove / vons.js
Last active December 10, 2016 02:54
easier way to order on shop.safeway.com
var script = document.createElement('script'); script.src = 'http://code.jquery.com/jquery-2.0.3.min.js'; document.head.appendChild(script);
var order = {
960015155: 1, // Lucerne Cheese Natural Pepper Jack - 32 Oz
960035197: 1, // Coke Soda Diet - 20-12 Fl. Oz.
188560047: 1, // Smithfield Bacon Naturally Hickory Smoked Thick Sliced - 16 Oz
960030810: 1, // Claim Pie Lattice Apple Jumper - 46 Oz
184490015: 3, // Green Jalapeno Peppers
184060007: 5, // Bananas
// 960073834: 1, // Safeway Farms White Whole Mushrooms - 16 Oz
@icodeforlove
icodeforlove / insert_data.sql
Created September 12, 2013 19:27
insert_data procedure takes about 230 seconds to run 1 million inserts
DELIMITER ;;
CREATE PROCEDURE insert_data()
BEGIN
DECLARE i INT DEFAULT 0;
WHILE i < 1000000 DO
/* QUERY */
SET i = i + 1;
END WHILE;
END;;
@icodeforlove
icodeforlove / dabblet.css
Created November 10, 2013 07:21
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@icodeforlove
icodeforlove / getBlocksFromRect.js
Last active December 28, 2015 06:29
getBlocksFromRect.js
function getBlocksFromRect(width, height, blockCount) {
var blocks = [], cols, rows;
if (Math.sqrt(blockCount) === Math.floor(Math.sqrt(blockCount))) {
cols = rows = Math.sqrt(blockCount);
} else {
cols = blockCount / 2 === Math.floor(blockCount / 2) ? 2 : 1;
rows = blockCount / cols;
}
@icodeforlove
icodeforlove / AsyncTaskThrottle.js
Last active December 28, 2015 19:59
easy way to throttle async tasks
function AsyncTaskThrottle () {
this._queued = null;
this._busy = false;
}
AsyncTaskThrottle.prototype = {
do: function (task) {
if (!this._busy) {
this._queued = task;
return this._call();