Skip to content

Instantly share code, notes, and snippets.

View taiki45's full-sized avatar

Taiki Ono taiki45

View GitHub Profile
@taiki45
taiki45 / ParserCombinator.hs
Last active June 27, 2022 14:14
http://d.hatena.ne.jp/tanakh/20040731 を読んでパーサを Applicative instance にしてみた
module ParserCombinator
( Parser
, parse
, satisfy
, char
, digit
, natural
, token
, oneOf
, listOf
@taiki45
taiki45 / play_with_ruby.rb
Created November 9, 2012 13:40
fun! ruby!
fact = lambda {
|pr, x| x * pr.((x - 1), pr)
}.curry.(lambda {|x, pr| x <= 0 ? 1 : x * pr.((x - 1), pr) })
a = Class.new.instance_exec(fact) do |fact|
define_method(:fact, fact)
self
end.new
p a.fact 5
@taiki45
taiki45 / envoy-hot-restart-version-format.md
Last active December 20, 2018 07:10
Current (around v1.8.0) format of Envoy's hot restart version output
10.200.16384.127.options=capacity=16384, num_slots=8209 hash=228984379728933363 size=2654312
${version}.${size_of_shared_memory}.${max_num_stats}.${max_name_length}.options=${options} hash=${hash_signature}, size=${hash_table_size?}
  • version: SharedMemory::VERSION which Envoy developers bump when breaking changes of shared memory/RPC were happened.
  • size_of_shared_memory: sizeof(SharedMemory)
# A sample Gemfile
source 'https://rubygems.org'
gem 'zipkin-tracer', path: '~/.ghq/github.com/twitter/zipkin/zipkin-gems/zipkin-tracer'
gem 'sinatra'
gem 'thin'
gem 'faraday'
gem 'pry'
gem 'faraday-zipkin', github: 'taiki45/faraday-zipkin', branch: 'zipkin-tracer-compatible'
diff --git a/lib/airbrake/rails/active_job.rb b/lib/airbrake/rails/active_job.rb
index d732093..330ebbc 100644
--- a/lib/airbrake/rails/active_job.rb
+++ b/lib/airbrake/rails/active_job.rb
@@ -16,7 +16,7 @@ module Airbrake
notice[:context][:component] = 'active_job'
notice[:context][:action] = self.class.name
- notice[:params] = serialize
+ notice[:params] = as_json
@taiki45
taiki45 / maybe_monad.hs
Last active December 29, 2015 01:39
How monads work for OOProgrammers. Monad in object-oriented-language is useless unless for leaning.
import Control.Monad
bind :: (Monad m, Functor m) => m a -> (a -> m b) -> m b
bind m f = join (fmap f m)
unit :: Monad m => a -> m a
unit = return
compose :: (b -> c) -> (a -> b) -> (a -> c)
compose = (.)
@taiki45
taiki45 / intall-rubinius-2.0.0-dev.md
Last active December 24, 2015 15:29
Install Rubinius 2.0.0-dev with rbenv

Install Rubinius 2.0.0-dev with rbenv

Install rubinius

  • Install rbenv with ruby-build.

  • Install Ruby 2.x and enable it by rbenv global.

  • Install bundler gem then rbenv-rehash.

In [1]: class ListA(object):
...: def __init__(self, x, y):
...: self.x = x
...: self.y = y
...: def sum(self):
...: return self.x + self.y
...:
In [2]: a = ListA(4, 5)
@taiki45
taiki45 / rpn_calculator.hs
Last active December 20, 2015 14:58
Haskell 練習: 逆ポーランド記法電卓の実装 一桁の数字のみ…
import Data.Char
type Stack = [Int]
type Machine = (String, Stack)
solve :: String -> Int
solve exprs = pick $ readExprs $ initMachine exprs where
pick (_, [num]) = num
initMachine = flip (,) []
@taiki45
taiki45 / lambda_and_closure.md
Last active December 20, 2015 02:38
λ式とクロージャ 〜手続きと環境のハーモニーを探して〜

λ式とクロージャ

手続きと閉包

前提

ここでは手続きまたは関数ともに純粋なものを扱う。

  • 関数は渡される引数が同じであれば常に同じ値を返す
  • 関数は変動する外部の変数を参照しない
  • 関数には副作用がない