Skip to content

Instantly share code, notes, and snippets.

View jooyunghan's full-sized avatar

Jooyung Han jooyunghan

View GitHub Profile
@jooyunghan
jooyunghan / buffer.c
Last active January 19, 2016 02:44
Using zer-length array for shared implementation for byte buffer
/*
============================================================================
Name : Buffer.c
Author : Jooyung Han
Version :
Copyright :
Description : Hello World in C, Ansi-style
============================================================================
*/
@jooyunghan
jooyunghan / ant.c
Last active February 2, 2016 09:36
C implementation of look and say sequence
//
// main.c
// ant
//
// Created by Jooyung Han on 1/31/16.
// Copyright © 2016 Jooyung Han. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@jooyunghan
jooyunghan / kmean.hs
Last active February 19, 2016 07:06
K-mean for [(d,d)] - slightly improved for readability
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module Lib
(
kMeans
) where
import GHC.Exts (groupWith)
import Data.List (transpose, sort)
import Data.List.Split (chunksOf)
@jooyunghan
jooyunghan / ant.go
Created March 1, 2016 08:34 — forked from anonymous/ant.go
Look and say sequence in Go using Chan/Goroutine
package main
import "fmt"
type genf func(chan<- uint8)
func gen(f genf) <-chan uint8 {
c := make(chan uint8)
go f(c)
return c
@jooyunghan
jooyunghan / ant.clj
Created March 1, 2016 08:36
Look-and-say sequence in Clojure using Lazy sequence
(defn nn [s] (->> s (partition-by identity) (mapcat (juxt count first))))
(defn ant [] (iterate nn [1]))
(-> (ant) (nth 1000000) (nth 1000000))
@jooyunghan
jooyunghan / child.js
Last active March 7, 2016 20:54
Promise 로 래핑하면서 오히려 실수할만한 내용.
process.on('message', function(message) {
console.log("message received", message);
process.send(message.toUpperCase(), function(err) {
console.log("replied",err);
});
});
@jooyunghan
jooyunghan / iter.js
Last active June 22, 2016 00:32
Another look-and-say sequence using JS Iterator(Generator)
function* Init() {
yield 1;
}
function* Next(it) {
var prev = it.next().value;
var count = 1;
for (let n of it) {
if (n == prev) {
count++;
@jooyunghan
jooyunghan / csp.js
Created March 8, 2016 17:59
Yet another look-and-say using js-csp
var csp = require("js-csp");
function Init() {
return csp.go(function* () {
return 1;
});
}
function Next(i) {
var out = csp.chan();
@jooyunghan
jooyunghan / promise-util.js
Created March 9, 2016 04:01
Promise helper which works like mapM
/**
* @template T, S
* @param {[T]} items
* @param {function(T):Promise<S>} f
* @return {Promise<[S]>}
*/
function traverse(items, f) {
if (items.length == 0) {
return Promise.resolve([]);
}
@jooyunghan
jooyunghan / regex.js
Created March 10, 2016 15:19
Print look-and-say sequence using Regex/Generator
const ant = function *(s = "1") {
yield s;
yield* ant(s.replace(/(.)\1?\1?/g, g => g.length + g[0]));
}
for (var i=0, a = ant(); i++<10; ) {
console.log(a.next().value)
}