Skip to content

Instantly share code, notes, and snippets.

View wuct's full-sized avatar

CT Wu wuct

View GitHub Profile
exports.setHTML = function(el) {
return function (htmlElement) {
return function() {
el.innerHTML = '';
el.appendChild(htmlElement);
};
};
};
@masaeedu
masaeedu / _main.js
Last active January 13, 2019 22:20
Interpreting callback APIs as pure, monad-returning functions
const Cont = require("@masaeedu/fp/dist/instances/cont");
const S = require("sanctuary");
// > It is often said that callbacks do not compose. While this may
// > be true, functions that *accept* callbacks compose extraordin-
// > arily well. In fact, such functions, which I'll hereafter refer
// > to as "continuations", form a monad, and a rather powerful and
// > versatile monad at that.
// >
// > In this snippet, I'll try to demonstrate how the continuation
@coodoo
coodoo / v3.hs
Created October 27, 2017 06:14
Convert list to tree using State monad, in a suck less manner 😅
module Bar () where
import Data.Maybe
import Control.Monad.State
import qualified Data.Map as M
data Item = Item {
sId :: String,
pId :: String,
value :: [Char],
children :: [String]
@acdlite
acdlite / coordinating-async-react.md
Last active March 20, 2022 12:27
Demo: Coordinating async React with non-React views

Demo: Coordinating async React with non-React views

tl;dr I built a demo illustrating what it might look like to add async rendering to Facebook's commenting interface, while ensuring it appears on the screen simultaneous to the server-rendered story.

A key benefit of async rendering is that large updates don't block the main thread; instead, the work is spread out and performed during idle periods using cooperative scheduling.

But once you make something async, you introduce the possibility that things may appear on the screen at separate times. Especially when you're dealing with multiple UI frameworks, as is often the case at Facebook.

How do we solve this with React?

Re: asyncio 好寫嗎?

首先,其實還滿開心有機會可以做個小小辯論的啦。我的回應如下

這把好幾個主題混在一起了,需要一個一個看。

1. Async Program 好寫嗎?

不好寫。東西好不好寫的意思,代表它和 programmer 的內在思考模式符合程度。Async program 不符合人類習慣思維,所以才會被說一開始的學習 overhead 很高,寫起來容易卡。尤其如果同步與異步 paradigms 並立(例如 Python),就更容易在切換的時候出問題。

import Data.Functor
readInt = read <$> getLine :: IO Int
readIntArray = map read . words <$> getLine :: IO [Int]
m = 10^9 + 7
mm a b = (a * b) `mod` m
extractCD2 :: (Int, [Int]) -> Int -> (Int, [Int])
@bendrucker
bendrucker / droplr-gh.md
Last active February 1, 2021 12:30
Pasting droplr image/gif links to Github

Droplr will auto-copy the sharing link when you take a screenshot. You'll use this on GitHub.

That copied link will look like this: http://d.pr/i/13PDt

To paste that into a GitHub issue:

![](http://d.pr/i/13PDt+)
@jhartikainen
jhartikainen / commit-msg
Created February 6, 2015 17:46
ESLint git commit hook
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.js$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
echo $files | xargs eslint
@sebmarkbage
sebmarkbage / ReactCanvasDrawing.js
Created July 25, 2014 19:14
Canvas Drawing Example
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {