Skip to content

Instantly share code, notes, and snippets.

Stephen Murray spmurrayzzz

View GitHub Profile
@spmurrayzzz
spmurrayzzz / immutable-proxy-example.js
Last active Oct 22, 2016
Immutable object factory, using proxies
View immutable-proxy-example.js
const immutable = require('./immutable');
let obj;
obj = immutable({ foo: 'bar' });
obj.foo = 'baz'; // assignment fails silently
delete obj.foo; // delete fails silently
obj = immutable({ foo: [ 1, 2, 3 ] });
obj.foo.push( 4 ); // mutation fails silently
@spmurrayzzz
spmurrayzzz / score.js
Created Aug 16, 2015
js13kgames closure fun
View score.js
(function() {
var score = 0;
Object.defineProperty( this, 'score', {
get: function(){
return score;
},
set: function( val ) {
score = val;
this.elem.innerHTML = _.template(
tmplStr, { score: score }
View localStorage-shim.js
// Sourced from https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage
//
// Note: The maximum size of data that can be saved is severely restricted by the use of cookies.
// With this algorithm, use the functions localStorage.setItem() and localStorage.removeItem() to add,
// change, or remove a key. The use of methods localStorage.yourKey = yourValue; and delete localStorage.yourKey;
// to set or delete a key is not a secure way with this code. You can also change its name and use it only to
// manage a document's cookies regardless of the localStorage object.
if (!window.localStorage) {
Object.defineProperty(window, "localStorage", new (function () {
@spmurrayzzz
spmurrayzzz / Vagrantfile
Last active Dec 31, 2015
High-performing Vagrant settings
View Vagrantfile
# Note: If you're serving files via shared folders, for christs sake use NFS
# but that does require private networking.
#
# The DNS settings were the ones that made the most difference, so if you're resource
# constrained, the last two settings were the ones that helped the most.
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "90"]
vb.customize ["modifyvm", :id, "--cpus", 2]
@spmurrayzzz
spmurrayzzz / d_day.js
Created Jul 10, 2013
fucking birthday
View d_day.js
var me = new Person();
var d_day = setInterval(function(){
if (me.age == 30) {
console.log('fuck my life');
shuffle_off(me.mortal_coil);
clearTimeout(d_day);
}
}, 86400e1);
@spmurrayzzz
spmurrayzzz / archive.py
Last active Dec 17, 2015
Semi-intelligently archive the contents of Mac OS X Desktop
View archive.py
#!/usr/bin/env python
'''
archive.py
Quick and dirty script that moves desktop clutter to a date-sorted archive
location. Nothing elegant here, just keeps desktop workspace much less
cluttered. Intended to be run as a cron job at a sane frequency.
Usage is ideal if your desktop is merely a swap space, not so ideal if your
@spmurrayzzz
spmurrayzzz / get-donors.py
Created Apr 18, 2013
Scrape donors from HTML
View get-donors.py
#!/usr/bin/env python
from subprocess import call
from bs4 import BeautifulSoup
import json
import os
def get_html():
if os.path.isfile('richard-family-fund'):
@spmurrayzzz
spmurrayzzz / euler-25.py
Created Mar 24, 2013
Project Euler #25
View euler-25.py
def fib():
first = 0
second = 1
while True:
cached = first
first = first + second
second = cached
yield first
@spmurrayzzz
spmurrayzzz / django-user-extend.py
Created Feb 20, 2013
Extending Django User model
View django-user-extend.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
# ------------- USERS -------------
class UserProfile(models.Model):
user = models.OneToOneField(User)
def __unicode__(self):
You can’t perform that action at this time.