Skip to content

Instantly share code, notes, and snippets.

View speed-of-light's full-sized avatar

Speed of Light speed-of-light

View GitHub Profile
@speed-of-light
speed-of-light / gcst :: git clone specific tag
Last active December 21, 2015 10:08 — forked from fajrif/gist:1265203
shell string manipulation
function gcst(){
# $1: repo path
# $2: tag-name
git clone $1
cd ${$1%%.*}
git tag -l
git checkout $2
git branch -D master
git checkout -b master

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@speed-of-light
speed-of-light / ability.rb
Last active December 23, 2015 02:39 — forked from vmarcetic/ability.rb
cancan ability
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # This is used for not logged user if you have a need for it
if User.current_role == 'admin' # From ApplicationController we can get current_role and check it up against the role we want.
can :manage, :all
else
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:

Github 發 Pull Request & 貢獻流程速查

前言

此文目標讀者需先自行學會

  • 開 Github 帳號
  • 會 fork 程式 repository
  • 會在自己的電腦使用命令列 git
  • 會 clone 自己的 repository
@speed-of-light
speed-of-light / session.rb
Last active December 30, 2015 08:49 — forked from marcomd/gist:3129118
rails session controller for angular js
#Session controller provides a token
#/controllers/api/sessions_controller.rb
class Api::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :except => [:create]
before_filter :ensure_params_exist, :except => [:destroy]
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user_login][:email])
return invalid_login_attempt unless resource
@speed-of-light
speed-of-light / all-templates.html
Created December 5, 2013 14:06 — forked from vojtajina/all-templates.html
angularjs templates
<script type="text/ng-template" id="one.html">
<div>This is first template</div>
</script>
<script type="text/ng-template" id="two.html">
<div>This is second template</div>
</script>
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
@speed-of-light
speed-of-light / sidekiq.rb
Created January 22, 2014 18:07 — forked from hayeah/sidekiq.rb
sidekiq runners
# adapted from bin/sidekiq
# to invoke, run: zeus runner sidekiq.rb
require 'sidekiq/cli'
begin
cli = Sidekiq::CLI.instance
cli.parse
cli.run
rescue => e