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 CaseComparator | |
| def initialize(object, operator) | |
| @object = object | |
| @operator = operator | |
| end | |
| def ===(other) | |
| other.send(@operator, @object) | |
| 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
| #!/usr/bin/env ruby | |
| `git diff --cached --name-only --diff-filter=AM`.lines.each do |filename| | |
| path = File.join(Dir.pwd, filename.strip) | |
| puts "Checking syntax of #{ filename.strip }" | |
| case filename | |
| when /.haml$/ | |
| exit 1 unless system('haml', '--check', path) | |
| when /.scss$/ | |
| exit 1 unless system('scss', '--check', path) |
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
| # This is not the best example, but imagine a Rails project with lots of complex logic and methods and stuff... | |
| # Imagine that Base is an 500 line ActiveRecord model... :) | |
| require 'rubygems' | |
| require 'active_support/core_ext' | |
| Customer = Struct.new(:id, :first_name, :last_name, :company_name) | |
| ## Implementation directly in the class | |
| # Pros: |
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
| # changed line 19 of rubygems/ext/builder.rb from: | |
| mf = File.read('Makefile') | |
| # into | |
| mf = File.read('Makefile', :encoding => 'iso-8859-15').encode('utf-8') | |
| # Problem was that qmake generated a Makefile that included a latin 1 "å" in the date because of swedish locales... |
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 | |
| # encoding: utf-8 | |
| require 'yaml' | |
| require 'stringio' | |
| class LocaleFormatter | |
| ESCAPE_KEYS = %w(true false yes no on off) | |
| ESCAPE_VALUE_RE = /[^[:alnum:]_\-\/\.\?]/ | |
| MULTILINE_INDENT_LEVEL = 2 |
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
| # encoding: utf-8 | |
| class LocaleDiffer | |
| RED = 31 | |
| GREEN = 32 | |
| def initialize | |
| load_locales | |
| 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
| class ActiveRecord::SchemaDumper | |
| def dump(stream) | |
| header(stream) | |
| tables(stream) | |
| sequences(stream) | |
| sequence_defaults(stream) | |
| trailer(stream) | |
| stream | |
| 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
| module I18n | |
| # Usage (Haml in examples): | |
| # | |
| # - t_scope(:"public.sign_up_or_log_in") do |s| | |
| # = simple_format(s.t(:text, | |
| # sign_up: link_to(s.t(:sign_up), signup_path), | |
| # log_in: link_to(s.t(:log_in), login_path))) | |
| # | |
| # is equivalent to | |
| # |
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
| # This takes about 1.6 seconds for 800x600 | |
| def short_screenshot!(width, height) | |
| pixels = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE) | |
| image = ChunkyPNG::Image.from_rgb_stream(width, height, StringIO.new(pixels)) | |
| image.flip_horizontally! | |
| image.save('screenshot.png', :fast_rgb) | |
| end | |
| # This takes about 0.8 seconds for 800x600 | |
| def long_screenshot!(width, height) |
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
| # Based on https://github.com/Sojo-Studios/catmull-rom/blob/master/test.js | |
| # This implementation assumes circular splines. | |
| class CatmullRomSplines | |
| def initialize(points) | |
| @key_points = points | |
| end | |
| def generate(detail) | |
| points = [] |