Skip to content

Instantly share code, notes, and snippets.

var artNums = [
"DV138501174HK",
"02002788399970580927",
"02002788399970580926",
"EG945761960US",
"92410944973202000000246909",
"9566700003681143083527",
"CA005338152RU",
"CA677001201US",
"EA272521142US",
@danlynn
danlynn / filename.js
Created September 30, 2011 15:47
Description
/*
* Rewraps the elements in a table to the specified 'width'. If 'elements'
* is provided then populates the innerHTML of the cells of the specified
* 'table' using the data in the 'elements' array instead of re-using the
* elements already in the table.
*
* rewrapTableToWidth($('#myTable'), $(window).width())
*/
function rewrapTableToWidth(table, width, elements) {
table = typeof(table[0]) != "undefined" ? table[0] : table;
@danlynn
danlynn / gist:1182447
Created August 30, 2011 23:59
Sublime fails to obtain system input
#!/usr/bin/env ruby
@my_number = (rand(10) + 1).to_s
@tries = 10
def try
print "Tries left = #{@tries -= 1}: Guess my number (1..10): "
gets.chomp == @my_number rescue puts "<nil input>"
end
@danlynn
danlynn / gist:1171719
Created August 25, 2011 20:03
Commented out method auto-formatted to be utterly useless
/*
* public void setLookupDao(LookupDao lookupDao) { this.lookupDao =
* lookupDao; String timeoutStr =
* getLookupDao().lookupSingleValueByKey("DEFAULT_WEBTOOLS_CLIENT_TIMEOUT");
* try { setTimeout(Integer.valueOf(timeoutStr)); } catch
* (NumberFormatException e) {logDebug(
* "Failed to assign timeout for EnhancedHttpClient because LookupDao value for DEFAULT_WEBTOOLS_CLIENT_TIMEOUT is '"
* +timeoutStr+"'"); } }
*/
@danlynn
danlynn / gist:899186
Created April 2, 2011 02:32
This is the DAO code gen'd by hibernate
package com.itcadre.adapt.hibernate;
// Generated Apr 1, 2011 10:29:11 PM by Hibernate Tools 3.4.0.CR1
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@danlynn
danlynn / gist:899185
Created April 2, 2011 02:31
Domain class generated by hibernate
package com.itcadre.adapt.hibernate;
// Generated Apr 1, 2011 10:29:11 PM by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@danlynn
danlynn / gist:809103
Created February 3, 2011 05:54
Grouping a list of strings by similarity using Levenshtein string distance
# The Levenshtein distance between two strings is defined as the minimum number
# of edits needed to transform one string into the other, with the allowable
# edit operations being insertion, deletion, or substitution of a single character.
#
# see:
# http://en.wikipedia.org/wiki/Levenshtein_distance
# http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Levenshtein_distance#Ruby
# https://github.com/threedaymonk/text/blob/master/lib/text/levenshtein.rb
on_data_proc = lambda do |ch, data|
log.puts "out: #{data}"
channel.send_data("yes\n") if data =~ /continue connecting \(yes\/no\)/i
channel.send_data("#{cmds["password"]}\n") if data =~ /Password/i
if data =~ /Last login:/i
log.puts "logged in"
process_cmds(cmds, nest+1, params)
log.puts "processing nested commands finished"
channel.on_data do |ch, data|
on_data_proc.call(ch, data)
class Owner < ActiveRecord::Base
belongs_to :owner
# fields: name, fullname, email, phone, owner_id
def self.find_incomplete_owners
Owner.find(:all, :conditions => "fullname is null or email is null")
end
def get_owner_or_init_from_svn
unless self.owner
owner_name = Source.get_owner_from_svn_log(self.path)
if owner_name
self.owner = Owner.find_or_create_by_name(owner_name)
self.save!
end
end
return self.owner
end