Skip to content

Instantly share code, notes, and snippets.

View coodoo's full-sized avatar

Jeremy Lu coodoo

View GitHub Profile
@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
@coodoo
coodoo / LookupTableEx.lua
Created April 4, 2016 08:42
Added support to pass in pre-trained weights for LookupTable so that RNNLM could be trained with large data set
local THNN = require 'nn.THNN'
local LookupTable, parent = torch.class('nn.LookupTable', 'nn.Module')
LookupTable.__version = 4
-- added 3rd argument, to pass in pre-trained weights
function LookupTable:__init(nIndex, nOutput, odlWeights )
parent.__init(self)
-- simple case to reproduce GPU crash bug
require 'paths'
require 'rnn'
require 'nngraph'
require 'cltorch'
require 'clnn'
cltorch.setDevice(1)
------------------------------------------------------------------------------------