This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Strings aren't objects.*/ | |
typeof '' // 'string' | |
'' instanceof Object // false | |
/*But they have methods.*/ | |
'a'.concat(' string'); // 'a string' | |
/*A string's methods are equal across receivers.*/ | |
'a'.concat === 'b'.concat // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function C(a){ | |
this.a = a | |
this.f = function(){ print(this.a); }; | |
} | |
o = new C('racecar'); | |
o.f() // prints 'racecar' | |
a = o.f | |
a() /* prints: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Uses my xkpa password generator: https://github.com/beala/xkcd-password | |
# The password generation method can be modified below. | |
# Depends on openssl and ssss (http://point-at-infinity.org/ssss/) | |
# Copyright (c) 2012 Alex Beal | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of | |
# this software and associated documentation files (the "Software"), to deal in | |
# the Software without restriction, including without limitation the rights to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create constructors for Parent, Sub1, and Sub2. | |
function Parent(){} | |
function Sub1(){} | |
function Sub2(){} | |
// Sub1 and Sub2 inherit from Parent. | |
Sub1.prototype = Sub2.prototype = new Parent(); | |
(new Sub1()) instanceof Sub2 // true. Wat? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch(NaN){ | |
case Infinity: print(Infinity); break; | |
case NaN: print(NaN); break; | |
default: print('default'); break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* For the SpiderMonkey command line interp. */ | |
(function () { | |
print("(" + arguments.callee + ")();"); | |
})(); | |
/* For the browser. */ | |
(function () { | |
console.log("(" + arguments.callee + ")();"); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Semaphore | |
attr_reader :value, :max | |
def initialize(count) | |
@m = Mutex.new | |
@value = count | |
@waiting = [] | |
end | |
def synchronize(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Small changes to DrSkippy's code. Turns graph horizontal. Makes margins smaller. | |
// Original (https://gist.github.com/4057438) Blog (http://blog.drskippy.com/2012/11/11/age-visualization/) | |
import java.util.*; | |
import java.text.*; | |
int boxSize = 5; // pixel size of month representation | |
int boxSpacing = 4; // vertical and horizontal spacing | |
int decadeSpacing = 2*boxSpacing; // extra space between decades | |
int markerOverhang = 18; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
def getSuccessors(color): | |
def perm(l, n, str_a, perm_a): | |
"""Generate every permutation of length `n`, selecting from the | |
possible values in `l`. | |
""" | |
if len(str_a) == n: | |
return (str_a,) + perm_a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_order(cur_order, menu, valid_orders): | |
# Try every item in the menu. | |
for selection in menu: | |
new_order = cur_order + [selection] | |
# Try again if the current item blows the budget. | |
if sum(new_order) > 15.05: | |
continue | |
# If the order costs 15.05, then it meets our contraints. | |
elif sum(new_order) == 15.05: | |
valid_orders.append(new_order) |