Skip to content

Instantly share code, notes, and snippets.

View vinh0604's full-sized avatar

Vinh Bachsy vinh0604

View GitHub Profile

I wanted a way to scale up and down the dynos in Heroku based on time of day. To do so, I added the scheduler add-on to heroku heroku addons:add scheduler

In my Rails app, I added the scale_dynos.rake file in /lib/tasks/ and the following line to the Gemfile: gem 'heroku-api', '~> 0.3.17', :require => false

Now I can run heroku run rake scale_dynos:up (and down) through the command line, as well as scheduling the command rake scale_dynos:up in the Scheduler add-on. a

# In config/initializers/local_override.rb:
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
...
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
config.authentication_keys = [ :login ]

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@vinh0604
vinh0604 / spec_helper.rb
Created November 29, 2012 12:52 — forked from terut/spec_helper.rb
Clean up carrierwave's files for rspec.
RSpec.configure do |config|
# ...
config.after(:all) do
if Rails.env.test?
FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"])
end
end
end
# put logic in this file or initalizer/carrierwave.rb
@vinh0604
vinh0604 / api.rb
Created November 28, 2012 03:50 — forked from noahhendrix/api.rb
API Spec
module Todo
class API < Grape::API
use Rack::Session::Cookie
version 'v1', :format => :json
resource do
http_basic do |username, password|
User.authenticate(username, password)
end
@vinh0604
vinh0604 / TableViewNeverending.js
Created October 24, 2012 12:05 — forked from mschmulen/TableViewNeverending.js
Titanium tableView with a continuous amount of data.
//
// in this demo, we simply show how you could dynamically scroll
// with a continuous amount of data in the tableview by detecting
// when the user's scroll position gets near the end of the table
// and start a background fetch of new data and seamlessly append
// the new data to the table automatically
//
var win = Ti.UI.createWindow();
@vinh0604
vinh0604 / ActionBarView.js
Created October 7, 2012 16:03 — forked from Mode54/ActionBarView.js
Action Bar Module for Titanium Mobile
/*
* Android API Guide
* http://developer.android.com/guide/topics/ui/actionbar.html
* Android Design Guide
* http://developer.android.com/design/patterns/actionbar.html
* Titanium Mobile will support someday
* https://jira.appcelerator.org/browse/TIMOB-2371
*/
var osName = Ti.Platform.osname,
isAndroid = osName==='android',