Skip to content

Instantly share code, notes, and snippets.

View ryancheung's full-sized avatar
🌝

Ryan Cheung ryancheung

🌝
  • Earth
View GitHub Profile

installing postgresql 9.3.2 on ubuntu 12.04

$ echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-9.3 postgresql-contrib-9.3

you should succesfully installing postgresql 9.3.2 on your machine.

# rubocop config files for small Rails4/Ruby2 project
# blog post: http://joanswork.com/rubocop-rails-getting-started/
# .rubocop.yml
AllCops:
Include:
- Rakefile
- config.ru
Exclude:
# replace file basename with a UUID when uploaded
# e.g.: avatar.jpg becomes 41bf830f-80cf-4efe-ad90-3b29bc6708b5.jpg
# but don't regenerate a UUID each time file url is accessed
class User < ActiveRecord::Base
has_attached_file :avatar, path: ":basename.:extension"
before_validation { set_avatar_file_name }
def set_avatar_file_name
# replace any NEW filename with a UUID
#! /bin/bash
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@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 / 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.