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
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
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
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
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
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
puts a = (2500 * 56) / 10000.0 # => 14.0 | |
puts b = (250 * 5.6) / 100.0 # => 14.0 | |
puts c = 25 * 0.56 # => 14.0 | |
puts a % 1 # => 0 ... Expected | |
puts b % 1 # => 0 ... Expected | |
puts c % 1 # => 1.77635683940025e-15 .. Not Expected |
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
if /(?<hour>\d?\d)\:(?<min>\d\d)(?<suffix>[pa]m)/ =~ "5:03pm" | |
puts hour | |
puts min | |
puts suffix | |
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 WillPaginate | |
class Collection | |
# This is a special case of paginate() for _dubstep_ fans (_hyper-dubstep_ not supported). | |
# It is different in this regard: | |
# * The first page should load +first_per_page+ records | |
# * The rest of the pages should load +more_per_page+ records | |
# | |
# NOTE: will_paginate view helpers not really tested with this (eg the '1,2,3...N' thing) | |
# | |
def self.dubstep_paginate(finder, page = 1, first_per_page = 15, more_per_page = 15, finder_opts = {}) |