Skip to content

Instantly share code, notes, and snippets.

@ilake
ilake / gist:3656567
Created September 6, 2012 14:01
Add X-CSRF-Token header for ajax call to pass csrf verfication
// reference : http://stackoverflow.com/questions/7203304/warning-cant-verify-csrf-token-authenticity-rails
// : http://stackoverflow.com/questions/8511695/rails-render-json-session-lost
$.ajax({ url: 'YOUR URL HERE',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
},
data: 'someData=' + someData,
success: function(response) {
@ilake
ilake / gist:2042942
Created March 15, 2012 08:33
metaprograming: define_method, define_singleton_method(1.9)
# base on ruby 1.9
# Reference :
# http://stackoverflow.com/questions/185947/ruby-define-method-vs-def
# define_method is a (private) method of the object Class. You are calling it from an instance. There is no instance method called define_method, so it recurses to your method_missing, this time with :define_method (the name of the missing method), and :screech (the sole argument you passed to define_method).
# http://stackoverflow.com/questions/752717/how-do-i-use-define-method-to-create-class-methods
class Base
def self.meta_instance_method &block
define_method "ins", block
end
git config --global user.name "ilake"
git config --global user.email "iamilake@gmail.com"
git config --global alias.co checkout
git config --global apply.whitespace nowarn
git commit -v
git commit -v -a
git branch -a
@ilake
ilake / gist:3658755
Created September 6, 2012 17:25
fileuploader-custom.js
/**
* http://github.com/Valums-File-Uploader/file-uploader
*
* Multiple file upload component with progress-bar, drag-and-drop.
*
* Have ideas for improving this JS for the general community?
* Submit your changes at: https://github.com/Valums-File-Uploader/file-uploader
*
* VERSION 2.0 beta
* Original version 1.0 © 2010 Andrew Valums ( andrew(at)valums.com )
@ilake
ilake / gist:3338917
Created August 13, 2012 09:56
[翻譯] 圖形計算機的故事
作者: iincho (..) 看板: Soft_Job
標題: [翻譯] 圖形計算機的故事
時間: Tue Mar 4 12:04:50 2008
Copyright (c) 2004 Ron Avitzur.
============================================================
本文譯自 http://www.pacifict.com/Story/
已獲得作者授權翻譯並同意於 PTT 發布
# config/initializers/devise.rb
# for web
config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
{ access_type: "offline",
prompt: "consent",
select_account: true,
provider_ignores_state: true,
scope: "plus.profile.emails.read,calendar,contacts" }
# for api
let result = await fetch({
api: "http://localhost:3000/users/auth/google_oauth2_for_api/callback",
method: 'get',
params: {
code: response.params.code,
redirect_uri: redirectUrl
}
})
// The result is from rails side.
let redirectUrl = Expo.AuthSession.getRedirectUrl();
let response = await Expo.AuthSession.startAsync({
authUrl:
`https://accounts.google.com/o/oauth2/v2/auth?` +
`&client_id=${GOOGLE_WEB_APP_ID}` +
`&redirect_uri=${encodeURIComponent(redirectUrl)}` +
`&response_type=code` +
`&access_type=offline` +
`&prompt=consent` +
`&scope=${encodeURIComponent('https://www.googleapis.com/auth/plus.profile.emails.read https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/contacts')}`,