Skip to content

Instantly share code, notes, and snippets.

View ChunAllen's full-sized avatar

Allen Chun ChunAllen

  • Singapore
View GitHub Profile
@ChunAllen
ChunAllen / user.rb
Last active August 29, 2015 14:26
Roomarama Test Exercise
class User < ActiveRecord::Base
MAGIC_NUMBER = 3
VALIDCHARS = 'abcdefghjkmnpqrstuvwxyzABCDEFGJKMNPQRSTUVWXYZ23456789'
has_many :host_inquiries, class_name: 'Inquiry', foreign_key: 'host_id'
validates :password, presence: true
before_save :create_new_password
@ChunAllen
ChunAllen / capybara cheat sheet
Last active August 29, 2015 14:27 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=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')
@ChunAllen
ChunAllen / gist:359de08af46d632584ce
Last active August 29, 2015 14:27 — forked from ryansobol/gist:5252653
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@ChunAllen
ChunAllen / application.html.slim
Created August 15, 2016 10:44
Calling Javascript per controller and its action
doctype html
html
head
meta charset='UTF-8'
meta name='viewport' content='width=device-width, initial-scale=1.0'
meta http-equiv='x-ua-compatible' content='ie=edge'
title APP_NAME
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
- controller.js_assets.each do |name|
@ChunAllen
ChunAllen / Backup Heroku Database and Restore to Local
Last active November 28, 2016 04:09
Backup Heroku Database and Restore to Local
$ heroku login --> Login to your Heroku account using CLI
Create latest dump from heroku app
$ heroku pg:backups capture --app [heroku-remote]
$ heroku pg:backups public-url [database_num] --app [app_name]
$ curl -o latest.dump ‘[database_url]'
@ChunAllen
ChunAllen / API.md
Created April 5, 2017 03:33 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@ChunAllen
ChunAllen / chosen-bootstrap.css
Created August 6, 2017 03:23 — forked from koenpunt/chosen-bootstrap.css
Bootstrap 3.0 theme for Chosen
select.form-control + .chosen-container.chosen-container-single .chosen-single {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
color: #555;
vertical-align: middle;
background-color: #fff;
@ChunAllen
ChunAllen / host_your_rails_app_on_ec2.md
Created November 9, 2017 03:48 — forked from the-dvlpr/host_your_rails_app_on_ec2.md
Deploy and Reroute Traffic from Purchased Domain Name to your Rails App on a self-hosted EC2 Server

Punchlist for Serving your Rails App on an EC2 Instance

Run through this list to setup your EC2 instance and host your rails app. This list makes a few assumptions (make changes as necessary)

  • You have github repo with a rails app pushed to it that we'll just pull down to the new server
  • You're using Rails 5.1

If not, see very bottom for steps to build a quick example app.

Launching EC2 instance

  • Use the basic Linux AMI distro: Amazon Linux AMI 2017.09.0 (HVM), SSD Volume Type - ami-8c1be5f6
  • Select a size: t2.micro is fine for this, unless you need larger for a production app
@ChunAllen
ChunAllen / Capistrano Commands
Created November 19, 2017 13:56 — forked from clara101/Capistrano Commands
Deploy Rails 4 to AWS EC2(Ubuntu 14.04.4 LTS). Nginx, Puma, Capistrano3, PostgreSQL, RVM.
Capistrano::Rails::Db
cap production deploy:db:abort_if_pending_migrations # Run rake db:abort_if_pending_migrations
cap production deploy:db:create # Run rake db:create
cap production deploy:db:drop # Run rake db:drop
cap production deploy:db:migrate # Run rake db:migrate Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
cap production deploy:db:migrate:down # Run rake db:migrate:down Run the "down" for a given migration VERSION
cap production deploy:db:migrate:redo # Run rake db:migrate:redo Rollback the database one migration and re migrate up (options: STEP=x, VERSION=x)
cap production deploy:db:migrate:reset # Run rake db:migrate:reset Reset your database using your migrations
cap production deploy:db:migrate:status # Run rake db:migrate:status Display status of migrations
cap production deploy:db:migrate:up # Run rake db:mi
@ChunAllen
ChunAllen / how-to-copy-aws-rds-to-local.md
Created December 15, 2017 09:59 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored