Skip to content

Instantly share code, notes, and snippets.

# How to install ipython notebook without messing up your entire system.
# Inspect EVERY LINE of this document. Copy+paste in a terminal; don't
# just blindly run it.
public class Test {
public static void main(String[] args) {
float sum = 0;
long startTime = System.currentTimeMillis();
for (int i = 0; i<100000000; i++) {
sum = sum + 0.1f;
}
long endTime = System.currentTimeMillis();
System.out.println("Took "+(endTime-startTime)/1000.0+" sec");
public class Test {
public static void main(String[] args) {
float sum = 0;
long startTime = System.nanoTime();
for (int i = 0; i<100000000; i++) {
sum = sum + 0.1f;
}
long endTime = System.nanoTime();
System.out.println("Took "+(endTime-startTime)/10e9+" sec");
import smtplib
def send_message(from_addr, password, to_addr, subject, body):
"""
This function sends an email message through gmail.
from_addr is your gmail address, like foo@gmail.com
to_addr is the recipient's address
password should be your gmail password
subject is the message subject
body is the message body
@gcr
gcr / u.java
Created February 24, 2012 03:07
public class Circle{
public void doSomething(){
System.out.println("Testing");
}
}
public class Test {
public static void main(String[] args) {
final int x = 25;
@gcr
gcr / u.java
Created February 24, 2012 03:02
public class Circle{
public void doSomething(){
System.out.println("Testing");
}
}
public class Test {
public static void main(String[] args) {
Circle c = new Circle() {
public void doSomething(){
@gcr
gcr / class.py
Created February 22, 2012 02:37
class Klass(object):
def __init__(self):
self.a = 23
def do_something(self):
print self.a
class Subklass(Klass):
def __init__(self):
self.a = 95
@gcr
gcr / class.py
Created February 22, 2012 02:34
class Klass(object):
def do_something(self):
print "Hello"
class Subklass(Klass):
def do_something(self):
print "OVERRIDDEN"
a = Klass()
public boolean groupSum(int start, int[] nums, int target) {
// This just calls groupSumSane with no start parameter (boo), an arrayList, and etc.
ArrayList lst = new ArrayList();
for (int i = start; i < nums.length; i++) {
lst.add(nums[i]);
}
return groupSumSane(lst, target);
}
public boolean groupSumSane(ArrayList nums, int target) {
public int strDist(String str, String sub) {
String x = str;
if (x.indexOf(sub) == -1) {
return 0; // Nothing here
}
if (!x.startsWith(sub)) {
// Chop a character off x
x = x.substring(1);
}
if (!x.endsWith(sub)) {