Skip to content

Instantly share code, notes, and snippets.

View BrianHicks's full-sized avatar

Brian Hicks BrianHicks

View GitHub Profile
// mostly stolen from http://phrogz.net/JS/classes/OOPinJS2.html
// first we define a mammal...
function Mammal(name) {
this.name = name;
this.offspring = [];
}
Mammal.prototype.haveABaby = function() {
var newBaby = new Mammal("Baby " + this.name);
this.offspring.push(newBaby);
// say you have the following object:
var friends = {
bob: {name: "Bob Robertson", nickname: "Bob the Terrible"},
jim: {name: "Jim Jameson", nickname: "Jim the Magnificent"},
bill: {name: "Bill Williamson", nickname: "Doodles"},
}
// So if you want to get Bob's nickname, you could access it like so:
console.log(friends.bob.nickname); // prints "Bob the Terrible"
// but say you just have Bill's name in a variable, and you need to look it up.
function compare(choice1, choice2) {
if (choice1 == choice2) return "The result is a tie!";
if (choice1 == "rock") {
if (choice2 == "paper") {
return "paper wins";
} else { // scissors
return "rock wins";
}
// or with a ternary statement...
//return (choice2 == "paper" ? "paper" : "rock") + " wins"
sets!
one(1): True
two(2): True
Join/Or!
one_or_two(1): True
one_or_two(2): True
Intersect/And!
one_but_not_two(1): True
@BrianHicks
BrianHicks / profile.yaml
Last active December 14, 2015 00:29
Starting a server on salt-cloud (command was `salt-cloud -l all -p manage-staging manage-staging 2> salt-cloud.log`)
manage-staging:
provider: aws
image: ami-43e2772a
size: m1.small
script: bootstrap-salt-minion
minion:
grains:
staging: True
database: True
media: True
@BrianHicks
BrianHicks / multiple-deps.yaml
Created February 15, 2013 13:50
Extra for my comment on saltstack/salt #3736
State: - pkg [425/1906]
Name: python-dev
Function: installed
Result: False Comment: The following package(s) failed to install/update: python-dev.
Changes: libgomp1: {'new': '4.6.3-1ubuntu5', 'old': ''} libmpfr4: {'new': '3.1.0-3ubuntu2', 'old': ''} libz-dev: {'new': '1', 'old': ''}
gcc-4.6: {'new': '4.6.3-1ubuntu5', 'old': ''} python2.7-dev: {'new': '2.7.3-0ubuntu3.1', 'old': ''} linux-libc-dev: {'new': '3.2.0-37.58', 'old': ''}
cpp-4.6: {'new': '4.6.3-1ubuntu5', 'old': ''} python-dev: {'new': '2.7.3-0ubuntu2', 'old': ''}
gcc: {'new': '4:4.6.3-1ubuntu5', 'old': ''}
@router.node(('bigram',))
def bigrams(msg):
'get bigrams from a document'
prev = None
for word in msg.document.strip().split(' '):
yield (prev, word)
prev = word
@router.node(('bigram', 'frequency'), 'bigrams')
def count_bigrams(msg):
@BrianHicks
BrianHicks / .poltergist.yaml
Last active December 12, 2015 03:59
Presentation on Emit
style: swiss.css
@BrianHicks
BrianHicks / _compass.rb
Created December 8, 2012 07:59
Improved Compass Rendering for Jekyll
require 'zurb-foundation'
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "_site/static/css"
sass_dir = "_sass"
images_dir = "static/images"
javascripts_dir = "static/js"
@BrianHicks
BrianHicks / uri_resource.py
Created September 21, 2012 14:29
Override URI field in TastyPie
'''
Usage:
class MyResource(CustomURIResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
url_field = 'username'
Will make accessible URIs like so: