Skip to content

Instantly share code, notes, and snippets.

View scizzorz's full-sized avatar
🐻

John Weachock scizzorz

🐻
View GitHub Profile
@scizzorz
scizzorz / pairs.py
Last active December 22, 2015 03:09
Generate a list of all unique pairs from a list of items
#!/usr/bin/env python
source = ("A", "B", "C", "D", "E", "F")
pairs = []
for i in source:
for j in source:
if i == j:
continue
package bakery;
public class Baker {
public static void main(String[] args) {
// Cut out three cookies:
// one with no toppings,
// one with lots of chocolate chips,
// and one with lots of sprinkles
Cookie plain = new Cookie(0, 0);
Cookie chips = new Cookie(10, 0);
@scizzorz
scizzorz / withself.py
Created September 22, 2013 19:36
Function decorator to add `self` to any Python function
# http://stackoverflow.com/a/5063783
def withself(f):
@wraps(f)
def wrapper(*args, **kwds):
return f(f, *args, **kw)
return wrapper
@withself
def aa(self):
print(self.__name__)
@scizzorz
scizzorz / TestInvalid.java
Created September 28, 2013 22:56
An idea for trapping runtime exceptions in arbitrary Java code for use the in Compytition grader.
public class TestInvalid {
public static void main(String[] args) {
System.out.println("I am *totally* going to touch that null pointer right now...");
String x = null;
System.out.println(x.length());
}
}
@scizzorz
scizzorz / StudentList.java
Created September 29, 2013 21:30
Example to help understand expression evaluation in Java.
// StudentList classroom;
// Student[] StudentList.getStudents()
// Student StudentList.getStudent(int index)
// String Student.getName()
// String[] Student.getClasses()
// String Student.getClass(int index)
// 1
classroom.getStudents()[2].getName()
@scizzorz
scizzorz / test-invalid.py
Created September 30, 2013 19:52
An idea for trapping runtime exceptions in arbitrary Python 2 code for use the in Compytition grader.
print "I am *totally* going to divide by zero..."
print 5/0
@scizzorz
scizzorz / test-invalid.py
Created September 30, 2013 19:53
An idea for trapping runtime exceptions in arbitrary Python 3 code for use the in Compytition grader.
print("I am *totally* going to divide by zero...")
print(5/0)
'copy'
'Copy a file from {source} to {destination}'
{'dest': 'Destination', 'source': 'Source', 'return': None}
'copy'
'Copy a file from {source} to {destination}'
{'dest': 'Destination', 'source': 'Source', 'return': None}
def partial(func, *args):
def curry(*cargs):
return func(*(args + cargs))
return curry
def f(*args):
print args
g = partial(f, 3, 4, 5, 6, 7)
h = partial(f, 5, 6, 7)