Skip to content

Instantly share code, notes, and snippets.

View dabit's full-sized avatar

David Padilla dabit

View GitHub Profile
@dabit
dabit / Rack.rb
Created March 21, 2013 03:31
Railsconf talk
def call(env)
[200, {}, 'Hello']
end
def foo(options = {})
[options[:bar], options[:baz]]
end
foo(bar: '12345', baz: 'abcdef') # => ["12345", "abcdefg"]
def times_bought
count = 0
orders = Spree::Order.complete
orders.each {|o| count+=1 if o.products.include?(self)}
count
end
def matches?(env)
req = @request.new(env)
@constraints.each { |constraint|
if constraint.respond_to?(:matches?) && !constraint.matches?(req)
return false
elsif constraint.respond_to?(:call) && !constraint.call(*constraint_args(constraint, req))
return false
end
}
@dabit
dabit / Gemfile
Last active December 12, 2015 01:38
Rails Issue #8811
source "https://rubygems.org"
gem "sqlite3"
gem "rails", :git => 'https://github.com/rails/rails.git', :branch => '3-2-stable'
@dabit
dabit / Rakefile
Created November 16, 2012 17:26
How to fix the Ruby motion dependency problem
Motion::Project::App.setup do |app|
app.files.insert(-10, "./app/controllers/nav_bar_controller.rb")
end
@dabit
dabit / lazy-1.rb
Created November 4, 2012 06:25
Ruby 2.0 features examples
elements = (1..19999999)
p elements.class # => Range
results = elements.select { |n|
n % 2 == 0
}.map { |n|
n + 1
}.take(10)
@dabit
dabit / fix_skype_conversation_icons_retina.sh
Created October 14, 2012 03:40 — forked from dive/fix_skype_conversation_icons_retina.sh
Fix the size of avatars in the Skype conversation screen for Retina Macbook Pro screen
#!/bin/bash
# by Artyom Loenko aka dive (artyom.loenko@mac.com)
# Usage:
# - download this script
# - open Terminal.app
# - goto to Folder where script downloaded
# - run 'chmod +x fix_skype_conversation_icons_retina.sh'
# - then run './fix_skype_conversation_icons_retina.sh'
@dabit
dabit / spree_spec.rb
Created September 29, 2012 17:55
Spec for the spree issue
require 'spec_helper'
describe Spree::Config do
before do
ActionController::Base.perform_caching = true
# config.cache_store = :dalli_store, { expires_in: 5.seconds }
end
it "Should fallback to database if cache keys expire" do
Spree::Config.featured_sale_id = 10
@dabit
dabit / gist:3800937
Created September 28, 2012 16:55 — forked from anonymous/gist:3791655
SG codigo 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SG___Code_1
{
class Program
{
static void Main(string[] args)