This file contains hidden or 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.lang.reflect.Field; | |
public class MontyPython { | |
public static void main(String[] args) throws Exception { | |
Field v = Integer.class.getDeclaredField("value"); | |
v.setAccessible(true); | |
v.set(3,5); | |
System.out.printf("Ready the holy hand grenade!\n"); | |
Thread.sleep(1000); | |
System.out.printf("%d\n", 1); | |
Thread.sleep(1000); |
This file contains hidden or 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 hidden or 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 hidden or 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 json | |
import gzip | |
import cStringIO | |
from boto.s3.connection import S3Connection | |
from boto.s3.key import Key | |
AWSACCESSKEY='********************' | |
AWSSECRETKEY='****************************************' | |
def read_gzipped_json_file_from_s3(bucket_name, key_name): |
This file contains hidden or 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 hidden or 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 hidden or 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
abstract class Animal(name: String) { | |
def speak = name + " says " + sound | |
def sound: String | |
} | |
class Cow(name: String) extends Animal(name) { | |
override def sound() = "moooooo" | |
} | |
class Horse(name: String) extends Animal(name) { |
This file contains hidden or 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
abstract class Animal { | |
private String name; | |
public Animal(String name) { | |
this.name = name; | |
} | |
public String speak() { | |
return name + " says " + sound(); | |
} | |
public abstract String sound(); | |
} |
This file contains hidden or 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 hidden or 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)}, |