Skip to content

Instantly share code, notes, and snippets.

@amencarini
amencarini / default_tax.rb
Created February 18, 2012 16:55
default_tax.rb with different calculation method
def compute_order(order)
matched_line_items = order.line_items.select do |line_item|
line_item.product.tax_category == rate.tax_category
end
line_items_total = matched_line_items.sum(&:total)
round_to_two_places(line_items_total - ( line_items_total / (1 + rate.amount) ) )
end
def compute_line_item(line_item)
@PetrKaleta
PetrKaleta / config.ru
Created March 20, 2012 14:27
The Rack::TryStatic middleware delegates requests to Rack::Static middleware trying to match a static file
# config.ru
# The Rack::TryStatic middleware delegates requests to Rack::Static middleware
# trying to match a static file
#
# Inspired by original code from rack-contrib
# http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
#
module Rack
<!doctype html>
<!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ -->
<html>
<head>
<title>iOS 8 web app</title>
<!-- CONFIGURATION -->
@corny
corny / date_scope.rb
Created March 29, 2012 10:55
Flexible rails scope for date-attributes in a PostgreSQL table
#
# Scopes for date attribute
# https://gist.github.com/2235839
#
module Common::DateScope
extend ActiveSupport::Concern
included do
unless respond_to?(:year)
@dg
dg / fibonacci.js
Last active October 2, 2015 23:07
Fibonacci number benchmark
// fibonacci(40) takes 2 seconds in Node.js 0.6.14
// http://en.wikipedia.org/wiki/Fibonacci_number
function fibonacci(n) {
return n < 2 ? n : fibonacci(n-2) + fibonacci(n-1);
}
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@mfojtik
mfojtik / pretty_exceptions.rb
Created May 25, 2012 15:19
This piece of code will report the chunk of code that caused exception
class StandardError
alias :original_backtrace :backtrace
def backtrace
unless original_backtrace.nil?
file, number = original_backtrace.first.split(':')
$stdout.print "\n# %s\n\n" % file
__get_script_line(file, number.to_i) do |line|
$stdout.print line
@peter
peter / creating-edgerails-app.sh
Created June 30, 2012 21:03
Creating and Deploying an EdgeRails (Rails 4) Application to Heroku
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone https://github.com/rails/rails.git
@juandazapata
juandazapata / mountain_lion_home_brew.md
Created July 26, 2012 15:07
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

After upgrading to Mountain Lion, I got this message when trying to run my local rails server:

Installing rmagick (2.13.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    Users/user/.rvm/rubies/ruby-1.9.3-rc1/bin/ruby extconf.rb
@mrrooijen
mrrooijen / README.md
Created August 15, 2012 01:30
Heroku SSL Endpoint, RapidSSL

Heroku SSL Endpoint

Assumptions:

  • You want to enable SSL for your domain.
  • You want to go with RapidSSL.
  • Your domain name is www.domain.com during this example.
  • You want to encrypt requests for a single domain (no wildcard)
  • You want to apply this certificate to Heroku's SSL Endpoint