Skip to content

Instantly share code, notes, and snippets.

View davidsheldon's full-sized avatar

David Sheldon davidsheldon

View GitHub Profile
@davidsheldon
davidsheldon / CrossProductIterator.java
Created July 27, 2011 14:47
A class to interate through the cross product of all of the pairs of values from iterators.
import java.util.Iterator;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;
/**
*/
public abstract class CrossProductIterator<A, B, C> extends AbstractIterator<A> {
private Iterator<B> outer_;
@davidsheldon
davidsheldon / gist:602571
Created September 29, 2010 11:16
Example of generics needing an extra, hacky, method in order to bind a type for a block.
import java.util.ArrayList;
import java.util.List;
public class GenericsExample {
public static class CollectionWrapper<T> {
private List<T> stuff;
public List<T> getStuff() {
return stuff;
#!/bin/bash
mkdir thumbs
cp *.jpg thumbs
perl -e 'while(<*.jpg>) { print "<a href=\"$_\"><img src=\"thumbs/$_\"></a>\n";};' > index.html
mogrify -geometry 100 thumbs/*.jpg
@davidsheldon
davidsheldon / findMissingFKIndexes.pl
Created July 17, 2009 15:09
If you have a column with a foreign key constraint, and no index, then whenever anything is deleted from the target table it has to do a table scan. This will show you columns that might cause this error. pg_dump -s databaseName | findMissingFKIndexes.pl
#!/usr/bin/perl
my $DEBUG=0;
my %indexes = ();
my %keys = ();
my $last = "";
while(<>) {
if (/^CREATE INDEX.*ON (\S+) USING btree \((\S+)(,.*)?\)/) {
class gen {
Object obj;
public gen(Object s) {
obj = s;
}
T test() {
return (T) obj;
}
}