Skip to content

Instantly share code, notes, and snippets.

View cades's full-sized avatar

hong-jen kao cades

View GitHub Profile

1. Separation of immutable and mutable logic

Quite a lot of different people have been on the same trail of thought. Gary Bernhardt's formulation of a "functional core, imperative shell" seems to be the most voiced.

"Boundaries" - Gary Bernhardt

"Imperative shell" that wraps and uses your "functional core".. The result of this is that the shell has fewer paths, but more dependencies. The core contains no dependencies, but encapsulates the different logic paths. So we’re encapsulating dependencies on one side, and business logic on the other side. Or put another way, the way to figure out the separation is by doing as much as you can without mutation, and then encapsulating the mutation separately. Functional core — Many fast unit tests. Imperative shell — Few integration tests

https://www.youtube.com/watch?v=yTkzNHF6rMs

@cades
cades / Functional Core, Imperative Shell
Created January 8, 2018 16:11 — forked from jhrr/Functional Core, Imperative Shell
Notes and links for ideas about Gary Bernhardt's "functional core, imperative shell"
http://www.infoq.com/presentations/Simple-Made-Easy
http://www.infoq.com/presentations/integration-tests-scam
http://blog.thecodewhisperer.com/2010/09/14/when-is-it-safe-to-introduce-test-doubles
http://youtu.be/yTkzNHF6rMs
http://pyvideo.org/video/1670/boundaries
http://skillsmatter.com/podcast/ajax-ria/enumerators
http://alistair.cockburn.us/Hexagonal+architecture
http://c2.com/cgi/wiki?PortsAndAdaptersArchitecture
http://www.confreaks.com/videos/977-goruco2012-hexagonal-rails
http://www.confreaks.com/videos/1255-rockymtnruby2012-to-mock-or-not-to-mock

Keybase proof

I hereby claim:

  • I am cades on github.
  • I am cadeskao (https://keybase.io/cadeskao) on keybase.
  • I have a public key ASAA4ohCDiWEhnRhWxypFtKQM1ESnUXso-pIWy9JcM-2oQo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am cades on github.
  • I am cadeskao (https://keybase.io/cadeskao) on keybase.
  • I have a public key ASAx0YvoGBzahnrUBRq7XyWOQLT1JV3Y3h7pYaXjl5L0EQo

To claim this, I am signing this object:

@cades
cades / HOC-after-2.2.0.js
Created April 21, 2017 05:51
higher-order component for vue.js 2
export default function(WrappedComponent) {
const mixinProps = (WrappedComponent.mixins || [])
.filter((mixin) => mixin.props)
.map((mixin) => mixin.props);
const allProps = mixinProps.concat(WrappedComponent.props);
const mergedProps = allProps.reduce((merged, props) => Object.assign(merged, props), {});
return {
props: mergedProps,
render(createElement) {
@cades
cades / gist:44862551de984dd760f35a68f3cae21e
Created January 30, 2017 04:55 — forked from ciaranj/gist:9056285
A *working* (on Windows) UDP Multicast client & server with Node.Js v0.10.25 (I spent a *LOT* of time getting EINVAL and I still don't quite know why :/)
For my own sanity ;) Scraped from a variety of places, including: http://stackoverflow.com/questions/14130560/nodejs-udp-multicast-how-to?utm_medium=twitter&utm_source=twitterfeed
!Server
var news = [
"Borussia Dortmund wins German championship",
"Tornado warning for the Bay Area",
"More rain for the weekend",
"Android tablets take over the world",
"iPad2 sold out",
@cades
cades / 1-first-attempt.js
Last active May 27, 2016 08:14
在 mocha 中模仿 rspec-given 語法
describe('App.login()', () => {
it('should give token if success', sync(function*() {
var subject = Object.create(App), result
subject.init({ authVerifier: fakeAuthVerifier })
result = yield subject.login('user', 'pass', resume())
assert(typeof result.token === 'string')
}))
@cades
cades / response.feature
Created March 20, 2015 12:40
a HTTP server testing DSL proposal
Feature: I can test request response features
Scenario Outline: response code
When I request "GET" "http://httpbin.org/status/<code>"
Then the response code should be <code>
Examples:
| code |
| 200 |
| 411 |
@cades
cades / gulpfile.js
Last active August 29, 2015 14:08
static web development setup with livereload
var gulp = require('gulp'),
connect = require('gulp-connect');
gulp.task('webserver', function(){
connect.server({
livereload: true
});
});
gulp.task('watch', function(){
@cades
cades / ng-google-auth.js
Created October 15, 2014 07:01
登入 Google 帳號的 AngularJS directive。 HackNTU 的產出之一,未完成
'use strict';
angular.module('calenshareApp')
.factory('GoogleAuth', function () {
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=render';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);