Skip to content

Instantly share code, notes, and snippets.

View coodoo's full-sized avatar

Jeremy Lu coodoo

View GitHub Profile
@coodoo
coodoo / fat.js
Created August 6, 2018 08:11
How to write fat arrow function.
import io from 'socket.io-client'
const A = require('automerge')
const foo = bar => {
bar.map( b => b.title )
}
startConnection() {
this.socket = io('http://localhost:5000')
@coodoo
coodoo / a.hs
Last active January 8, 2018 01:06
Find first not repeated char in a string. "Technical question" -> h. "Backend" -> b
-- f (x:xs) = case x `elem` xs of
-- True -> f xs
-- False -> x
f s = f' $ map toLower s
where
f' (x:xs) =
case x `elem` xs of
True -> f' xs
False -> x
module Main where
import Control.Monad.State
import System.Directory
import System.Exit
import System.FilePath
import Data.Time
data File = File
{ name :: FilePath
@coodoo
coodoo / Interop.hs
Created December 9, 2017 12:03
Would appreciate any correction, better way to do it or generic advices on this practice code.
{-
Functionality:
- Read all folders and sub-folders with structure like below
- store all folder and file info in State monad,
- at the end of the loop, print it.
├── aaa
│ ├── b
│ │ ├── b1
│ │ │ ├── b1-1
@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]
@coodoo
coodoo / v2.hs
Created October 25, 2017 09:25
list to tree v2
data Item = Item {
sId :: String,
pId :: String,
value :: [Char],
children :: [Item]
} deriving (Show)
list :: [Item]
list = [
Item { sId="1", pId="0", value="1", children=[] },
@coodoo
coodoo / v1.hs
Created October 25, 2017 04:47
convert list to tree structure
data Item = Item {
sId :: String,
pId :: String,
value :: [Char],
children :: [String]
} deriving (Show)
list :: [Item]
list = [
Item { sId="1", pId="0", value="1", children=[] },
@coodoo
coodoo / WriterMonadExample.hs
Last active October 11, 2017 23:46
writer monad example
module Bar
(
) where
import System.IO
import System.Environment
import Control.Monad
import Data.Maybe
import Data.List
import Control.Monad.Writer
big :: Int
big =
-- (\x -> x - 1) -- 可以
(-1) -- 不行
$ length
$ takeWhile (< 10)
$ scanl (\acc x -> sqrt x + acc) 0 [1..]
@coodoo
coodoo / bulkapp.js
Created July 2, 2017 06:20
Application of Bulk monoid
const Task = require('data.task')
const { List, Map } = require('immutable-ext')
const { Pair, Sum, Intersection } = require('./monoid')
const { findArtist, relatedArtists } = require('./spotify')
const Bulk = (...xs) => ({
xs,
concat: ys => Bulk(...xs.map( (x, idx) => x.concat(ys.xs[idx]) )),
bulkMap: (...fs) => Bulk(...xs.map((x, idx) => fs[idx](x))),
toList: _ => xs,