Skip to content

Instantly share code, notes, and snippets.

@litch
litch / rpn_3_ways.rb
Last active December 20, 2015 01:29
RPN 3 ways. I had two - then tried to do the pattern-matching solution, wound up being intermediate performance...
require 'rspec/autorun'
require 'benchmark'
describe "polish notation" do
it "do a trivial case" do
polish_parser(:+, 1, 1).first.should == 2
reverse_stack_polish_parser(:+, 1, 1).first.should == 2
pm_polish_parser(:+, 1, 1).first.should == 2
end
@litch
litch / merchant_account_test.rb
Created May 28, 2013 19:44
crazy epic unit test
require 'test_helper'
class MerchantAccountTest < ActiveSupport::TestCase
setup do
@merchant_account = FactoryGirl.create(:merchant_account)
end
should "fetch authorized orders" do
@order = FactoryGirl.create(:order, venue: @merchant_account.venue)
credit_card_hash = {
class SpeakersController < ApplicationController
load_and_authorize_resource :event
load_and_authorize_resource :speaker, through: [:event], shallow: true #the array here could only be the single symbol but since i almost always wind up adding more, i just start with it
before_filter :new_speaker, :only => [:new, :create]
respond_to :html
def index
end
def show
@litch
litch / Gemfile
Created February 24, 2013 17:34
Ruby 2.0.0 installation with RVM and running on heroku. RVM instructions sourced from: https://coderwall.com/p/tptocq A quick comparison of Ruby 2.0.0 performance loading rails can be found at my blog: www.superpumpup.com
source 'https://rubygems.org'
ruby "2.0.0"
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
...
App.Router.map(function() {
this.resource('tables', function() {
this.resource('table', {path: ':table_id'});
});
});
@litch
litch / can_be_in_diff_places.js
Created January 28, 2013 22:07
javascript to have a button do something but still pass through
$("#my_button_id").click(function () {
call_my_other_js;
});)
$("#my_button_id").click(function () {
$("form#formID").submit();
});)
$("#my_button_id").click(function () {
do_thing_3_for_kicks;
});)
require "xpath" # XPath is a separate gem now
module Cucumber
module Rails
module CapybaraSelectDatesAndTimes
def select_date (date, options = {})
date = Date.parse(date)
# lookup id prefix by label
id_prefix = id_prefix_for(options[:label])
@litch
litch / equipment_item.rb
Created January 23, 2013 17:58
Refactor me challenge!
class EquipmentItem
attr_accessor :task_items, equipment_hauls
def current_location
last_task = task_items.sort_by{|a| a.end_time }.last
last_haul = equipment_hauls.last
if last_task && last_haul
if last_task.end_time > last_haul.performed_at
last_task.timesheet.job
else
@litch
litch / crawl_the_site.rb
Last active December 11, 2015 07:59
One of the most frustrating things I run into in development is that sometimes, when I have been doing my testing, (even FE testing) and making changes to FE code, and pushing to production and start getting 500's because some element in my production dataset is nil that is not nil in my factories.  So now I just cobbled together a test method t…
require_relative '../features_helper'
describe "as an admin", js: true do
it 'crawls the site with a tiny data set' do
default_url_options[:host] = "127.0.0.1:6543"
sign_in(:admin)
objects = [
create(:customer),
create(:job),
create(:employee),
it "can have the dig test requirement overridden" do
job = create :job
job.approve
sign_in(:dispatcher)
visit edit_job_path(job)
find(:css, "#job_no_dig_test_needed").set(true) #selenium test errors on this line - it can't find the selector but in reality it didn't find the job
click_button "Update"
visit job_path(job)
expect(page).to have_content "Activate"
end