Skip to content

Instantly share code, notes, and snippets.

@googya
googya / gist:759338
Created December 30, 2010 01:41 — forked from xdite/gist:758319

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@googya
googya / class_module.rb
Created August 21, 2011 02:20 — forked from sergeyenin/class_module.rb
ClassModule
module ClassModule
#all successors excluding self
def successors(klass=self.name.to_s)
descendants = []
begin
ObjectSpace.each_object(class << eval(klass);self;end) do |found|
descendants << found
end
rescue Exception=>e
@googya
googya / irb3.rb
Created January 29, 2012 09:47 — forked from peterc/irb3.rb
irb3 - Run an IRB-esque prompt over multiple Ruby implementations at once using RVM
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using RVM)
#
# By Peter Cooper, BSD licensed
#
# Main dependency is term-ansicolor for each impl:
# rvm exec gem install term-ansicolor
@googya
googya / deploy.rb
Created November 22, 2012 09:34 — forked from bkutil/deploy.rb
Start and Stop tasks for resque workers and resque scheduler with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
after "deploy:restart_workers", "deploy:restart_scheduler"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
@googya
googya / gist:bc69a5b47f13d24cac076d81e034ed98
Created April 9, 2016 05:25 — forked from tamoyal/gist:10441108
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile

(my response to https://twitter.com/apotonick/status/717105889845624832)

I haven't yet came across readily available resources for large-scale application architecture for Elixir apps. I found Programming Phoenix to be a good start for that though. And there's ~30 years of knowledge in the Erlang land :)

For web apps, I found the abstractions that Elixir/Phoenix provides to be really helpful. Indeed, the list below is somewhat ORM focused.

In the small, Ecto.Schema, Ecto.Query, Ecto.Changeset, and Phoenix.View allow me to build highly composable and side-effect free modules. I can have many schemas, changesets and queries all interacting with the same underlying DB table(s) if I want to. Most of the side-effects (through Ecto.Repo for DBs) are usually in the Phoenix.Controller (or other Plugs).

@googya
googya / ml-ruby.md
Created May 5, 2016 09:46 — forked from gbuesing/ml-ruby.md
Resources for Machine Learning in Ruby

Resources for Machine Learning in Ruby

Gems

@googya
googya / setEnv.sh
Created September 21, 2016 01:34
Enable or disable ENV variables.
#!/bin/bash
# . script.sh # identical to "source script.sh"
if [ $# -eq 0 ]
then
echo "No arguments supplied"
fi
if [ $# -eq 1 ]
then
if [[ "$1" = "--set" ]]
@googya
googya / latency.markdown
Created October 9, 2016 03:07 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs