Skip to content

Instantly share code, notes, and snippets.

View jumph4x's full-sized avatar

Denis Ivanov jumph4x

  • FCP Euro
  • Oakland
View GitHub Profile
@jumph4x
jumph4x / gist:2232399
Created March 29, 2012 01:54
I love your feet Ryan
GRADES = ['A', 'B', 'C', 'D']
def grade_formula(book_count, reads_books = true)
raise "One cannot have read a negative amount of books, you numbnuts." if book_count < 0
index = case book_count
when 0..9
3
when 10..20
2
@jumph4x
jumph4x / Rakefile
Created March 27, 2012 18:20
Depending on a third-party Spree Extension and including relevant migrations while generating a dummy application for testing
desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree_google_base'
puts 'Installing spree-multi-domain migrations [required for testing]'
dep_path = `bundle show spree_multi_domain`.chomp
migration_path = File.join(dep_path,'db','migrate')
dummy_path = File.join(FileUtils.pwd, 'spec', 'dummy', 'db')
FileUtils.mkdir_p(dummy_path)
@jumph4x
jumph4x / gist:2158376
Created March 22, 2012 13:37
Using [unreleased] master spree executables to generate extensions
bundle
bundle show spree
# => /home/denis/.rvm/gems/ruby-1.9.2-p290/bundler/gems/spree-b58d645ac730/cmd
/home/denis/.rvm/gems/ruby-1.9.2-p290/bundler/gems/spree-b58d645ac730/cmd/bin/spree
# voila
@jumph4x
jumph4x / gist:2152664
Created March 21, 2012 20:37
manual rate_hash iteration for spree
#this is what Order#rate_hash outputs, roughly
sample_rate_hash = [{:id => 4, :name => 'ShippingMethod', :price => 24.55}]
# we take the array of hashes and for each one we create an HTML <option>, we show the user the name and the price, for value we store the shipping_method_id
# then we join all the html options into one string
# then we mark the string as safe for frontend
options = sample_rate_hash.map{|rate| content_tag(:option, "#{rate[:name]} #{rate[:price]}", :value => rate[:shipping_method_id])}.join.html_safe
# then we simply give that to select
select_tag :order, options
@jumph4x
jumph4x / gist:2141056
Created March 20, 2012 20:39
Loopty loop
# rake
# Same as invoke, but explicitly pass a call chain to detect
# circular dependencies.
def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
new_chain = InvocationChain.append(self, invocation_chain)
@lock.synchronize do
if application.options.trace
$stderr.puts "** Invoke #{name} #{format_trace_flags}"
end
@jumph4x
jumph4x / gist:2139089
Created March 20, 2012 18:16
Asset precompilation failure with Spree 1.0.3 and Rails 3.1.4
denis@h213h:~$ cd rails/vanilla-spree/
denis@h213h:~/rails/vanilla-spree$ rake assets:precompile --trace
(in /home/denis/rails/vanilla-spree)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/denis/.rvm/rubies/ruby-1.9.2-p290/bin/ruby ./bundler_stubs/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
(in /home/denis/rails/vanilla-spree)
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
@jumph4x
jumph4x / hw0-makefile
Created January 27, 2011 03:50
CSE4100/hw0: Makefile
OFILES = main.o# type.o
LEX = flex
BISON = bison
CPATH =
CC = $(CPATH)llvm-g++
LD = $(CPATH)llvm-g++
CXXFLAGS = `$(CPATH)llvm-config --cppflags`
LDFLAGS = `$(CPATH)llvm-config --ldflags --libs core jit native`
all: typetest
require 'prawn/layout'
require 'prawn/format'
bill_address = @order.bill_address
ship_address = @order.ship_address
font "Helvetica"
image Spree::PrintInvoice::Config[:print_invoice_logo_path], :at => [0,720], :scale => 0.65
require 'rubygems'
require 'spork'
require 'factory_girl'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
unless defined? SPREE_ROOT
@jumph4x
jumph4x / gist:194473
Created September 26, 2009 22:14
Can factory_girl do this? Is it my RSpec loading order?
# factories.rb
Factory.define :app do |i|
i.association :sku, :factory => :sku
i.base_vehicle_id BaseVehicle.last.id
end
# base_vehicle.rb
class BaseVehicle < ActiveRecord::Base
self.establish_connection :special_connection
end