Skip to content

Instantly share code, notes, and snippets.

@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 / equipment.md
Last active June 7, 2023 01:28
軟體工程師裝備建議

最後編輯 2020-11-01

列舉的種類基本上是生產力、健康相關,或是好用的工程師潮流精品(?)

這些是我偏好或想要的裝備,歡迎留言提供其他推薦裝備、發問為何要用或不用某個裝備、品牌。

免費的工具軟體雖然也很重要,但不在這邊討論,有興趣請查看 我的 Mac 環境設定

電腦周邊設備

@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|
# Available cops (199) + config for /Users/bruce/Projects/rails:
# Type 'Lint' (36):
Lint/AmbiguousOperator:
Description: Checks for ambiguous operators in the first argument of a method invocation
without parentheses.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-as-args
Enabled: false
Lint/AmbiguousRegexpLiteral:
Description: Checks for ambiguous regexp literals in the first argument of a method
@ascendbruce
ascendbruce / gist:ed51360753edf7ce1fd8
Last active February 6, 2016 10:57
Fetch facebook graph object scrape information clear cache in command line
curl -X POST -F "id={the url}" -F "scrape=true" "https://graph.facebook.com"
# from http://stackoverflow.com/questions/12100574/is-there-an-api-to-force-facebook-to-scrape-a-page-again
@ascendbruce
ascendbruce / trello-cards-count-bookmarklet.js
Last active February 27, 2016 06:34
Show cards count bookmarklet for Trello
javascript: ! function() {
$(".js-num-cards").each(function(i) {
var size = $(".js-list:nth(" + i + ") .list-card-details").length;
$(".js-num-cards:nth(" + i + ")").text(size + " cards");
});
$(".js-num-cards").toggleClass('hide');
if ($(".board-header-btn-name .js-list-card-count").length === 0) {
$(".board-header-btn-name span").append(" <span class=\"js-list-card-count\"></span>");