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
File f = new File("foo.txt"); | |
// You're not allowed to make a Path using raw strings, | |
// that would be dangerous! | |
Path p = FileSystems.getDefault().getPath("foo.txt"); | |
// Both of these type check :) | |
f.getName().endsWith(".txt"); // true | |
p.getFileName().endsWith(".txt"); // false |
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
package sandbox; | |
import java.util.Arrays; | |
import java.util.Random; | |
public class SoABenchmark { | |
public static Random rand = new Random(9001); | |
public static int NUM_LABELS = 10; | |
public static Struct[] aos; |
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
package sanbox; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
import java.io.Serializable; | |
public class SerializationBugMWE { |
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
object IDontCare { | |
def main(args: Array[String]) { | |
example | |
example2 | |
example3 | |
} | |
def conjoin[I,P,O](f1: I => P, f2: I => P, compose: (P, P) => O): I => O = { |
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
trait Func0[V, P] { | |
def value(p: P): V | |
def dimension: Int | |
} | |
trait Func1[V, G, P] extends Func0[V, P] { | |
def grad(p: P): G = compute(p)._2 | |
def compute(p: P): (V, G) | |
} |
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
// NOTE: I actually made a mistake in this implementation | |
// Logging needs to have a redirect with type Logging, not Logger | |
// this is so that if a->b and b gets redirected, things logged via a.log() | |
// actually get forwarded along (regardless of what came first: redirecting | |
// b somewhere else or the call to a.log()). | |
// the only thing to worry about is loops, but i'm willing to take that risk for now. | |
// i have an implementation of this in Parma called Logging2 | |
import util.Random |
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
// Foo.scala | |
class Foo { | |
private var i = 0 | |
private[this] var j = 0 | |
def getJ = j | |
def iThing = i * i | |
def jThing = j * j | |
} |
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
time gzip -c <orig >orig.gz | |
real 0m0.311s | |
user 0m0.289s | |
sys 0m0.005s | |
time bzip2 -c <orig >orig.bz2 | |
real 0m3.358s | |
user 0m2.981s | |
sys 0m0.367s |
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
#!/usr/bin/python | |
import sys, httplib, re | |
if len(sys.argv) < 2: | |
print 'provide a query' | |
exit(0) | |
c = httplib.HTTPConnection('www.google.com') | |
c.request('GET', '/search?q=%s' % ('_'.join(sys.argv[1:]))) | |
r = c.getresponse() |
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 sys, math | |
if len(sys.argv) != 2: | |
print 'provide a diagonal length' | |
exit(0) | |
diag = float(sys.argv[1]) | |
# x*x + y*y = diag^2 | |
# x*ar = y |
NewerOlder