Skip to content

Instantly share code, notes, and snippets.

View kyanny's full-sized avatar

Kensuke Nagae kyanny

View GitHub Profile
@MichalPekala
MichalPekala / proxy.ru
Created September 27, 2012 12:24
Rack Proxy with HTTP Basic Authentication
require 'rubygems'
require 'rack/streaming_proxy'
use Rack::Auth::Basic, "Restricted Area" do |username, password|
[username, password] == ['user', 'password']
end
use Rack::StreamingProxy do |request|
if request.path.start_with?("/proxy")
"http://other.host#{request.path}"
@mala
mala / gist:5002784
Last active December 14, 2015 00:59
このLEMONってのがrapgeniusの人ね。
http://cache.gyazo.com/91f2e906a220fbeef2e9283b0aee597a.png
Unicorn使っても2workerで動いているところに遅いリクエストが3件来たら詰まるよ!!
根本的な解決にならない!!
とか言ってるんですよ。
じゃあ例えば、並列数1x10と並列数2x5で遅いリクエスト5件投げてキューに詰まる確率を考えてみよう。
絵で表すとこう。絵じゃなくて文字だけど。
@kenn
kenn / gist:5105175
Last active December 14, 2015 15:08
Unicorn memory usage improvement with Ruby 2.0.0

Unicorn memory usage improvement with Ruby 2.0.0

Here's a preliminary experiment to see how much memory is saved with the new copy-on-write friendly (bitmap marking) GC.

Calculated by memstats.rb https://gist.github.com/kenn/5105061 on Debian x86_64.

Master process:

# ./memstats.rb 20547
メモ
全体的なこと
- 想定してるRubyとかRailsのバージョンが古いので何とかしたい。
- 個人的に改造してる人がそれなりにいるので、その辺まとめたい。
- github/livedoor もあるんだけど、そこにadmin権限持ってるユーザー好き勝手追加は怖いので別で + コミュニティ主導でやりたい
- html/js/css も割と古くなってしまっているので、そのへんも何とかしたい。
----
オープンソースに拘るのは保険的な意味合いもあるのだけど、
サービス型のRSSリーダーで出来無いことがそれなりにあるというのが大きい。
= 桐島、((*Ruby*))やめるってよ
: author
nari/@nari3/authorNari
: institution
ネットワーク応用通信研究所
: content-source
#odrk03
: date
2013/3/16
# !!!!! まだ動きません!!!!! Fastladder 側で改修が必要 !!!!!
require 'user-stream-receiver'
require 'json'
require 'rest_client'
UserStreamReceiver.new.run{|chunk|
begin
chunk = JSON.parse(chunk)
@fujimura
fujimura / listen_spring.rb
Created March 28, 2013 05:00
listen_spring.rb
require 'listen'
def run(files_to_run)
puts "Running: #{files_to_run}"
system %|bundle exec spring rspec #{files_to_run}|
end
Listen.to 'spec', filter: /.*_spec\.rb/ do |modified, added, removed|
file_to_run = (modified || added).first
run file_to_run

Array#bsearch の前提について

arrayはソート済みである必要がある。ここで言う「ソート済み」とは、各要素に対してブロックを評価した場合に

[false, false, false, false, true, true]

みたいな感じになっている必要がある、という意味で、

[true, false, true, false, true]
@laiso
laiso / hoge.m
Created April 11, 2013 08:14
テストコード
{
id addressbook = [OCMockObject mockForClass:[RHAddressBook class]];
id person = [OCMockObject mockForClass:[RHPerson class]];
[[person expect] setFirstName:@"テスト"];// 実行順序 3
[[person expect] setLastName:@"ユーザー"];// 実行順序 4
[[person expect] save];// 実行順序 6
RHMutableMultiValue* emails = [[RHMutableMultiValue alloc] initWithType:kABMultiStringPropertyType];
[emails addValue:@"test@example.com" withLabel:(__bridge NSString*)kABWorkLabel];
module Element
alias_method :near_equal?, :===
def ===(other)
other.respond_to?(:include?) ? other.include?(self) : self.near_equal?(other)
end
end
[String, Symbol, Numeric].each do |elm|
elm.send(:include, Element)