Skip to content

Instantly share code, notes, and snippets.

View aitor's full-sized avatar
👊
Working!

Aitor García Rey aitor

👊
Working!
View GitHub Profile
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class BuildStatusTest < ActiveSupport::TestCase
test "remove the old statii" do
assert_equal 2, BuildStatus.count
BuildStatus.expire_old
statii = BuildStatus.all
assert_equal 1, statii.size
assert statii[0].updated_at >= 30.days.ago
end
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class BuildStatusTest < ActiveSupport::TestCase
context "expiring build statii" do
should "remove the old one" do
assert_equal 2, BuildStatus.count
BuildStatus.expire_old
statii = BuildStatus.all
assert_equal 1, statii.size
assert statii[0].updated_at >= 30.days.ago
@alloy
alloy / status_bar_view.rb
Created March 30, 2011 09:10
A MacRuby example of a custom view in the status bar, with selection highlight.
class StatusBarView < NSView
attr_reader :progressIndicator, :statusBarItem
def initWithStatusBarItem(item)
bar = item.statusBar
if initWithFrame([[0,0], [bar.thickness, bar.thickness]])
@statusBarItem = item
@highlight = false
origin, size = frame.origin, frame.size
@SebastianEdwards
SebastianEdwards / gist:945263
Created April 27, 2011 21:30
Nicest way to get barista working on heroku
# Gemfile
gem "therubyracer-heroku"
# config/initializers/barista_config.rb
Barista.configure do |c|
c.root = Rails.root.join("app", "coffeescripts")
c.output_root = Rails.root.join("tmp", "javascripts")
end
require 'fileutils'
@teich
teich / gist:1000964
Created May 31, 2011 17:53
May 31st Heroku Updates
@bnadlerjr
bnadlerjr / hoboken.rb
Created June 26, 2011 23:39
Sinatra App Generator
#!/usr/bin/env ruby
require 'thor/group'
require 'thor/util'
require 'date'
class Hoboken < Thor::Group
desc 'Generates a new modular Sinatra app'
include Thor::Actions
@alloy
alloy / gist:1109803
Created July 27, 2011 16:50
Disable zooming in a UIWebView _without_ setting scalesPageToFit to NO.
- (void)hijackWebViewScrollViewDelegate:(UIWebView *)webView {
UIScrollView *scrollView = (UIScrollView *)[webView.subviews objectAtIndex:0];
scrollView.delegate = self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return nil;
}
// The rest of the UIScrollViewDelegate methods are not interesting for us, so forward them to the webview.
@raul
raul / retry_upto.rb
Created October 7, 2011 06:42
retry_upto.rb
# Ruby `retry` with steroids:
#
# - retry up to 5 times without waiting between them and retrying after any exception
#
# retry_upto(5) do ... end
#
# - retry up to 5 times, waiting 2 seconds between retries
#
# retry_upto(5, :wait => 2) do ... end
#
@alloy
alloy / gist:1281203
Created October 12, 2011 13:17
ActiveRecord::Relation#merge example
class Edition < ActiveRecord::Base
scope :published, where(arel_table[:published_at].not_eq(nil))
scope :generated, where(arel_table[:generated_at].not_eq(nil))
scope :available, published.generated
end
class Magazine < ActiveRecord::Base
# This is where #merge works its magic, by allowing you to merge scopes from other models.
scope :with_available_editions, includes(:editions).merge(Edition.available)
end
@cavalle
cavalle / feature.rb
Created November 7, 2011 16:22
Meatloaf (Just another scam)
require 'meatloaf'
require 'steps'
Feature "Eat candies" do
Scenario "Eat a candy from a jar full of them" do
Given "I have a jar with candies", candies: 10
When "I eat one candy"
Then "the jar won't be empty"
end