Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
ascendbruce / gist:7071061
Created October 20, 2013 15:26
Ubuntu add an user to admin group using usermaod
usermod -a -G sudo USERNAME

or

usermod -a -G admin USERNAME

@ascendbruce
ascendbruce / gist:7071080
Created October 20, 2013 15:28
ruby 陽春模仿 1.year/month/day, Array#sum
# ruby Fixnum# year/month/day
class Fixnum
def minutes
self*60
end
def hours
self*60*60
end
def days
@ascendbruce
ascendbruce / gist:7071165
Created October 20, 2013 15:34
Indifferent access an array with string/symbol keys or convert all keys to symbol
## with_indifferent_access
1.9.2p290 :018 > h = {:a=>1, "b"=>2, :c=>3}
# => {:a=>1, "b"=>2, :c=>3}
1.9.2p290 :019 > h = h.with_indifferent_access
# => {"a"=>1, "b"=>2, "c"=>3}
1.9.2p290 :020 > h["b"]
# => 2
1.9.2p290 :021 > h[:b]
# => 2
@ascendbruce
ascendbruce / gist:7071173
Last active December 26, 2015 01:28
Temporarily Disable Executed SQL Command Output in Rails Console (Disable rails logger output)
ActiveRecord::Base.logger.level = Logger::INFO
# from http://lexsheehan.blogspot.tw/2013/04/temporarily-disable-executed-sql.html
@ascendbruce
ascendbruce / gist:7558475
Created November 20, 2013 06:03
用 request-log-analyzer 分析 rails 的 log

先安裝 request-log-analyzer gem,建議把 log 檔抓到自己電腦來做分析。

gem i request-log-analyzer

分析某一個 log 檔

request-log-analyzer log/production.log --output HTML --file tmp/log_report.html

指定多個 log 檔

# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential git-core curl libssl-dev \
libreadline5 \
zlib1g zlib1g-dev \
libmysqlclient-dev \
libcurl4-openssl-dev \
libxslt-dev libxml2-dev
@ascendbruce
ascendbruce / 0_reuse_code.js
Created January 2, 2014 03:27
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
@ascendbruce
ascendbruce / gist:10584882
Created April 13, 2014 13:46
KKBOX 授權擁有的動漫卡通音樂 集中帖 第一頁 (markdown)

整理自 KKBOX 討論區的「KKBOX 授權擁有的動漫卡通音樂 集中帖」的第一頁(討論串樓主整理的)

需注意後面零星的歌單並沒有整理到這裡

這個 gist 是整理到 ACG Music (Taiwan) 前整理用 temp。

「鋼之鍊金術師」

《劇場版 主題曲》Link-L'Arc-en-Ciel(彩虹樂團)

@ascendbruce
ascendbruce / unicode_spaces.rb
Created May 7, 2014 06:06
Unicode special space characters as ruby method name
# encoding: utf-8
# inspired by http://jsbin.com/nuhinuda/1/edit
def  
"U+2004 THREE-PER-EM SPACE"
end
def  
"U+2005 FOUR-PER-EM SPACE"
#!/usr/bin/env ruby -w
require 'csv'
# 1. Create a class with same initialization arguments as BIGMETHOD
# 2. Copy & Paste the method's body in the new class, with no arguments
# 3. Replace original method with a call to the new class
# 4. Apply "Intention Revealing Method" to the new class. Woot!
class FormatterNew
def initialize(file_name)