Skip to content

Instantly share code, notes, and snippets.

View jhuttner's full-sized avatar

Joseph Huttner jhuttner

View GitHub Profile
@jhuttner
jhuttner / drain.py
Created May 31, 2011 19:46
Drain the battery on your computer, via the Command Line.
#!/usr/local/bin/python
# If you have an n-core machine, open n terminals and run this script in each one.
def fib(n):
if n == 1 or n == 0:
return 1
else:
return fib(n-1) + fib(n-2)
#!/bin/bash
ssh local pbcopy -
@jhuttner
jhuttner / store
Created June 7, 2011 19:06
Store last command to mac buffer
PUT AS TWO SEPARATE SCRIPTS: store.sh, and store.py.
USAGE: ./store.sh
#/!bin/bash
echo "Wait...."
history > /tmp/store
/home/jhuttner/store.py
cat /tmp/store2 | pbcopy
public static function indentJSON($json) {
$result = '';
$pos = 0;
$strLen = strlen($json);
//$indentStr = ' ';
//$newLine = "\n";
$indentStr = '    ';
$newLine = "<br/>";
for($i = 0; $i <= $strLen; $i++) { $char = substr($json, $i, 1); if($char == '}' || $char == ']') { $result .= $newLine; $pos --; for ($j=0; $j<$pos; $j++) { $result .= $indentStr; } } $result .= $char; if ($char == ',' || $char == '{' || $char == '[') { $result .= $newLine; if ($char == '{' || $char == '[') { $pos ++; } for ($j = 0; $j < $pos; $j++) { $result .= $indentStr; } } } return $result;
@jhuttner
jhuttner / demo.js
Created August 16, 2011 16:07
jquery demo
<select id="sel1">
<option>Eric</option>
<option>Joe</option>
</select>
<p id="eric" class="hidden">Hi, I'm eric</p>
<p id="joe" class="hidden">Hi, I'm joe</p>
$(document).ready(function(){
@jhuttner
jhuttner / gist:1251710
Created September 29, 2011 19:37
My Code Review Submission
_oMyController.setListener('firstEvent secondEvent', function(data) {
if (data.is_second_event) {
// do something specific just to the second event
}
// do something common to both events
});
@jhuttner
jhuttner / toggler.js
Created October 5, 2011 18:48
Easily change show/hide text on links that toggle DOM elements - by Joseph Huttner
function toggler(dom_element) {
var inner = dom_element.innerHTML;
var new_inner;
if (inner.indexOf('Show') !== -1) {
new_inner = inner.split('Show').join('Hide');
} else if (inner.indexOf('show') !== -1) {
new_inner = inner.split('show').join('hide');
} else if (inner.indexOf('hide') !== -1) {
new_inner = inner.split('hide').join('show');
<?php
function splitArray($array) {
$array = $this->quoteArray($array);
$fields = array_keys($array);
$fields_with_ticks = array();
foreach($fields as $f) {
$fields_with_ticks[] = '`'.$f.'`';
}
$values = array_values($array);
@jhuttner
jhuttner / eachWhile.js
Created October 21, 2011 21:12
eachWhile
var add_to_list = false;
var result = [];
$.each(checks, function(check) {
// don't go through all the logic if we know we are going to append it
if (add_to_list) {
return true;
}
if (check()) {
addToList = true;
if (!items_by_name[name]) {
items_by_name[name] = [];
}
items_by_name[name].push(item);
// could we do something like this?
items_by_name[name].smart_push(item, [])