Skip to content

Instantly share code, notes, and snippets.

View cades's full-sized avatar

hong-jen kao cades

View GitHub Profile
@cades
cades / transformer.js
Last active June 5, 2020 02:52
讀取 google calendar api v3 / Events: list , 轉換成 FullCalendar 的格式
var util = require('util'),
request = require('request'),
parser = require('xml2json'),
calendar_id = 'fgj3gh1p2chvsb0vge2sjrejag@group.calendar.google.com',
api_key = 'AIzaSyBQal2rNhP5SRkU5hZytY7Yb8nYc5Q1nrc',
url = util.format('https://www.googleapis.com/calendar/v3/calendars/%s/events?key=%s', calendar_id, api_key);
request({url: url}, function(error, response, json){
var data = JSON.parse(json),
transformed = data.items.map(function(event){

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 / 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 / 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 / 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 / compile-jade-on-save.el
Created July 28, 2013 16:18
Writing html in jade is nice, but I always forget to compile it. Add this piece of code into your .emacs file, your emacs will compiles jade into html after save. 用 jade 寫 html 是件很棒的事, 但我老是忘記編譯它. 把這段 code 加入 .emacs, emacs 在存檔時會自動替你編譯.
;; auto compile jade file after save
(add-hook
'after-save-hook
(lambda ()
(if (string= (file-name-extension (buffer-file-name)) "jade")
(if (= (shell-command
(concat "jade --pretty " (buffer-file-name)))
0)
(message (concat (buffer-file-name) " just saved and compiled into html"))))))
@cades
cades / angularjs-provider-demo.js
Last active December 20, 2015 02:59
示範如何在config()中呼叫provider提供的函式。 這個例子寫了一個pathRootProvider, 注意其中兩個被return的object: 第一個是 provider()回傳的物件,注入config()的就是它。第二個是$get()回傳的物件,注入controller的就是它。 關鍵在於「把函式提出$get, 拉到與$get同一個層級」,放在這裡的函式才能在config()內被呼叫。 順帶一提,factory()是provider()的一個方便使用的包裝,傳給factory的function會被放進$get中,也因此失去在config()中被呼叫的可能性。 Robin Fan提供一個影片,解說的頗清楚:http://www.egghead.io/video/HvTZb…
angular.module('myApp', ['ui.state']).
provider('pathRoot', function() {
return {
partialView: function(filename) {
return '../js/angular/partial/' + filename;
},
$get: function(pathId) {
return {};
}
};