Skip to content

Instantly share code, notes, and snippets.

@DavidMah
DavidMah / gist:1133140
Created August 9, 2011 00:30
Print what is inside of a 2d array
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
@DavidMah
DavidMah / populate.rb
Created August 26, 2011 22:57
Fill up your Postercloud Rails Backend with stuff.
def make_sites(options = {})
times = options[:times] ? options[:times] : 50
users = options[:users] ? options[:users] : User.all
times.times do |t|
n = Site.new
begin
n.user = users.sample
n.hostname = "siteno#{t}"
n.save
puts t
@DavidMah
DavidMah / populate.rb
Created August 29, 2011 20:35
Populate Posterous devcloud
def make_sites(options = {})
times = options[:times] ? options[:times] : 50
users = options[:users] ? options[:users] : User.all
times.times do |t|
n = Site.new
begin
n.user = users.sample
n.hostname = "siteno#{t}"
n.save
puts "site #{t}"
@DavidMah
DavidMah / experiment.java
Created October 5, 2011 00:57
throwing an exception
public class experiment {
public static void main(String[] args) {
throw new ArrayIndexOutOfBoundsException();
}
}
@DavidMah
DavidMah / TestExample.java
Created December 13, 2011 06:22
TestExample
public class TestExample {
public static void main(String[] args) {
int[] a = {};
expect("it should leave the empty list alone", a, "[]");
int[] b = {39};
expect("it should leave the single element list alone", b, "[39]");
int[] c = {39, 42};
expect("it should leave the two element list alone", c, "[39, 42]");
int[] d = {39, 42, 9001};
expect("it should reverse this one chunk of three", d, "[9001, 42, 39]");
@DavidMah
DavidMah / LinkedIntList.java
Created December 13, 2011 06:34
testFunction()
public void testFunction() {
reverse3();
}
@DavidMah
DavidMah / Human.java
Created December 13, 2011 06:54
compareTo
public int compareTo(Human other) {
if(age < other.age) {
return -1;
} else if (age > other.age) {
return 1;
} else {
return 0;
}
}
@DavidMah
DavidMah / Human.java
Created December 13, 2011 06:56
compareTo with two fields
public int compareTo(Human other) {
if(age < other.age) {
return -1;
} else if (age > other.age) {
return 1;
} else {
// Fall back to the logic for the second field only if the first two are equal.
if(guiltyPleasure < other.guiltyPleasure) {
return -1;
} else if(guiltyPleasure > other.guiltyPleasure) {
@DavidMah
DavidMah / string_transform.rb
Created April 3, 2012 04:41
String Transformations
# string_transform
# Usage:
# ruby string_transform.rb <target string>
#
# The hello world of genetic algorithms creates
# a random string and mutates it until it becomes
# the target string
def get_worth(item, target)
sum = 0
@DavidMah
DavidMah / dafuq.sh
Created May 4, 2012 07:23
Bullshit bash
#!/usr/bin/sh
dafuq="echo \" betsuni baka baka\""
$dafug