Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
AndrewRayCode / gist:825583
Created February 14, 2011 07:15
recursive read directory in node.js returning flattened list of files and directories
function readDir(start, callback) {
// Use lstat to resolve symlink if we are passed a symlink
fs.lstat(start, function(err, stat) {
if(err) {
return callback(err);
}
var found = {dirs: [], files: []},
total = 0,
processed = 0;
function isDir(abspath) {
@AndrewRayCode
AndrewRayCode / gist:1071081
Created July 8, 2011 03:37
broken prompt
color() {
tput setaf $1
shift
printf -- "$@"
tput sgr0
}
color_yellow() {
color 3 "$@"
}
PS1='\n$(color_yellow \u)\w '
@AndrewRayCode
AndrewRayCode / gist:1208792
Created September 10, 2011 21:10
Git is_submodule function
function is_submodule() {
# Find out if the parent directory of our current git repo is also a git repo
parent_git=`cd "$_git_dir/.." && git rev-parse --show-toplevel 2> /dev/null`
if [[ -n $parent_git ]]; then
# If it is, list all submodules of the parent
submodules=`cd $parent_git && git submodule --quiet foreach 'echo $path'`
for line in $submodules; do
# cd to each directory, if it matches our current git repo then we are in a submodule
cd "$parent_git/$line"
if [[ `pwd` = $_git_dir ]]; then return 0; fi
@AndrewRayCode
AndrewRayCode / google_search.py
Created November 14, 2011 03:29
Google search query
import twill.commands
import BeautifulSoup
import time
class browser:
def __init__(self, url="http://www.google.com",log = None):
self.a=twill.commands
self.a.config("readonly_controls_writeable", 1)
self.b = self.a.get_browser()
@AndrewRayCode
AndrewRayCode / gist:2153138
Created March 21, 2012 21:36
chosen nowidth fix
commit e9501568acae1988ba51b5a29269023d3400db42
Author: Andrew Ray <[email protected]>
Date: Thu Aug 4 18:37:11 2011 -0700
making chosen work with whatever width the input box is set to with css for jquery, addressing issue #92
diff --git a/chosen/chosen.jquery.js b/chosen/chosen.jquery.js
index 2b95f10..43ee5b4 100644
--- a/chosen/chosen.jquery.js
+++ b/chosen/chosen.jquery.js
@AndrewRayCode
AndrewRayCode / gist:3784055
Created September 25, 2012 19:53
jQuery plugin for shift + click to select multiple checkboxes
// Usage: $form.find('input[type="checkbox"]').shiftSelectable();
// replace input[type="checkbox"] with the selector to match your list of checkboxes
$.fn.shiftSelectable = function() {
var lastChecked,
$boxes = this;
$boxes.click(function(evt) {
if(!lastChecked) {
lastChecked = this;
@AndrewRayCode
AndrewRayCode / okcmbf.js
Created November 19, 2012 07:20
Print relevant data from OKC's My Best Face
/**
* Go to the "see all votes" section of the report, then
* paste this script into your console. It will show you actual
* vote counts for your images. "Normalized" OKC data is BS and
* misleading. Don't be fooled!
*/
var imgs = document.querySelectorAll('img[title="An image of you"]'),i=0,img,badge,
badges = document.querySelectorAll('div.badge'),
prev = imgs[0].getAttribute('src'),
var size = 100,
uvMat = mesh.geometry.faceVertexUvs[0],
faceVerts, fi, vi;
for( fi = 0; faceVerts = uvMat[fi++]; ) {
for( vi = 0; vi < faceVerts.length; vi++ ) {
var pos = mesh.localToWorld( mesh.geometry.vertices[ vi ].clone() );
faceVerts[ vi ] = new THREE.Vector2(
var texelMap = {
0: 3,
1: 1,
2: 0,
3: 2
};
for( fi = 0; faceVerts = uvMat[fi++]; ) {
for( vi = 0; vi < faceVerts.length; vi++ ) {
#!/bin/sh
compression=80
hasExif=`which exiftool`
pngs=`git status -s | grep .png | awk '{print $2}'`
arr=($pngs)
if [ -n "$arr" ]; then
echo "Compressing png images by $compression%..."
for png in "${arr[@]}"