Skip to content

Instantly share code, notes, and snippets.

@tetsuo
tetsuo / tree.ts
Created July 19, 2021 20:18
tree.ts
interface Tree<A> {
readonly value: A
readonly forest: Forest<A>
}
type Forest<A> = Array<Tree<A>>
const draw = (indentation: string, forest: Forest<string>): string => {
let r: string = ''
const len = forest.length
import { array } from 'fp-ts/lib/Array'
import { fromTraversable, Lens, Prism, Iso } from 'monocle-ts'
interface Model {
sensors: Array<Sensor>
}
interface Sensor {
ip: string
temp: number

Keybase proof

I hereby claim:

  • I am tetsuo on github.
  • I am tetsuo (https://keybase.io/tetsuo) on keybase.
  • I have a public key ASDbwdTJXtudwZoP7yJRtZbv0P7AvC1zaojOMGvs3qrpdgo

To claim this, I am signing this object:

@tetsuo
tetsuo / index.js
Created July 14, 2017 17:16
xus-example-index-4
import { createElement } from "react"
import { observer } from "mobx-react"
const tree = render(state, {
createElement: createElement,
observer: observer
})
ReactDOM.render(tree, document.getElementById("main"))
@tetsuo
tetsuo / index.js
Created July 14, 2017 16:16
xus-example-index-3
const state = State.create({
todos: [
{ title: "Get coffee", done: false },
{ title: "Wake up", done: true }
]
})
@tetsuo
tetsuo / index.js
Created July 14, 2017 16:13
xus-example-index-2
const State = types.model("State", {
todos: types.array(Todo),
get completedCount() {
return this.todos.reduce(function(count, todo) {
return todo.done ? count + 1 : count
}, 0)
}
})
@tetsuo
tetsuo / index.js
Created July 14, 2017 16:06
xus-example-index-1
import { types } from "mobx-state-tree"
const Todo = types.model("Todo", {
title: types.string,
done: types.boolean
}, {
toggle: function() {
this.done = !this.done
}
})
@tetsuo
tetsuo / layout.html
Last active July 14, 2017 02:44
xus-example-layout.html
<div>
<p>You have completed <b>{completedCount}</b> of your tasks.</p>
<p><b>Click on more tasks to finish them!</b></p>
<ul>
{#todos}
<li class="{#done}finished{/done}" onclick="toggle">{title}</li>
{/todos}
</ul>
<div>
@tetsuo
tetsuo / gist:6742855
Created September 28, 2013 14:53
grouping objects by attribute in python
import itertools
class A:
def __init__(self, uniq, key):
self.uniq = uniq
self.key = key
def __repr__(self):
return "%s(%s, %s)" % (self.__class__, self.uniq, self.key)