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 Kernel | |
| # Prints out progress | |
| @@printp_spinner = %w(⇐ ⇖ ⇑ ⇗ ⇒ ⇘ ⇓ ⇙) | |
| @@printp_spinnerpos = 0 | |
| @@printp_cols = [`tput cols`.to_i - 20, 50].max | |
| def printp(symbol, i) | |
| print @@printp_spinnerpos % @@printp_cols == 0 ? "\n" : ("\b" * (16 + symbol.size)) | |
| print "#{symbol}#{" %3d%" % i} complete #{@@printp_spinner[(@@printp_spinnerpos+=1) % 8]} " | |
| STDOUT.flush | |
| 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 "bcrypt" | |
| a = ::BCrypt::Password.create "somepassword" # => "$2a$10$DaVOCJ1GX1z9ZPMAda2UQOwyZQKbghWwHc249YURGlGhsfNy/PZtm" | |
| b = ::BCrypt::Password.create "somepassword" # => "$2a$10$BA6xc2/2WQ30T.rHsviMH.SP8/9JXbRtvgABceoNzd8z2.xO9J1IC" | |
| ::BCrypt::Password.new(a) == "somepassword" # => true | |
| ::BCrypt::Password.new(b) == "somepassword" # => 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
| class UserSession < Authlogic::Session::Base | |
| ... # rest of your code | |
| private | |
| # Reorder persist_callback_chain at runtime (only way I know of doing this). | |
| def run_callbacks(kind, options = {}, &block) | |
| self.class.send("#{kind}_callback_chain").tap { |callback_chain| | |
| if kind.to_s == "persist" |
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 UserSession < Authlogic::Session::Base | |
| ... # rest of your code | |
| _persist_callbacks.replace(_persist_callbacks.sort_by { |cb| | |
| order = %w(params session http_auth cookie).index(cb.filter.to_s.sub(/^persist_by_/, '')) | |
| order || _persist_callbacks.size | |
| }) | |
| __define_runner(:persist) # must regenerate _run_persist_callbacks() to take effect | |
| 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 Kernel | |
| @@frame1 = " ======== ᙅ ⎌ ᙂ ========" | |
| @@frame2 = " ======== ᘩ ⎌ ᘵ ========" | |
| @@framepos = 1 | |
| def swim | |
| frame = @@framepos == 1 ? @@frame1 : @@frame2 | |
| print frame | |
| sleep 0.3 | |
| print "\b" * frame.size |
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
| # config/routes.rb | |
| mount MyGrapeAPI => "/grape_api" | |
| namespace :api do | |
| namespace :v1 do | |
| resources :projects | |
| end | |
| end | |
| ####################### | |
| ##### RAILS 3 API ##### |
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
| boxee.apiMinVersion=7.0; | |
| boxee.reloadOnPageChange = true; | |
| boxee.setMode(boxee.CURSOR_MODE); | |
| boxee.onKeyboardKeyDown = function() { | |
| document.write("TIEG") | |
| } | |
| boxee.onMouseMoveDown = function() { | |
| document.write("MOUSE MOVE DOWN"); | |
| } |
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 SomeClass | |
| self.instance_variable_set('@my_attribute', {:class => true}) | |
| def self.my_attribute; @my_attribute; end | |
| def self.inherited(klass) | |
| val = self.instance_variable_get('@my_attribute') | |
| klass.instance_variable_set('@my_attribute', val.duplicable? ? val.dup : val) | |
| super | |
| 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
| // Key difference: the old way of using {write,read}_inheritable_attribute was | |
| // a *static default* for child classes. The new way of using class_attribute is a | |
| // *dynamic default*. | |
| class A | |
| class_attribute :foo | |
| self.foo = 1 | |
| end | |
| class B < A; end | |
| class C < B; end |