Skip to content

Instantly share code, notes, and snippets.

View alex-zige's full-sized avatar
🤞
Focusing

Alex Z. Li alex-zige

🤞
Focusing
View GitHub Profile
@alex-zige
alex-zige / gist:6445334
Last active December 22, 2015 08:29
put it into your ~/.bash_profile. Allow you to create Pull Request faster.
function pr () {
local repo=`git remote -v | grep "origin" | grep -m 1 "(push)" | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
local branch=`git name-rev --name-only HEAD`
echo "... pushing current branch \"$branch\" in \"$repo\" to github" &&
$(git push origin $branch) &&
echo "... push succeed" &&
target_branch=$1
echo "... creating pull request for branch \"$branch\" in \"$repo\"" &&
if [[ ! -z $target_branch ]]; then
open https://github.com/$repo/pull/new/$target_branch...$branch
@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views

DNS for EC2 / Elastic Beanstalk Load Balancing

Becuase EC2 and Elastic Beanstalk instance will apply load balancer, so no static IP address is assigned. So the only valid option is to create "www" cname that opint to the EC2 instantces load balancing url. However, if you want to change the root level domian, most of DNS provider won't allow you to do so, cause the URL is not a valid ip address. Some DNS provider allows you to create @ cname and point to 'app.url'

Alternatively, could use AWS Router 53. Router 53 helps you created hosted zone that then define record sets. So you could create an "Alias" www or root then point to Load Balancer.

#HTTPS SSL on AWS

@alex-zige
alex-zige / gist:5566238
Last active December 17, 2015 06:29
Rspec and Guard setup

enable test suit in Gemfile

group :test, :development do
  gem 'guard'
  gem 'guard-rspec'
  gem "rspec-rails"
  gem 'guard-zeus'
  gem "factory_girl_rails", "~> 4.0"
  gem 'mysql2'

Getting heroku db:pull to Work

$ rvm install 1.9.2
  • I had to do this business per the instructions I saw when I ran that command:
@alex-zige
alex-zige / gist:5442604
Created April 23, 2013 10:48
to switch ruby version & gemset & project dir & fire zeus and sublime
#!/bin/bash --login -fp alex

# IMPORTANT: Source RVM as a function into local environment.
#            Otherwise switching gemsets won't work.

if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

  source "$HOME/.rvm/scripts/rvm"
@alex-zige
alex-zige / gist:5432382
Created April 22, 2013 04:04
Git commands

#GIT

#reset the current head to origin status

git reset --hard origin master

#clean the repo & delete the untracked files

@alex-zige
alex-zige / gist:5428019
Last active December 16, 2015 11:29
tips for rails
try
  User.all.pluck(:email)
instead of
  User.select(:email).map(&:email)

overwrite default attributes

def owner=(ownder)
    self.previous_owner = owner
@alex-zige
alex-zige / gist:5400640
Last active December 16, 2015 07:39 — forked from dhh/gist:1014971
ruby on rails module standard include
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@alex-zige
alex-zige / gist:5381146
Created April 14, 2013 02:37
spec_header.rb with zeus and rspec.
require 'rubygems'
# require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
# Spork.prefork do
# # Loading more in this block will cause your tests to run faster. However,
# # if you change any configuration or code from libraries loaded here, you'll
# # need to restart spork for it take effect.
# # This file is copied to spec/ when you run 'rails generate rspec:install'