Skip to content

Instantly share code, notes, and snippets.

View coodoo's full-sized avatar

Jeremy Lu coodoo

View GitHub Profile
@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,
@coodoo
coodoo / Bulk.js
Last active July 1, 2017 23:59
Bulk monoid
/*
- Goal:
implmenting something like Pair(a, b) but could accommodate any amount of arguments
- Usage:
Bulk( Sum(2), Sum(3), Sum(4) )
.concat(Bulk(Sum(1), Sum(1), Sum(1)))
@coodoo
coodoo / Map.js
Last active June 18, 2017 06:15
練習實作一支 Map type 與其身上多支指令,例如 map(), reduce(), foldMap() 等...
const Mapp = val => ({
val,
// {a: 'aa', b: 'bb'}
// f :: v -> value
map: f => {
const o = {}
// let resultArr = Object.keys(val).map((key, idx) => ({ [key]: f(val[key]) })) // 錯的,會變成[{}, {}]
Object.keys(val).map((key, idx) => o[key] = f(val[key]) )
@coodoo
coodoo / weight.js
Last active May 11, 2017 03:10
從目標體脂推算理想體重與需減去的脂肪,用法為 weight( 100, 0.3, 0.2, 400 ),代表目前體重 100kg,體脂 30%,目標體脂 20%,每日運動可燒掉 400大卡。
function weight(
currentWeight = 82,
currentRatio = 0.23,
targetRatio = 0.2,
dailyBurn = 400
) {
const currentFat = currentWeight * currentRatio
const currentMuscle = currentWeight - currentFat
const targetWeight = currentMuscle / (1 - targetRatio)
const loseFat = currentWeight - targetWeight // kg
@coodoo
coodoo / weight.js
Created May 11, 2017 02:26
從目標體脂推算理想體重與需減去的脂肪,用法為 weight( 100, 0.3, 0.2, 400 )
function weight(
currentWeight = 82,
currentRatio = 0.23,
targetRatio = 0.2,
dailyBurn = 400,
) {
const currentFat = currentWeight * currentRatio
const currentMuscle = currentWeight - currentFat
const targetWeight = currentMuscle / (1 - targetRatio)
const loseFat = currentWeight - targetWeight // kg
@coodoo
coodoo / icons.jsx
Last active July 11, 2016 22:04
Code snippet for using SVG icons in react
/*
Usage:
import SVGIcon from './Icons.jsx'
<SVGIcon kind='edit' style={{width: 48, height:48, fill:'green'}} />
*/
import React, { Component, PropTypes } from 'react'
// base icon style
const styles = {
import hyperarray from 'hyper-array'
import memdb from 'memdb'
const dag = hyperarray( memdb() )
// step 1
// api: array.insert(value, [before], [after], [cb=function (err, entry) {}])
dag.insert( 'abc', null, null, ( err, node ) => {
conole.log( node )
--[[
- here's a better way to train RNNLM with large dataset,
- persist the weights from LookupTable into file
- and load it back later to use in sentiment analysis tasks
- detailed discussion here: https://github.com/torch/nn/issues/747
- thanks @fmassa for pointing out the direct direction