Skip to content

Instantly share code, notes, and snippets.

View raviwu's full-sized avatar

Ravi Wu raviwu

  • Taiwan
View GitHub Profile
@raviwu
raviwu / iTerm_2_notes.md
Last active March 27, 2016 04:46
shortcuts for iTerm 2

Shortcut of iTerms2

windows and tabs

  • command + T to open new tab
  • shift + command + [ / ] to switch between tabs
  • command + W to close the tab
  • command + D to have vertical divided windows
  • command + [ / ] to switch between windows
@raviwu
raviwu / command_line_notes.md
Last active April 3, 2016 03:49
notes for command line tools

Basic tools

See Usage of specific command: man

man command checks out the manual for the command, for instance use man echo to see the description of the echo command.

Commen quit from mass or manufal windows

Use q to quit the manual mode, normally q works for the similar mode entered by other command like ri Array.

@raviwu
raviwu / basic_git_command.md
Last active April 25, 2017 20:59
Basic Git Commands

git init

git add . add current directory to stage

git add -A add all untrack directories and files to stage

git commit commit staged files

git checkout -b new-branch-name create new branch and checkout to new branch

@raviwu
raviwu / jwt_in_rails_1_model_setup.rb
Last active June 10, 2016 02:28
Integrate JWT into Rails Grape API for Multi-Login
# Prepare the schema for the additional session records.
# XXXXXXXXXXXXXXXX_create_user_session.rb
class CreateUserSessions < ActiveRecord::Migration
def change
create_table :user_sessions do |t|
t.references :user, :foreign_key => true, :index => true, :null => false
t.text :user_agent
t.datetime :expire_at # use expire_at to control the expiration after issuing JWT
t.timestamps null: false
@raviwu
raviwu / amazon_sns_wrapper.rb
Last active June 24, 2016 15:30
AmazonSnsWrapper Setup
# In Gemfile
# Include AWS SDK V1 for paperclip if your paperclip version is less than 5.0
gem 'aws-sdk-v1'
# Need to AWS V2 SDK for SNS methods, gem 'aws-sdk', '~>1.6' doesn't have Aws::SNS methods
gem 'aws-sdk', '~> 2.0'
######################################################
@raviwu
raviwu / amazon_sns_info.rb
Last active June 24, 2016 10:06
AmazonSnsInfo Model Setup
# In db/migrate/XXXXXXX_create_amazon_sns_infos.rb
class CreateAmazonSnsInfos < ActiveRecord::Migration
def change
create_table :amazon_sns_infos do |t|
t.references :user, :foreign_key => true, :index => true, :null => false
t.string :platform
t.string :device_token
t.string :endpoint_arn
t.string :platform_application_arn
@raviwu
raviwu / parse_installation_wrapper.rb
Last active June 24, 2016 10:04
ParseInstallationWrapper Setup
# In app/services/parse_installation_wrapper.rb
class ParseInstallationWrapper
def self.check_and_unregister(options = {})
# provide no params will clear out the Parse installation with no device_token
object_ids = get_push_registered_installation_object_ids(options)
delete_push_installations(object_ids)
end
private
# In your api call endpoint for update_push_subscription
# I use Grape, but the logic is similar in RailsAPI
resource :update_push_subscription do
desc "Update the user mobil push notification registration on Amazon SNS"
params do
requires :push_platform, type: String, desc: "Push Service Platform", values: %w(apns gcm)
requires :device_token, type: String, desc: "Device Token for Mobile Push Notification"
end
post do
@raviwu
raviwu / push_services_wrapper.rb
Created June 24, 2016 10:19
PushServicesWrapper
# In app/services/push_services_wrapper.rb
require 'json/ext'
class PushServicesWrapper
attr_reader :message, :to_email, :channels, :badge, :from_id, :push_time, :addition, :push_uri, :to_id
def initialize(options = {})
@message = options[:message]
@to_email = options[:to_email].kind_of?(Array) ? options[:to_email] : [options[:to_email]]
@raviwu
raviwu / google_sheets_api_1_setup.rb
Created July 9, 2016 01:58
Use Google Sheets API and Service Account to import Data to Rails APP
# Gemfile
gem 'google-api-client'
gem 'googleauth'