Skip to content

Instantly share code, notes, and snippets.

@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)
@ascendbruce
ascendbruce / gist:c4a823b3202d7ed6f80e
Created June 14, 2014 12:17
Terminal & mac say stopwatch for interval training
class Notifier
def initialize(voice)
@voice
end
def sprint
say "sprint"
puts %(
###### ######## ######## #### ## ## ########
## ## ## ## ## ## ## ### ## ##
@ascendbruce
ascendbruce / duplication.rb
Created June 29, 2014 13:03
code club #4 候選題目
module Timer
def times(env)
value_s = env['interval']
if value_s == nil
raise "interval missing"
end
value = Integer(value_s)
if value <= 0
raise "interval should be > 0"
@ascendbruce
ascendbruce / regex_gsub.rb
Created July 15, 2014 06:03
gsub regex replace part
content = "這是標題之前<h1>這是標題</h1>這是標題之後"
content.gsub(/\<h1(.*)\<\/h1\>/, '<h2\1</h2>')
=> "這是標題之前<h2>這是標題</h2>這是標題之後"
# 重點在於 match 時的 () 包起來的東西變成 \1 (但必須用單引號 '' 才有效)
# source: http://jokercatz.blogspot.tw/2013/09/rails-get-all-models.html
#first load all models
Rails.application.eager_load!
#okay…each now :)
ActiveRecord::Base.send(:subclasses).each do |model|
puts model.name
end
require 'benchmark'
require "active_support/core_ext/object/blank"
TIMES = 1000000
Benchmark.bmbm do |x|
x.report("if present? (actually present)") do
TIMES.times do
if "1".present?
@ascendbruce
ascendbruce / .pryrc
Last active August 29, 2015 14:10
rails console customization without modifying Gemfiles
# encoding: utf-8
# work-around from http://stackoverflow.com/a/15017892
required_version_gems = %w(
awesome_print-1.2.0
hirb-0.7.2
hirb-unicode-0.0.5
unicode-display_width-0.1.1
)
required_version_gems.each do |version_gem|
@ascendbruce
ascendbruce / gist:7009252
Created October 16, 2013 15:10
Ruby File open read/write examples
File.open("/usr/local/widgets/data").each do |line|
    puts line if line =~ /blue/
end



logfile = File.new("/tmp/log", "w")

logfile.close