Skip to content

Instantly share code, notes, and snippets.

View ryancheung's full-sized avatar
🌝

Ryan Cheung ryancheung

🌝
  • Earth
View GitHub Profile
@ryancheung
ryancheung / tag_spec.rb
Created November 25, 2012 02:15
specification pattern implementation
# encoding: utf-8
class TagSpec
attr_reader :tag
attr_accessor :result
def initialize(tag)
@tag = tag
end
def match?(tag_collection)
@ryancheung
ryancheung / deploy.rb
Created April 8, 2013 07:01
Capistrano config file example with Resque and Resque Scheduler
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Literal ":user"
set :application, "blog_test"
set :repository, "git@github.com:ryancheung/blog.git"
set :scm, :git
@ryancheung
ryancheung / unicorn.sh
Created April 11, 2013 04:57
Unicorn rails init script
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=$(pwd)
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="bundle exec unicorn_rails -D -c $APP_ROOT/config/unicorn.rb"
@ryancheung
ryancheung / unicorn.rb
Created April 11, 2013 05:02
Unicorn rails config example
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
rails_env = ENV["RAILS_ENV"] || "development"
RAILS_ROOT = File.expand_path("../../", __FILE__)
if rails_env == "production"
worker_processes 2
# Resize selenium browser window to avoid Selenium::WebDriver::Error::MoveTargetOutOfBoundsError errors
#
# Example usage with Rspec (in spec/support/spec_helper.rb):
#
# config.before(:each) do
# set_selenium_window_size(1250, 800) if Capybara.current_driver == :selenium
# end
#
def set_selenium_window_size(width, height)
window = Capybara.current_session.driver.browser.manage.window
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
# http://stackoverflow.com/a/8936202
#
# ActiveAdmin already includes the necessary jquery in active_admin/base,
# so just add this to javascripts/active_admin.js after //= require active_admin/base
#
#
# Serialize and Sort
#
# model_name - you guessed it, the name of the model we are calling sort on.
# This is the actual variable name, no need to change it.
@ryancheung
ryancheung / pubsub.coffee
Last active December 21, 2015 04:18
Simple pubsub implementation in coffee
window.ActiveAdminSortableEvent = do ->
eventToListeners = {}
return {
add: (event, callback) ->
if not eventToListeners.hasOwnProperty(event)
eventToListeners[event] = []
eventToListeners[event].push(callback)
trigger: (event, args) ->

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.

Running local YARD server

regenerates docs for each request

require 'bundler/capistrano'
set :application, "net"
set :repository, "git@githost.com:net.git"
set :scm, :git
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}