Skip to content

Instantly share code, notes, and snippets.

View aaronmccall's full-sized avatar

Aaron McCall aaronmccall

  • METER Group, Inc. USA
  • Kennewick, WA
View GitHub Profile
@aaronmccall
aaronmccall / placeholder.js
Created January 4, 2011 22:45
shim for browsers that don't support the html5 placeholder attribute
setup_placeholders = (function() {
$.support.placeholder = false;
test = document.createElement('input');
if('placeholder' in test) {
$.support.placeholder = true;
return function() {}
} else {
return function(){
// How to create a setTimeout-based incrementer that is self-calling
(function() {
var i = 0;
function incrementer(undefined) {
if (i !== undefined && i < 10) {
i++;
console.log('i is %s', i);
setTimeout(incrementer, 500);
}
}
@aaronmccall
aaronmccall / zippy.html
Created November 12, 2011 02:39
One approach to reducing data over the wire...
<!DOCTYPE html>
<html>
<head>
<title>Zippy Test</title>
<script type="text/javascript" src="zippy.js"></script>
<script type="text/javascript">
console.profile();
var kv_str = 'foo,bar,baz|1,2,3,4,5,6,7,8,9',
zippy_list = string_to_zippy(kv_str, true),
zippy_json = JSON.stringify(zippy_list);
@aaronmccall
aaronmccall / most_used_commands.txt
Created December 31, 2011 19:43
My most popular shell commands
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
95 node
82 git
37 ./manage.py
35 ls
35 cd
25 pip
22 jshint
18 brew
@aaronmccall
aaronmccall / README.md
Created January 4, 2012 00:54
Convention-based nginx+django dev environment bootstrapping for Mac OS

Conventions

dev_env.sh

  • Groks nginx installed via MacPorts or Homebrew (/opt/local or /usr/local)
  • Follows the Ubuntu sites-available/sites-enabled convention

runserver.sh

  • Expects top-level project folders to exist in ~/Sites
@aaronmccall
aaronmccall / inst_wout_new.js
Created March 28, 2012 17:55
Javascript instance without new
// Constructor function makes a Person model
var Person = function (lastName, firstName) {
// What's that? I'm not feeling like myself today!
if (!(this instanceof Person)) {
// Just call myself with new then!
return new Person(lastName, firstName);
}
this.lastName = lastName;
this.firstName = firstName;
@aaronmccall
aaronmccall / interval_ajax.js
Created July 2, 2012 17:57
a periodic ajax update with jQuery
$(function () {
setInterval(function () {
$.post('/has-changed', function (data) {
if (data == '1') {
$(document.body).css('backgroundColor', 'red');
}
});
}, 15);
});
@aaronmccall
aaronmccall / prune_empties.py
Created July 10, 2012 22:51
fastest way to prune empty strings from a python list
pruned_list = filter(None, list_of_strings)
@aaronmccall
aaronmccall / unix_line_endings.sh
Created September 18, 2012 17:25
command to convert \r\n to \n line endings
tr '\015' '\n' < file_with_carriage_returns.txt > out && mv out file_with_carriage_returns.txt
@aaronmccall
aaronmccall / pubsub.js
Created October 17, 2012 19:38
tiny standalone pubsub in javascript
//PubSub
(function(attachTo, defaultContext) {
var topics = {},
attachTo = attachTo||this,
defaultContext = defaultContext||this,
__slice = function (obj) { return [].prototype.slice.call(obj) };
attachTo.publish = function() {
var args = __slice(arguments),
topic = args.shift();