Skip to content

Instantly share code, notes, and snippets.

Avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
  • Finland
View GitHub Profile
@milankinen
milankinen / main.js
Last active Mar 17, 2016
TSERS "cyclish"
View main.js
import {Observable as O} from "rx"
import makeReactDOM from "@tsers/react"
import tsersRun from "./tsersRun"
function main({DOM}) {
let {h} = DOM
let action$ = O.merge(
DOM.select('.decrement').events('click').map(ev => -1),
DOM.select('.increment').events('click').map(ev => +1)
);
@milankinen
milankinen / app.js
Created Mar 5, 2016
Dynamic CycleJS counters
View app.js
function Counter({signals, DOM: {render, h, events}, title}, initial$ = Observable.just(0)) {
const model = (signals, initial$) =>
initial$.first().concat(signals.in("inc").merge(signals.in("dec"))).scan((s, a) => s + a).share()
const view = (counter$) =>
[counter$, render(counter$.map(count =>
h("div", [
h("button.increment", "Increment"),
h("button.decrement", "Decrement"),
h("p", title + ": " + count)
View cycle-dom-alt.js
import EventEmitter from "events"
import {Observable} from "rx"
import h from "virtual-dom/h"
import diff from "virtual-dom/diff"
import patch from "virtual-dom/patch"
import el from "virtual-dom/create-element"
import selmatch from "matches-selector"
import {values, indexBy, prop} from "ramda"
const delegate = (name, em) => ({
@milankinen
milankinen / fun.js
Created Mar 2, 2016
Optimized list rendering with atoms and lenses
View fun.js
import React from "react"
import R from "ramda"
const shallowEq = (a, b) => {
const aKeys = R.keys(a), bKeys = R.keys(b)
if (aKeys.length !== bKeys.length) return false
for (let i = 0; i < aKeys.length; i++) {
if (a[aKeys[i]] !== b[aKeys[i]]) return false
}
View lifting.js
import R from "ramda"
const subLens = (by, val, def) => {
const orDefault = val => val === undefined ? def : val
const matches = R.compose(R.equals(val), by)
return R.lens(
s => orDefault(R.find(matches, s)),
(a, s) => {
const idx = R.findIndex(matches, s)
return idx >= 0 ? R.set(R.lensIndex(idx), a, s) : s
@milankinen
milankinen / render-dom.diff
Last active Feb 26, 2016
cyclejs-dom isolation mods
View render-dom.diff
@@ -4,6 +4,7 @@ let VDOM = {
h: require(`./virtual-hyperscript`),
diff: require(`virtual-dom/diff`),
patch: require(`virtual-dom/patch`),
+ createElement: require(`virtual-dom/create-element`),
parse: typeof window !== `undefined` ? require(`vdom-parser`) : () => {},
}
let {transposeVTree} = require(`./transposition`)
@@ -60,26 +61,66 @@ function renderRawRootElem$(vtree$, domContainer) {
.flatMap(diffAndPatchToElement$)
@milankinen
milankinen / cycle-dom-modified.js
Last active Feb 26, 2016
cycle-dom with better isolation
View cycle-dom-modified.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.CycleDOM = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
},{}],2:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var isValidString = function isValidString(param) {
@milankinen
milankinen / output.txt
Created Feb 4, 2016
deep learning finnish
View output.txt
Using Theano backend.
Load data
> dataset = ../datasets/sample_xs_2.txt
> words
- total = 3500
- distinct = 7
> chars = 14
> metadata saved to "./output/meta.json"
Generate matrices
> dim(X) = (128, 5, 8, 14)
@milankinen
milankinen / app.js
Created Jan 25, 2016
fluorine+combinators
View app.js
import React from "react"
import {Subject, Observable} from "rx"
import {render} from "react-dom"
import {Combinator} from "react-combinators/rx"
import {createDispatcher} from "fluorine-lib"
const initialBMI = {weight: 80, height: 180}
function BMI(state, action) {
View tiny-cycle-3.js
let i = 0
let main = () => document.querySelector("#app").innerHTML = `Seconds elapsed ${i++}`
main() && setInterval(main, 1000)
You can’t perform that action at this time.