Skip to content

Instantly share code, notes, and snippets.

@stanislaw
stanislaw / warden.rb
Created May 16, 2011 05:45 — forked from cavalle/warden.rb
Testing Warden/Devise with Steak
# Create a file `spec/acceptance/support/warden.rb' with the following
# contents:
Spec::Runner.configure do |config|
config.include Warden::Test::Helpers, :type => :acceptance
config.after(:each, :type => :acceptance) { Warden.test_reset! }
end
# Or, if you're using RSpec 2 / Rails 3, the contents should be the following
# instead:
@stanislaw
stanislaw / handystuff.md
Created September 19, 2011 21:19 — forked from gilgen/handystuff.md
Handy stuff
@stanislaw
stanislaw / ruby-1.9-tips.rb
Created November 25, 2011 19:13 — forked from igrigorik/ruby-1.9-tips.rb
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@stanislaw
stanislaw / README.md
Created December 27, 2011 19:15 — forked from jlecour/README.md
Identify paperclip attachment files that are not attached to any record

Let's say you have a model, with an files attached, using Paperclip. You have a couple millions of those files and you're not sure that every one of them (and all its thumbnails) are still used by a database record.

You could use this rake task to recursively scan all the directories and check if the files need to be kept or destroyed.

In this example, the model is called Picture, the attachment is image and the path is partitioned like images/001/412/497/actual_file.jpg

The task is going down the path. Each time the path ends with 3 triplets of digits ("001/412/497" for example) it looks for a record with the ID 1412497. If such a record doesn't exist, the whole directory is moved to a parallel images_deleted directory. At the end you can delete the files if you like, or move them to an archive location.

You can use the "dry run" mode : to print which files would be removed

@stanislaw
stanislaw / spec_helper.rb
Created February 3, 2012 17:23 — forked from sr75/spec_helper.rb
Example rails 3.1 spec_helper.rb file using spork, rspec, factory_girl, database_cleaner, I18n
require 'spork'
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.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
@stanislaw
stanislaw / gist:2049280
Created March 16, 2012 09:32
Cucumber & Capybara against Spork - Always run tests in the same browser.
require 'rubygems'
require 'spork'
ENV["RAILS_ENV"] = 'test'
Spork.prefork do
require 'cucumber/rails'
require 'capybara/rails'
@stanislaw
stanislaw / sunrise.rb
Created March 25, 2012 21:23 — forked from njh/sunrise.rb
Ruby Code to calculate sunrise and sunset times where I live
#!/usr/bin/env ruby
require 'rubygems'
require 'solareventcalculator'
solar = SolarEventCalculator.new(Date.today, BigDecimal.new('51.563'), BigDecimal.new('-0.499'))
puts "Sunrise: #{solar.compute_utc_civil_sunrise.getlocal}"
puts "Sunset: #{solar.compute_utc_civil_sunset.getlocal}"
@stanislaw
stanislaw / gist:3132473
Created July 17, 2012 22:09
ruby-vips spec segmentation fault
/home/stanislaw/work/gems/ruby-vips/spec/vips/relational_spec.rb:31: [BUG]
Segmentation fault
ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]
-- Control frame information -----------------------------------------------
c:0022 p:---- s:0081 b:0081 l:000080 d:000080 CFUNC :more
c:0021 p:0020 s:0077 b:0077 l:000f54 d:000076 BLOCK
/home/stanislaw/work/gems/ruby-vips/spec/vips/relational_spec.rb:31
c:0020 p:---- s:0074 b:0074 l:000073 d:000073 FINISH
c:0019 p:---- s:0072 b:0072 l:000071 d:000071 CFUNC :instance_eval
@stanislaw
stanislaw / ruby-vips-vs-oil.rb
Created July 29, 2012 14:35
Ruby-vips vs Oil
#!/usr/bin/env ruby
require 'rubygems'
gem 'ruby-vips'
gem 'oil'
require 'vips'
require 'oil'

Howdy howdy, NSHipsters!

If you alloc init an NSCalendar, you'll notice that New Year's Eve falls on a Monday this year, a.k.a. "the day NSHipster is published every week". What fun!

So in celebration of the upcoming year++, I thought it'd be fun to compile a list of some of your favorite tips and tricks of the trade. Submit your favorite piece of Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

Here are a few examples of the kind of things I'd like to see: