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
| Number::ordinal = -> | |
| return 'th' if 11 <= this % 100 <= 13 | |
| switch this % 10 | |
| when 1 then 'st' | |
| when 2 then 'nd' | |
| when 3 then 'rd' | |
| else 'th' | |
| Number::ordinalize = -> | |
| this + this.ordinal() |
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
| # spec/support/autocompletion.rb | |
| module Autocompletion | |
| def select_autocompletion(value, from:, with:, multiple: false) | |
| input_field = find_field(from) | |
| input_value = multiple ? "#{input_field.value}#{with}" : with | |
| # fill_in input[:id], with: input_value | |
| # input_field.trigger(:keydown) | |
| page.execute_script "$('##{input_field[:id]}').val('#{input_value}').trigger('keydown')" |
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
| jQuery.ajax | |
| async: false | |
| dataType: 'json' | |
| url: '/path/to/data.json' | |
| success: (data) -> | |
| google.load 'visualization', '1', {packages: ['corechart']} | |
| google.setOnLoadCallback -> | |
| table = new google.visualization.DataTable() | |
| table.addColumn 'datetime', 'Timestamp' | |
| table.addColumn 'number', 'Memory Total' |
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! RunFile() | |
| if match(@%, '.rb$') != -1 | |
| let argv = input('!ruby % ') | |
| exec '!ruby % ' . argv | |
| elseif match(@%, '.py$') != -1 | |
| let argv = input('!python % ') | |
| exec '!python % ' . argv | |
| else | |
| echo '<< ERROR >> RunFile() only supports ruby and python' | |
| endif |
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
| QuoteReport.new(:quarter, ReportFilter.new) | |
| # => Quote.all | |
| QuoteReport.new(:quarter, Composer.find(42)) | |
| # => Composer.find(42).quotes | |
| QuoteReport.new(:quarter, ReportFilter.new(composer_id: 42)) | |
| # => Quote.joins(cue: :composer).where(cue: {composer_id: 42}) | |
| QuoteReport.new(:quarter, ReportFilter.new(composer_id: [42, 101])) | |
| # => Quote.joins(cue: :composer).where(cue: {composer_id: [42, 101]}) |
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
| [1] pry(main)> Base64.encode64 'a' * 64 | |
| => "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh\nYWFhYWFhYWFhYWFhYWFhYWFhYQ==\n" | |
| [2] pry(main)> Base64.strict_encode64 'a' * 64 | |
| => "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==" |
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
| noremap <Leader>rs :call RunSpec('spec', '-fp')<CR> | |
| noremap <Leader>rd :call RunSpec(expand('%:h'), '-fd')<CR> | |
| noremap <Leader>rf :call RunSpec(expand('%'), '-fd')<CR> | |
| noremap <Leader>rl :call RunSpec(expand('%'), '-fd -l ' . line('.'))<CR> | |
| function! RunSpec(spec_path, spec_opts) | |
| let speccish = match(@%, '_spec.rb$') != -1 | |
| if speccish | |
| exec '!bundle exec rspec ' . a:spec_opts . ' ' . a:spec_path | |
| else |
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
| [1] pry(main)> user = User.new(password: nil, password_confirmation: nil) | |
| => #<User id: nil, username: nil, email: nil, name: nil, password_digest: nil, created_at: nil, updated_at: nil> | |
| [2] pry(main)> user.valid? | |
| => false | |
| [3] pry(main)> user.invalid?(:password) | |
| => true | |
| [4] pry(main)> user.errors[:password] | |
| => [] | |
| [5] pry(main)> user.errors[:password_confirmation] | |
| => [] |
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
| # Place in test_helper.rb or spec_helper.rb | |
| AuthLogic::CryptoProviders::BCrypt.cost = 1 |
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
| # RAILS_ROOT/lib/tasks/assets.rake | |
| namespace :assets do | |
| desc 'Precompile assets and upload to S3' | |
| task :upload, [:noop] => ['assets:clean', 'assets:precompile'] do |_, args| | |
| args.with_defaults(noop: false) | |
| Fog.credentials_path = "#{Rails.root}/config/fog_credentials.yml" | |
| Dir.chdir("#{Rails.root}/public") do | |
| assets = FileList['assets',"assets/**/*"].inject({}) do |hsh, path| |
NewerOlder