Skip to content

Instantly share code, notes, and snippets.

@alkhe
alkhe / cycle.js
Last active January 12, 2016 05:24
dumbed down Cycle.js
export default {
run(main, drivers) {
let sinkProxies = {}
let sources = {}
for (let name in drivers) {
sinkProxies[name] = new Rx.ReplaySubject(1)
sources[name] = drivers[name](sinkProxies[name], name)
}
@alkhe
alkhe / hGetContents'.hs
Created February 10, 2016 06:17
hGetContents'
import System.IO
import Control.Monad
import Control.Monad.Loops
hGetContents' :: Handle -> IO String
hGetContents' h = whileM (not <$> hIsEOF h) (hGetChar h)
@alkhe
alkhe / hexdump.hs
Created February 10, 2016 07:46
Haskell Hex Dumper
import System.IO
import System.Environment
import Control.Monad
import Control.Monad.Loops
import Data.List
import Data.List.Split
import Data.Char
import Data.Hex
import Data.Monoid
@alkhe
alkhe / pigen.hs
Created February 10, 2016 08:10
stack-based pi-approximator
atan1 0 = 1
atan1 degree = (if even degree then id else negate) 1 / (2 * fromIntegral degree + 1) + atan1 (degree - 1)
pigen = (4*) . atan1
main = print $ pigen 10000000 -- 3.1415927535897814
@alkhe
alkhe / pigen2.hs
Created February 10, 2016 08:16
trampolined pi-approximator
atan1t 0 = 1
atan1t degree = (if even degree then id else negate) 1 / (2 * fromIntegral degree + 1)
pigen = (4*) . sum . flip take (fmap atan1t [0..])
main = print $ pigen 10000000 -- 3.1415925535897915
@alkhe
alkhe / hexdump2.hs
Created February 10, 2016 21:36
Haskell Hex Dumper
import System.IO
import System.Environment
import Control.Monad
import Data.Char
import Data.List.Split
import Data.Hex
unwhite :: String -> String
unwhite = fmap replace
where replace c

Keybase proof

I hereby claim:

  • I am edge on github.
  • I am redux (https://keybase.io/redux) on keybase.
  • I have a public key whose fingerprint is F612 8689 E889 3DC8 49CC ECDD 491A D175 095E A2B1

To claim this, I am signing this object:

@alkhe
alkhe / cyclewriter.js
Created March 2, 2016 19:32
Cycle.js Isolation with a Writer Monad
import { Subject, Observable as $ } from 'rx';
import { assign } from 'cycle-monad';
function LabeledSlider({ DOM, props$ }) {
/* this is our source for local events
* the parent DOM isn't supposed to provide it anyways
*/
const hooks = Subject();
const initialValue$ = props$
@alkhe
alkhe / Counter.js
Last active March 13, 2016 21:18
Cycle using Subject handlers instead of DOM.select. Counter2 is native API-compatible.
import { Subject, Observable as $ } from 'rx';
let Counter = ({ props$ }) => {
const handlePlus$ = Subject();
const handleMinus$ = Subject();
const value$ = props$.init.concat(
$.merge(handlePlus$.map(() => 1), handleMinus$.map(() => -1))
).startWith(0).scan((acc, x) => acc + x));
return {
export default ({ DOM }) => {
- Button(DOM.select('.Home')).forEach(() => {
- window.location.href = '/';
- });
- Button(DOM.select('.Github')).forEach(() => {
- window.location.href = 'https://github.com/edge/cyc';
- });
+ const homeClick$ = DOM.handler();
+ const ghClick$ = DOM.handler();
+ homeClick$.forEach(() => {