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 java.util.Random; | |
public class Mystery { | |
public static void main(String[] args) { | |
System.out.println(randomString(-229985452) + " " + randomString(-147909649)); | |
} | |
private static String randomString(int code) { | |
Random random = new Random(code); |
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 byteString(n) { | |
if (n < 0 || n > 255 || n % 1 !== 0) { | |
throw new Error(n + " does not fit in a byte"); | |
} | |
return ("000000000" + n.toString(2)).substr(-8) | |
} |
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
# A typical example of inheritance | |
class Animal | |
constructor: (@name) -> | |
speak: -> | |
"#{@name} says #{this.sound()}" | |
class Cow extends Animal | |
sound: -> "moo" |
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
"""A module with talking animals.""" | |
class Animal(object): | |
def __init__(self, name): | |
self.name = name | |
def speak(self): | |
print self.name, 'says', self.sound() | |
class Cow(Animal): |
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
// These are answers to practice problems for the freshmen. | |
// | |
// Note they mignt not be the fanciest possible solutions because they are | |
// problems for a beginner class. | |
var sameLength = function (a, b) { | |
return a.length === b.length; | |
} | |
var evenlyDivides = function (x, y) { |
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
C.evalAST = function (ast) { | |
var environment = {} | |
function ev(ast) { | |
return !Array.isArray(ast) ? ast : ops[ast[0]].apply(undefined, ast.slice(1)) | |
} | |
var ops = { | |
id : function(x) {return environment.hasOwnProperty(x) ? environment[x] : 0}, | |
set : function(id, exp) {return environment[id] = ev(exp)}, |
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
if #arg ~= 1 then | |
io.stderr:write('Exactly one argument required\n') | |
os.exit(1) | |
end | |
function generatePermutations(n, a) | |
if n == 0 then | |
print(utf8.char(table.unpack(a))) | |
else | |
for i = 1, n do |
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 powerpowermod(a, b, c, p) | |
if !isprime(p) | |
error("Go away. I not gonna even try this.") | |
end | |
return powermod(a, powermod(b, c, p-1), p) | |
end |
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
Vector = (function (class, meta, prototype) | |
class.new = function (i, j) | |
return setmetatable({i = i, j = j}, meta) | |
end | |
prototype.magnitude = function (self) | |
return math.sqrt(self.i * self.i + self.j * self.j) | |
end | |
meta.__index = prototype | |
meta.__add = function (self, v) | |
return class.new(self.i + v.i, self.j + v.j) |
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
# Mongo not happy unless lots of open files | |
ulimit -n 2000 | |
# Start server | |
sudo mongod --fork --syslog | |
# Already done | |
unzip all-films.zip | |
mongoimport -d mgo -c films all-films.json |
OlderNewer