Skip to content

Instantly share code, notes, and snippets.

View godfat's full-sized avatar

Lin Jen-Shin (godfat) godfat

View GitHub Profile
task :test do
sh 'ruby another.rb' # at_exit in another.rb didn't run or $stdout is broken or redirected?
# actuall: sh 'cd api; ruby -S rake test'
end
module SkipVerification
def verify_mode
OpenSSL::SSL::VERIFY_NONE
end
end
HTTPClient::SSLConfig.prepend(SkipVerification)
@godfat
godfat / draft.md
Last active August 29, 2015 14:10
The Promise of rest-core

rest-core 的承諾

在 [RubyConf.TW 2011][],我介紹了 [rest-core][],是用 Ruby 寫成的模組化 REST client 組合包與工具組。後來組合包的東西被抽至 [rest-more][],於是變成給 REST APIs 使用的模組化 Ruby clients interface。

在 [RubyConf.TW 2012][],我介紹了 Ruby 上的 concurrent 應用程式伺服器。之後在 rest-core 內,加入我從以上所學到的東西,使它能輕易地發出 concurrent requests。

在不同的使用情況下,我們有時候需要使用 promise、有時候需要使用 callback。這次我將介紹該怎麼利用 promise 來達成以我們所熟習的同步風格,發出

@godfat
godfat / install-rbx.sh
Last active August 29, 2015 14:10
rubinius on mac
sudo mv /usr/include/c++ /usr/include/c++.bak # avoid conflicting, might not be needed
brew install --HEAD ruby-install
brew tap homebrew/versions
brew install llvm35 --with-libcxx --with-clang --with-lld --all-targets --rtti
env CC=clang-3.5 CXX=clang++-3.5 CXXFLAGS=-stdlib=libc++ LDFLAGS='-L/usr/local/lib/llvm-3.5/usr/lib -lc++' ruby-install rbx -- --llvm-config llvm-config-3.5
sudo mv /usr/include/c++.bak /usr/include/c++ # restore g++ headers
04:17 ~/p/g/muack adopt-pork-1.0.0> mutant -Ilib -rmuack --use pork Muack
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[<Mutant::Expression: Muack>] subject_ignores=[] subject_selects=[]>
Integration: pork
Expect Coverage: 100.00%
Jobs: 8
Includes: ["lib"]
Requires: ["muack"]
..............................................................F.......................FFMuack.reset:/Users/godfat/project/godfat/muack/lib/muack.rb:16
- pork:Muack::IsAsatisfy
00:02 ~/p/g/muack *master> mutant -Ilib -rmuack --use pork Muack
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[<Mutant::Expression: Muack>] subject_ignores=[] subject_selects=[]>
Integration: pork
Expect Coverage: 100.00%
Jobs: 8
Includes: ["lib"]
Requires: ["muack"]
F.................................................F.......F...................Muack.reset:/Users/godfat/project/godfat/muack/lib/muack.rb:16
- pork:Muack
# slow as hell:
require 'rubygems/gem_runner'
Gem::GemRunner.new.run(['install', gem_path])
# fast!
require 'rubygems/commands/install_command'
# read ~/.gemrc
Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
Gem::Command.extra_args = Gem.configuration[:gem]
In reply to: https://twitter.com/plataformatec/status/525670283899072513
Hi,
This would probably be a long story, and I am not going to go
through all the details here. You're doing well in what
could be done, but in general, I oppose to build a user system
on top of some generic framework. The reason is that a user
system could be very specific to business logic, and it
could be very hard to customize devise in a way that works
def f a={}, **b
[a, b]
end
# huh?
f({:a => 0}) # => [{}, {:a => 0}]
# as expected
f(0) # => [0, {}]
Tags = %w[ruby haskell c++ scala java c# js php agda idris julia ocaml]
module BestMatch
module_function
def distance_tags a, b
sum(a & b) / sum(a)
end
def sum tags