Skip to content

Instantly share code, notes, and snippets.

@nguyenlocduy
nguyenlocduy / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# Matches patterns such as:
# https://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/#!/my_page_id => my_page_id
# http://www.facebook.com/pages/Paris-France/Vanity-Url/123456?v=app_555 => 123456
# http://www.facebook.com/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/#!/page_with_1_number => page_with_1_number
# http://www.facebook.com/bounce_page#!/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/bounce_page#!/my_page_id?v=app_166292090072334 => my_page_id
# http://www.facebook.com/my.page.is.great => my.page.is.great
// Check if an element has a class
var hasClass = function (elem, className) {
return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}
// Add a class to an element
var addClass = function (elem, className) {
if (!hasClass(elem, className)) {
elem.className += ' ' + className;
}
mkdir -p ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript
curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Syntaxes/CoffeeScript.tmLanguage
curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Preferences/CoffeeScript.tmPreferences
{
"name": "eschook",
"description": "eschook",
"version": "1.0.0-5",
"private": false,
"author": "Duy",
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
warn: Error returned from Nodejitsu
error: Error: Application crashed with the following output:
error:
error: events.js:72
error: throw er; // Unhandled 'error' event
error: ^
error: Error: EBADF, read
error:
require 'action_dispatch/middleware/static'
module Middleware
class FileHandler < ActionDispatch::FileHandler
def initialize(root, assets_path, cache_control)
@assets_path = assets_path.chomp('/') + '/'
super(root, cache_control)
end
def match?(path)
module Mongoid
class Criteria
def each_by(by, &block)
idx = 0
total = 0
set_limit = options[:limit]
while ((results = ordered_clone.limit(by).skip(idx)) && results.any?)
results.each do |result|
return self if set_limit and set_limit >= total
class InvitationsController < Devise::InvitationsController
# GET /resource/invitation/accept?invitation_token=abcdef
def edit
if params[:invitation_token] && self.resource = resource_class.to_adapter.find_first( :invitation_token => params[:invitation_token] )
session[:invitation_token] = params[:invitation_token]
render :edit
else
set_flash_message(:alert, :invitation_token_invalid)
redirect_to after_sign_out_path_for(resource_name)
@nguyenlocduy
nguyenlocduy / omniauth.rb
Last active December 16, 2015 01:08
How to integrate SHIFT API (https://shift.com) to your Rails App. You should read SHIFT API Docs to understand the flow before implementing this.
# config/omniauth.rb
# this is OPTIONAL if you want user to login not through SHIFT Website
# Register our provider with the OmniAuth Gem
module OmniAuth
module Strategies
# tell OmniAuth to load our strategy
autoload :Shift, 'shift_strategy'
end
end