Skip to content

Instantly share code, notes, and snippets.

View jcalvert's full-sized avatar

Jonathan Calvert jcalvert

View GitHub Profile
@jcalvert
jcalvert / gist:920637
Created April 14, 2011 21:46
Ugh. Doing so little with so much.
public final static String PERCENTAGE_TAGS = "%%";
public final static String OPEN_FLOWER_BRACKET = "{";
public final static String CLOSE_FLOWER_BRACKET = "}";
private static String replaceFlowerBrackets(String strQry) throws Exception {
strQry = strQry.replaceAll(Pattern.quote(OPEN_FLOWER_BRACKET), PERCENTAGE_TAGS);
strQry = strQry.replaceAll(Pattern.quote(CLOSE_FLOWER_BRACKET), PERCENTAGE_TAGS);
return strQry;
}
@jcalvert
jcalvert / gist:922038
Created April 15, 2011 17:01
Is there a better way?
class Array
def to_hash(&block)
Hash[*self.collect { |v|
block.call(v).flatten
}.flatten]
end
end
# so that ["foobar", "barfoo"].to_hash{|i| [i.upcase, i.downcase] }
# yields {"FOOBAR"=>"foobar", "BARFOO"=>"barfoo"}
@jcalvert
jcalvert / HqlLexer.patch
Created April 28, 2011 14:43
Hibernate HqlLexer patch.
--- hibernate-core/src/main/java/org/hibernate/hql/ast/HqlLexer.java 2011-04-28 10:39:48.000000000 -0400
+++ hibernate-core/src/main/java/org/hibernate/hql/ast/HqlLexer.java 2011-04-28 10:40:56.000000000 -0400
@@ -51,7 +51,7 @@
public void setTokenObjectClass(String cl) {
// Ignore the token class name parameter, and use a specific token class.
- super.setTokenObjectClass( HqlToken.class.getName() );
+ tokenObjectClass = HqlToken.class;
}
@jcalvert
jcalvert / gist:1000620
Created May 31, 2011 14:45
BAMFCSV vs FasterCSV
require 'benchmark'
require 'bamfcsv'
require 'csv'
glob,totalsize,rows,filetime,bamftime,fastertime=Dir.glob("*.csv"),0,[],Benchmark::Tms.new,Benchmark::Tms.new,Benchmark::Tms.new
content=nil
glob.each{|file|
filetime.add!{Benchmark.measure{ content = IO.read(file).rstrip.force_encoding("ISO-8859-1") }}
totalsize+=content.size
bamftime.add!{Benchmark.measure{BAMFCSV.parse(content){|row| rows << row}}}
@jcalvert
jcalvert / gist:1001100
Created May 31, 2011 19:19
BAMF Row object Monkeypatch
class BAMFCSV::Table::Row
def [](key)
field_key=@header_map[key]
if(!field_key.nil?)
@fields[field_key]
end
end
def []=(key,value)
if(self[key].nil?)
@jcalvert
jcalvert / gist:1146918
Created August 15, 2011 14:55
memcachestats
[jcalvert@aws-smm-01 sinatra-magic-mirror]$ memcached-tool localhost:11211 stats
#localhost:11211 Field Value
accepting_conns 1
auth_cmds 0
auth_errors 0
bytes 630343442
bytes_read 453062735
bytes_written 1109137
cas_badval 0
cas_hits 0
@jcalvert
jcalvert / gist:1147082
Created August 15, 2011 16:12
dalli vs memcached
ruby-1.9.2-p290 :001 > require 'dalli'
=> true
ruby-1.9.2-p290 :002 > require 'memcached'
=> true
ruby-1.9.2-p290 :003 > Dalli::Client.new('localhost:11211').get('[email protected]')
=> "\x04\bi\x02 \v"
ruby-1.9.2-p290 :004 > Memcached.new('localhost:11211').get('[email protected]')
=> 2848
ruby-1.9.2-p290 :005 >
@jcalvert
jcalvert / Npetest.java
Created August 31, 2011 21:57
Find the NullPointerException!
public abstract class AbstractLoader {
protected LoadJob loadJob;
public AbstractLoader(LoadJob loadJob)
{
this.loadJob = loadJob;
int foo = 0; //Doing stuff
String bar = "foobar";
this.load1();
@jcalvert
jcalvert / gist:1210479
Created September 12, 2011 02:36
to_hash
class Array
def to_hash
Hash[self.zip(map{|i| yield i})] if block_given?
end
end
@jcalvert
jcalvert / gist:1228041
Created September 20, 2011 00:56
Vetstreet is looking for developers

Vetstreet is looking for developers

Vetstreet is looking for solid software developers in the DC Metro area to work in our downtown Silver Spring office. We have a diverse, interesting, collaborative work environment, delivering software services to veterinarians and their clients.

The interesting bits:

  • We're a polyglot shop. Java and Ruby are our greatest needs right now. If you can do both, awesome. We have Perl and .NET hanging around too. SQL all around.
  • Experience is preferred, but junior candidates OK.
  • You should feel relatively comfortable jumping into different things; some back end, some front end.
  • Most important is that you're smart and enthusiastic.