Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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 / 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;
var artNums = [
"DV138501174HK",
"02002788399970580927",
"02002788399970580926",
"EG945761960US",
"92410944973202000000246909",
"9566700003681143083527",
"CA005338152RU",
"CA677001201US",
"EA272521142US",
erb_eval_mode = line =~ /^%ERB_START_EVAL/ if line =~ /^%ERB_START_EVAL|%ERB_STOP_EVAL/
if line =~ /^%ERB_START_EVAL/
erb_eval_mode = true
if line =~ /^%ERB_STOP_EVAL/
erb_eval_mode = false
1.9.2p320 :001 > s = "test: string with @ref and @ref2 in it"
=> "test: string with @ref and @ref2 in it"
1.9.2p320 :002 > s.scan(/(?<=@)\w+/)
=> ["ref", "ref2"]
1.9.2p320 :003 > s.scan(/@(\w+)/)
=> [["ref"], ["ref2"]]
require'socket'
server = TCPServer.new(8088);
loop do
connection = server.accept
puts 'Trapped a new connection'
end
@danlynn
danlynn / api_v1_scratch.rb
Created November 28, 2012 16:20
Registration steps
# Register - Step 1 (login): Authenticate using fuzzy card number as 'login' and last name as 'password' (note auth will fail if Card.Reg == 1 already)
curl -i -H "Accept: application/json" -X POST -d "api_user_session[retailer_id]=767&api_user_session[type]=Card&api_user_session[login]=40000000197&api_user_session[password]=Vandalay" http://local.webstophq.com:3000/api/v1/login
# Register - Step 2 (get preferred store list): Gets list of {:id, :store_number, :address_1, :city, :store_name}
GET /api/v1/retailers/:retailer_id/stores(.:format)
curl -i -H "Accept: application/json" http://local.webstophq.com:3000/api/v1/retailers/767/stores?api_user_credentials=tozaqJaMRDKPjXPWhDh
# Register - Step 3 (update consumer): Mark Consumer (Card) as registered and set preferred store and password - then return the Consumer (Card) including new single_access_token and legacy_token
PUT /api/v1/retailers/:retailer_id/consumers/:id(.:format)
curl -i -H "Accept: application/json" -X PUT -d "consumer[registered]=1&co