Skip to content

Instantly share code, notes, and snippets.

View ryo33's full-sized avatar

Ryo Hirayama ryo33

View GitHub Profile
Section "InputClass"
Identifier "Ryo33 HHKB"
MatchProduct "Topre Corporation HHKB Professional"
Option "XkbModel" "pc104"
Option "XkbLayout" "us"
EndSection
@ryo33
ryo33 / loop.ex
Created August 5, 2017 17:01
Spawn a new process with registering to a registry and receive messages continuously in Elixir
def register_handler(register_func, hander_func) do
spawn_link fn ->
register_func.()
for :ok <- Stream.cycle([:ok]) do
receive do
message -> handler_func.(message)
end
end
end
end
@ryo33
ryo33 / share-api.md
Last active May 11, 2017 13:28
sha.herokuapp.com API
@ryo33
ryo33 / ja.md
Last active June 4, 2018 06:56
ReduxでMiddlewareを使ってサクッと解決する

はじめに

これはredux-middlewaresの紹介です。

Middlewareについて

Middlewareがどのようなものかついては、非常に分かりやすい記事があるのでそれを貼っておきます。
http://qiita.com/kuy/items/57c6007f3b8a9b267a8e
僕がMiddlewareを活用するようになったのは、この記事を読んでからです。

@ryo33
ryo33 / 1.md
Last active January 4, 2017 00:14
redux-thunk and redux-middlewares

gaearon/redux-thunk

These examples are not completely compatible about whether to call next(action).

incrementAsync

redux-thunk

function incrementAsync() {
import { create as createJsondiffpatch } from 'jsondiffpatch'
import clone from 'clone'
const jsondiffpatch = createJsondiffpatch({})
function reducer(state = {}, action) {
switch (action.type) {
case 'INITIAL_STATE':
const initialState = action.payload
return initialState

Listen History API

Create a token

PUT /api/users/USER_ID

Headers

Content-Type: application/json
@ryo33
ryo33 / saga-relay.js
Last active October 18, 2016 12:35
function* relay(request, relayChannel, nextChannel) {
const result = yield call(request)
yield put(relayChannel, [result, nextChannel])
}
function* runSequencially(requestChannel, resultChannel) {
let head = channel()
let tail = head
while (true) {
const { request, relayResult } = yield race({
function* before() {
yield fork(function*() {
yield* takeEvery('FETCH_USERS', fetchUsers)
})
yield fork(function*() {
yield* takeEvery('CREATE_USER', createUser)
})
}
function* after() {
yield fork(takeEvery, 'FETCH_USERS', fetchUsers)
@ryo33
ryo33 / file0.js
Created August 26, 2016 12:09
Reactで描画回数を制限する(ためのHOCを作った) ref: http://qiita.com/ryo33/items/1c70fd0fb8af2169d159
import throttle from 'react-throttle-render';
const wrappedComponent = throttle(component, 50);