Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Yutaka Matsubara mopemope

🏠
Working from home
View GitHub Profile
View main.pony
use "net/http"
actor Main
new create(env: Env) =>
let service = try env.args(1) else "50000" end
let limit = try env.args(2).u64() else 100 end
Server(Info(env), Handle, CommonLog(env.out) where service = service,
limit = limit)
@mopemope
mopemope / lfe.md
Created May 21, 2015
LFE入門の進捗
View lfe.md

LFE 入門

近年、ネットワークアプリケーションを書くにあたり Erlang/OTP に対する注目が集まっています。 大規模サービスで使わているなどの事例が多く紹介されるようになり、導入を考えている方も多いでしょう。 ですが、Erlang は少々癖があり、難しく感じる方も少なくありません。 今回はそのような人向けに LFE を紹介しようと思います。

LFE とは

LFE とは (lisp (flavored (erlang))) の略です。その名の通り、 Erlang Virtual Machine (BEAM) 上で動く Lisp です。

View ppool-nagger.lfe
(defmodule ppool-nagger
(export all)
(behavior gen_server))
(defun start-link (task delay max send-to)
(gen_server:start_link (MODULE) `#(,task ,delay ,max ,send-to) '()))
(defun start_link (task delay max send-to)
(start-link task delay max send-to))
View band-supervisor.lfe
(defmodule band-supervisor
(export all)
(behavior 'supervisor))
(defun start-link (type)
(supervisor:start_link `#(local ,(MODULE)) (MODULE) type))
(defun start_link (type)
(start-link type))
View curling-accumulator.lfe
(defmodule curling-accumulator
(export all)
(behavior 'gen_event))
(defrecord state
(teams (orddict:new))
(round 0))
(defun init
(('()) `#(ok ,(make-state))))
View trade-call.lfe
(defmodule trade-call
(export all))
(defun sync1 (pid)
(! pid (self))
(receive
('ack 'ok)))
(defun sync2 ()
(receive
View kitty-gen-server.lfe
(defmodule kitty-gen-server
(export all)
(behavior 'gen_server))
(defrecord cat
name
(color 'green)
description)
(defun start-link ()
View kitty-server2.lfe
(defmodule kitty-server2
(export all))
(defrecord cat
name
(color 'green)
description)
(defun start-link ()
(my-server:start-link (MODULE) ()))
@mopemope
mopemope / kitty-server.lfe
Created Apr 14, 2015
simple kitty-server
View kitty-server.lfe
(defmodule kitty-server
(export all))
(defrecord cat
name
(color 'green)
description)
;; Client API
(defun start-link ()
View gist:9d8c1729c393e58e8ac6
💀 arch-xps λ sudo ./bin/rkt --debug run https://github.com/coreos/etcd/releases/download/v0.5.0-alpha.4/etcd-v0.5.0-alpha.4-linux-amd64.aci (git)-[master][~/go/.../coreos/rocket]
2014/12/04 10:52:27 Unpacking stage1 rootfs
2014/12/04 10:52:28 Writing stage1 init
2014/12/04 10:52:28 Wrote filesystem to /var/lib/rkt/containers/2cf348cd-42a8-4961-8094-effa76e002f9
2014/12/04 10:52:28 Loading image sha256-f9215c18b86f406c7cec4c7b45fd8752b5bfd1a492507d647821c2ce593fbf31
2014/12/04 10:52:28 Writing container manifest
2014/12/04 10:52:28 Pivoting to filesystem /var/lib/rkt/containers/2cf348cd-42a8-4961-8094-effa76e002f9
2014/12/04 10:52:28 Execing stage1/init
Spawning container stage1 on /var/lib/rkt/containers/2cf348cd-42a8-4961-8094-effa76e002f9/stage1.
Press ^] three times within 1s to kill container.
You can’t perform that action at this time.