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
| # Each time a failed authentication attempt happens we call the lockable handlers | |
| Warden::Manager.before_failure do |record, warden, options| | |
| if record && record.respond_to?(:active?) && !record.active? | |
| scope = options[:scope] | |
| # If winning strategy was set, this is being called after authenticate and | |
| # there is no need to force a redirect. | |
| if warden.winning_strategy | |
| warden.winning_strategy.fail!(record.inactive_message) | |
| 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
| class NFE < ActiveRecord::Base | |
| validates_presence_of :service_value | |
| usar_como_dinheiro :service_value | |
| end | |
| # >> n = NFE.new | |
| # >> n.service_value = 10 | |
| # => 10 | |
| # >> n.valid? | |
| # => true |
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
| # My Method | |
| def mymethod | |
| # My puts | |
| puts "Ruby Rocks" | |
| 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
| def mod10_febraban(value) | |
| result_string = "" | |
| factor = 2 | |
| total = 0 | |
| value.each_char do |c| | |
| result_string << (c.to_i * factor).to_s | |
| factor = (factor == 2 ? 1 : 2) | |
| end | |
| result_string.each_char { |c| total += c.to_i } | |
| result = 10 - total % 10 |
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
| Factory.define :application do |factory| | |
| factory.attachment(:sample, "public/samples/sample.doc", "application/msword") | |
| 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
| require 'formula' | |
| # some credit to http://github.com/maddox/magick-installer | |
| # NOTE please be aware that the GraphicsMagick formula derives this formula | |
| def ghostscript_srsly? | |
| ARGV.include? '--with-ghostscript' | |
| end | |
| def x11? |
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
| # coding: utf-8 | |
| import struct | |
| with open('in.bmp', 'rb') as fd, open('out.bmp', 'wb') as out: | |
| s = fd.read(1) | |
| count = 1 | |
| while s: | |
| if count < 37: # header bytes | |
| out.write(s) |
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
| Ctrl-L gives a hashrocket with spaces | |
| Shift-Ctrl-[ alternate between {} and do/end blocks | |
| Shit-Cmd-D open the require file in another window | |
| Ctrl-shift-V validates syntax of ruby file | |
| Ctrl-shift-E executes the line | |
| Ctrl-shift-; alternate between string and symbol | |
| Shift-Option-Cmd-Down show possible destinations | |
| Ctrl-Shift-H create partial from selection | |
| Ctrl-P gives params[:id] |
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 Note; end | |
| class C < Note; end | |
| class Cs < C; end | |
| class D < Note; end | |
| class Db < D; end | |
| class Ds < D; end | |
| class E < Note; 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
| Creating a gist from textmate |