Skip to content

Instantly share code, notes, and snippets.

View calvincorreli's full-sized avatar

Calvin Correli calvincorreli

View GitHub Profile
def estimate_fee(cents, cardtype)
case cardtype.to_s.downcase
when /dankort/
# Dankort:
# http://www.pbs.dk/da/produkter/dankort/Documents/DK_Prisliste_Dankort_eDankort_DK.pdf
# Transaction size Price
# 0 - 50.00 DKK 0.70 DKK
# 50.01 - 100.00 DKK 1.10 DKK
# > 100.01 1.45 DKK + 0.1%
# Using this: 1.45 DKK + 0.10%
@calvincorreli
calvincorreli / be.sh
Created July 29, 2012 21:59
Bundle Edit
#!/bin/zsh
file=`/Users/lars/.rvm/gems/ruby-1.9.3-p0/bin/bundle show $1`
if [ -x "$file" ]
then
mate $file
else
echo "No gem named $1 found" 1>&2
exit -1
fi
@calvincorreli
calvincorreli / glyphicons.rake
Created February 9, 2012 17:53
Glyphicons helper
task :glyphs => :environment do
glyphs = []
glyphs_hash = {}
longest_name = 0
Dir.glob(Rails.root.join("app", "assets", "images", "glyphicons", "*.png")) do |path|
width, height = `identify -format "%wx%h" #{path}`.strip.split(/x/)
# glyphicons_083_random.png
# glyphicons_083_random@2x.png
# glyphicons_halflings_047_bold.png
source 'http://rubygems.org'
gem "rails", '3.2.0.rc1'
gem "mysql2"
# Assets
group :assets do
gem 'sass-rails', git: 'https://github.com/rails/sass-rails.git', branch: '3-2-stable'
gem "coffee-rails"
@calvincorreli
calvincorreli / mixins.css.scss
Created November 30, 2011 10:25
IE gradient mixin with SCSS/SASS
@mixin gradient($first, $second) {
background-color: $second;
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#{ie-hex-str($first)}', endColorstr='#{ie-hex-str($second)}');";
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#{ie-hex-str($first)}', endColorstr='#{ie-hex-str($second)}');;
zoom: 1;
background: -webkit-gradient(linear, left top, left bottom, from($first), to($second));
background: -moz-linear-gradient(top, $first, $second);
}
@calvincorreli
calvincorreli / set_default_form_builder.rb
Created November 8, 2011 17:54
Set default form builder with autoload
module ActionView
module Helpers
module FormHelper
def form_for_with_bootstrap(record, options = {}, &proc)
options[:builder] = BootstrapFormBuilder
form_for_without_bootstrap(record, options, &proc)
end
def fields_for_with_bootstrap(record_name, record_object = nil, options = {}, &block)
options[:builder] = BootstrapFormBuilder
@calvincorreli
calvincorreli / jquery_link_to.js
Created September 6, 2011 11:11
Link two input fields
@calvincorreli
calvincorreli / examples.rb
Created September 5, 2011 19:52
Glyphicons rake task and helpers
link_to_glyphicon(:edit, edit_admin_product_coupon_path(@product, coupon))
glyphicon(:move, :class => 'drag_handle', :title => "Drag to reorder", :variant => :halfling)
@calvincorreli
calvincorreli / exceptional_for_delayed_job.rb
Created November 24, 2010 11:02
Integrating Exceptional with https://github.com/collectiveidea/delayed_job - put this in config/initializers/
if !Exceptional::Config.api_key.nil? && Rails.env == 'production'
begin
class Delayed::Worker
def handle_failed_job_with_exceptional(job, error)
Exceptional.handle(error, "Delayed::Job #{self.name}")
handle_failed_job_without_exceptional(job, error)
Exceptional.context.clear!
end
alias_method_chain :handle_failed_job, :exceptional
Exceptional.logger.info "Lars Pind's custom DJ integration enabled"
@calvincorreli
calvincorreli / cloudfront_not_streaming_log.pig
Created November 21, 2010 15:25
Parse cloudfront log for non-streaming distribution and count bandwidth per object that matches /uploads/assets/file/...
register file:/home/hadoop/lib/pig/piggybank.jar
raw_logs =
LOAD '$INPUT'
USING PigStorage('\t')
AS (
date: chararray, time: chararray, x_edge_location: chararray, sc_bytes: int,
c_ip: chararray, cs_method: chararray, cs_host: chararray, cs_uri_stem: chararray,
sc_status: chararray, cs_referer: chararray, cs_user_agent:chararray, cs_uri_query: chararray
);