- no fucking semi-colons (unless you really want them)
- irb
- local variable definition
- +, *, /, - are all methods
- puts vs print
- multiplying strings
- using if & when
- defining a method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Zip::ZipFile.open(f).read("data.txt").to_a.map { |x| x.chomp.split("|") }.delete_if { |x| x[2] == "KX" }.map { |a| BigDecimal(a.last) }.inject(0) { |sum, x| sum + x } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # First thing we need is the raw connection to our database. ActiveRecord makes this quite easy... | |
| pg_connection = ModelName.connection.raw_connection | |
| # Next, tell PG that we're going to be copying a boat load of data into model_names... | |
| pg_connection.exec "COPY model_names (field_a, field_b, field_c) FROM STDIN" | |
| # Process our file line-by-line | |
| IO.foreach("path/to/file.tsv", "r") do |line| | |
| # Convert our tab-delimited string into an array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class IncrementJumpingFormBuilder < ActionView::Helpers::FormBuilder | |
| def fields_for_with_nested_attributes(association_name, args, block) | |
| name = "#{object_name}[#{association_name}_attributes]" | |
| association = args.first | |
| if association.respond_to?(:new_record?) | |
| association = [association] if @object.send(association_name).is_a?(Array) | |
| elsif !association.is_a?(Array) | |
| association = @object.send(association_name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| class Foo | |
| attr_accessor :bar, :baz, :florp | |
| def initialize(properties = {}) | |
| properties.each do |key, value| | |
| self.send("#{key}=", value) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it "determines the controller name" do | |
| helper.instance_eval do | |
| stub(:params).and_return(controller: 'foos') | |
| resource_name.should == 'foos' | |
| namespace.should == nil | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [PlanetExpress] dan: ~/Desktop [ no repo | ree-1.8.7-2010.02@test ] | |
| > gem install rails -v=2.2.2 | |
| Successfully installed activesupport-2.2.2 | |
| Successfully installed activerecord-2.2.2 | |
| Successfully installed actionpack-2.2.2 | |
| Successfully installed actionmailer-2.2.2 | |
| Successfully installed activeresource-2.2.2 | |
| Successfully installed rails-2.2.2 | |
| 6 gems installed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mate() { | |
| if [[ `pwd` == ~ && $1 = "." ]]; then | |
| echo "Steadfastly refusing to open your entire home directory in TextMate." | |
| else | |
| /usr/local/bin/mate $1 | |
| fi | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT (field_a + field_b + field_c) AS virtual_field, * | |
| FROM "table_name" | |
| WHERE ("table_name".reference_id = 9999 AND (virtual_field > 0)) | |
| AND (boolean_field = 't') | |
| ORDER BY virtual_field DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function grr { | |
| if [[ -f ./Gemfile ]]; then | |
| bundle exec rake routes | awk '{ print $1; }' | grep $1 | |
| else | |
| rake routes | awk '{ print $1; }' | grep $1 | |
| end | |
| } |