Skip to content

Instantly share code, notes, and snippets.

View shuhei's full-sized avatar
🐢
...

Shuhei Kagawa shuhei

🐢
...
View GitHub Profile
@shuhei
shuhei / epic.js
Last active August 5, 2016 02:59
An idea of side-effect-free epic like redux-saga for redux-observable
// Explicit in-out of side-effect actions.
function epic(action$, store) {
const fooReq$ = action$.ofType('FOO')
.map(action => call('FOO_REQ', webapi.getFoo, action.payload.id));
const foo$ = action$.ofType('FOO_REQ')
.map(foo => ({ type: 'FOO_FETCHED', payload: { foo } }));
return Observable.merge(
fooReq$,
foo$
@shuhei
shuhei / compile_test.js
Created May 12, 2016 17:32
Angular 2 Offline Compile
// https://github.com/angular/angular/blob/master/modules/%40angular/compiler/test/offline_compiler_util.ts
// https://github.com/angular/angular/blob/master/modules/%40angular/compiler/test/offline_compiler_codegen_untyped.ts
/* eslint-env node */
import {OutputEmitter} from '@angular/compiler/src/output/abstract_emitter';
import {createOfflineCompileUrlResolver} from '@angular/compiler/src/url_resolver';
// import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
import {JavaScriptEmitter} from './js_emitter';
@shuhei
shuhei / couple.rb
Created May 9, 2016 16:23
愛を生む二人を探して
# Extract meaningful bits.
# https://en.wikipedia.org/wiki/UTF-8#Description
def code_bits(bits)
bits.each_slice(8).with_index.map do |byte, i|
i == 0 ? byte[4..-1] : byte[2..-1]
end.flatten
end
# Returns unicode charactor from bits.
def bits_to_char(bits)
require 'jbuilder'
ActiveSupport.on_load :action_view do
ActionView::Template.unregister_template_handler :jbuilder
ActionView::Template.register_template_handler :jbuilder, JbuilderInlinePartials::Handler
end
@shuhei
shuhei / README.md
Last active April 17, 2016 14:44
Faster partial rendering with Jbuilder

Before:

Running 10s test @ http://localhost:3000/tests/to_json.json
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    73.59ms    9.26ms 125.82ms   79.41%
    Req/Sec    13.19      4.94    20.00     60.42%
  136 requests in 10.06s, 29.14MB read
Requests/sec:     13.52
@shuhei
shuhei / SassMeister-input.scss
Created February 23, 2016 14:26
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
.my-awesome-block {
padding: 20px;
&__element-1 {
> p {
font-size: 16px;
@shuhei
shuhei / README.md
Last active November 25, 2015 07:43
Angular 2's property decorators don't work with Babel 5.x.

The _defineDecoratorPropertyDescriptor calls that Babel 5.x generates mess up @Input decorators somehow.

function Linker() {
  _classCallCheck(this, _Linker);

  _defineDecoratedPropertyDescriptor(this, 'name', _instanceInitializers);

  _defineDecoratedPropertyDescriptor(this, 'url', _instanceInitializers);
}
@shuhei
shuhei / buffer.js
Last active October 9, 2015 02:45
Buffer#toString on Node 0.12.7
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite();
suite.add('Buffer#toString 1MB', function () {
new Buffer(1000 * 1000).toString();
})
.add('Buffer#toString 100KB', function () {
new Buffer(100 * 1000).toString();
})
.on('cycle', function (event) {
@shuhei
shuhei / app.js
Created September 12, 2015 03:12
Angular 2 alpha.36 with ES5
var Hello = ng
.Component({
selector: 'hello'
})
.View({
template: '<p>Hello, {{ name }}!</p>'
})
.Class({
constructor: function () {
this.name = 'angular';
@shuhei
shuhei / app.js
Created September 1, 2015 07:55
angular2 alpha.35 router example
import { bind } from 'angular2/di';
import { Component, View, bootstrap } from 'angular2/angular2';
import { Route, Router, RouteConfig, RouteParams, LocationStrategy, HashLocationStrategy, routerInjectables, routerDirectives } from 'angular2/router';
@Component({
selector: 'hello'
})
@View({
template: `<p>Hello, {{ name }}!</p>`
})