Skip to content

Instantly share code, notes, and snippets.

@garethrees
garethrees / some_migration.rb
Created April 25, 2012 17:12
Touching data in migrations
$ git clone my_repo && cd my_repo
$ bundle install
$ rake db:create
$ rake db:create
=> Oh no! I can't build the db because I don't have any instances of SomeModel. Useless!
@garethrees
garethrees / gist:2512256
Created April 27, 2012 19:48
Questions/Topics for May cardiffrb

Lets face it; deploying Ruby applications is not the easiest thing to deal with. It's great if you use Heroku, or you have one or two apps on one server. But what happens when you want to run multiple apps, servers and Ruby versions.

There's not a great amount of support for deb/rpms, and RVM essentially builds from source.

@mattwillsh has offered to come and discuss the issue with us, so should make for some heated debates!

Join us @cardiffrb on Thursday May 10th 2012


@garethrees
garethrees / index.html.erb
Created May 3, 2012 11:15
HTML5 / SCSS Structure
<section id="widgets">
<% @widgets.each do |widget| %>
<article class="widget">
<!-- widget.stuff -->
</article>
<% end %>
</section>
<nav>
<ul>
<li>
<a>Item 1</a>
<ul>
<li>
<a>Subnav Item 1</a>
@garethrees
garethrees / gist:3039032
Created July 3, 2012 10:51
Fake Time.now and Time.zone.now
$start = Time.now - 1.month # this time last month
class Time
class << Time
def new
$start
end
def now
Time.new
end
end
/*
* do some jQuery magic on load
*/
$(document).ready(function() {
function showHiddenParagraphs() {
$("p.hidden").fadeIn(500);
}
setTimeout(showHiddenParagraphs, 1000);
});
@garethrees
garethrees / ruby.rb
Created July 19, 2012 09:58
Ruby Symbols
a = Person.new("Gareth", :occupation => "dev", :gender => "male", :hometown => "Pontypridd")
b = Person.new("Gareth", :hometown => "Pontypridd", :gender => "male", :occupation => "dev")
# a == b
@garethrees
garethrees / gist:3190153
Created July 27, 2012 19:52
Git Options
git config --global color.ui 1
git status -sb
# In Ruby you can do this:
if something then do_this else do_that
# Which is the same as:
something ? do_this : do_that
@garethrees
garethrees / gist:3714817
Created September 13, 2012 14:52
Rails Association CollectionProxy
# Ugh Rails Association CollectionProxy!
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/collection_proxy.rb
>> CountryProfile.all == Site.first.country_profiles
=> true
>> CountryProfile.all.count(:group => 'region')
=> 0
>> Site.country_profiles.count(:group => 'region')
=> #<OrderedHash {"Africa"=>4, "Asia"=>3, "Middle East/Eastern Europe"=>1, "Latin America"=>1}>