Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# require 'rubygems'
require 'mechanize'
require 'debugger'
require 'sidekiq'
# Sidekiq server is multi-threaded so our Redis connection pool size defaults to concurrency (-c)
Sidekiq.configure_server do |config|
config.redis = { :namespace => 'treehouse', :url => 'redis://127.0.0.1:6379' }
end
# Set the prefix to ^A.
unbind C-b
set -g prefix ^a
set -g base-index 1
# other ^A
unbind ^A
bind ^A last-window
@ilake
ilake / pricne.rb
Last active August 29, 2015 14:01
princely study
# lib/princely/asset_support.rb
# Rails.application.assets.find_asset is useful to find asset.
# you could get the content through
# Rails.application.assets.find_asset('analytics.css.sass').body
# get pathname through
# Rails.application.assets.find_asset('analytics.css.sass').pathname
def asset_file_path(asset)
# Remove /assets/ from generated names and try and find a matching asset
Rails.application.assets.find_asset(asset.gsub(%r{/assets/}, "")).try(:pathname) || asset
end
@ilake
ilake / tips_for_asset_pipeline.md
Last active August 29, 2015 14:01
12 Tips for the Rails Asset Pipeline

http://www.reinteractive.net/posts/116-12-tips-for-the-rails-asset-pipeline

The asset pipeline is not quite your assets folder

  • Every file that is not a Javascript file or CSS file that is in the app/assets folder will be copied by Rails into the public/assets folder when you compile your assets.

Don't fall back in staging or production

  • config.assets.compile
  • If it is set to "true" (which it is by default in development) then Rails will try to find a Javascript or CSS file by first looking in the public/assets directory and if it can't find it, will hunt through your app/assets folder looking for the file. If it finds it in app/assets it will go ahead and compile on the fly and then serve this asset up.

Mature engineers have an innate sense of anticipation, even if they don’t know they do.

how long will it last before it’s rewritten? Once it’s in production, how will its execution affect resource usage? How much so I expect CPU/memory/disk/network to increase or decrease? Will others be able to understand this code? Am I making it as easy as I can for others to extend or introspect this work?

# app/views/layouts/application.html.erb
<%= render_stylesheets content_for(:stylesheets) %>
# app/helpers/layout_helper.rb
def render_stylesheets(tag_html = nil)
html = []
if tag_html.present?
html << tag_html
else
# http://ruby.learncodethehardway.org/book/ex12.html
#http://stackoverflow.com/questions/318144/what-is-the-difference-between-include-and-require-in-ruby
- load, could use when file change, reload the file
- require, run the file, and track what will require
- inlcude, take method from module to another place.
- $LOAD_PATH, $: the load paths.
# http://ruby.learncodethehardway.org/book/ex13.html
- $0 the name of the ruby program being run

Database view

  1. 何時用?
  • 常用的query, subquery, 目的可以讓application layer 更清楚看這東西
  1. 特性:虛擬表格, 沒有真的存資料, view 的建立來源也可以從view 來 , 把它當作 named subquery, view 是just-in-time 是即時的。