Skip to content

Instantly share code, notes, and snippets.

View jszmajda's full-sized avatar

Jess Szmajda jszmajda

View GitHub Profile
# based on http://code.activestate.com/recipes/528911-barcodes-convert-upc-e-to-upc-a/
class Upc
def self.convert_upc_e_to_upc_a(upce=nil)
return upce if upce.nil? or upce.length < 6 or upce.length > 8 # not a UPC-E
upce = case upce.length
when 6
upce
when 7
upce[0,6]
# manifest-entry-field => [ search-method, product-data-source, link-weight ]
# search-method: is the name of a function [fuzzy_search | manufacturer_search | exact]
# OR a lambda which receives ( the value of manifest-entry-field, the value of product-data-source )
# and returns the matching product or nil
LINKING_COLUMNS = {
:title => [:fuzzy_search,
:title,
5],
#:description => [:fuzzy_search, :description, 10],
$('#bidding .editable').editable('/loads/<%=@load.id%>/manifest_entries/edit_in_place.ajax', {
'id': 'elementid',
'name': 'elementname',
'callback': function(result,settings){
var field = $(this).attr('class').split(/ /).pop();
if(field.match(/_cents$/)){
$(this).html(result.manifest_entry.manifest_entry[field]/100).formatCurrency();
} else {
$(this).html(result.manifest_entry.manifest_entry[field]);
}
@jszmajda
jszmajda / bar_spec.rb
Created November 15, 2010 14:17
how to handle conflicting stubbing requirements
require 'spec_helper'
describe "Bar" do
it "should not bar" do
lambda {
"foo".bar
}.should raise_exception
end
end
@jszmajda
jszmajda / gol_backbone.md
Created September 18, 2011 15:03
Game of Life in Backbone Design

Model: Cell {x, y, alive} View: CellView {model: Cell} Collection: Cells


CellView renders a div CellView listens to Cell.change to change b.g. color

On app init:

@jszmajda
jszmajda / README.md
Created October 17, 2011 22:16
A potential spec for a ruby X.commerce gem

Overview

This is a rough spec for a gem I would like to use to connect to X.commerce. As X.commerce is new and my experience with it is limited, I'd like to discuss with the community first how best to structure the interaction before actual code is written.

Structure

I've spec'd out the following basic object structure:

@jszmajda
jszmajda / ticket_to_ride_score.rb
Created December 19, 2011 03:21
Ticket To Ride Scoring
def points(x)
{
1 => 1,
2 => 2,
3 => 5,
4 => 7,
6 => 15,
8 => 21
}[x.to_i]
end
@jszmajda
jszmajda / stories.rb
Created March 12, 2012 16:39
Something to quickly create and deliver pivotal stories
require 'pivotal-tracker'
module PivotalTracker
class Project
def create_stories(options={})
req = options[:requester]
own = options[:owner]
stories = options[:stories]
stories.split(/\n/).each do |story|
md = story.strip.match(/^([fcb])(\d) (.*?) \[(.*)\]$/)
@jszmajda
jszmajda / gist:3076527
Created July 9, 2012 13:20
Utility script to create Pivotal Tracker stories
require 'pivotal-tracker'
module PivotalTracker
class Project
def create_stories(options={})
req = options[:requester]
own = options[:owner]
stories = options[:stories]
stories.split(/\n/).each do |story|
md = story.strip.match(/^([fcb])(\d) (.*?) \[(.*)\]$/)
@jszmajda
jszmajda / gist:3800974
Created September 28, 2012 17:00
Evil ping-pong pairing is fun
describe World do
it "should return no cell on a new board" do
w = World.new
w.cell_at(2,2).should be_nil
end
it "should allow cell creation" do
w = World.new
w.make_cell(2,2)
w.cell_at(2,2).should be_kind_of(Cell)
end