Skip to content

Instantly share code, notes, and snippets.

function formatDate (iso) {
const [year, month, day] = iso.split('T')[0].split('-')
return `${+month}/${+day}/${year}`
}
@timwis
timwis / form.js
Created July 16, 2016 21:00
choo form component example
const getFormData = require('get-form-data')
const html = require('choo/html')
module.exports = function formComponent (opts) {
return `
<form>
<input name="woof" type="text" placeholder="type here"
value=${opts.values.woof} oninput=${onInput}>
<input type="submit" onsubmit=${onSubmit}>
</form>
@timwis
timwis / index.js
Created July 21, 2016 10:59
requirebin sketch
const yo = require('yo-yo')
function parent (title) {
return yo`<div>${child(title)}</div>`
}
function child (title) {
const el = yo`<h1>${title}</h1>`
window.setTimeout(() => {
// silly example, but really referring to L.map() or other init() libraries
@timwis
timwis / index.js
Created July 22, 2016 10:33
requirebin sketch
const choo = require('choo')
const html = require('choo/html')
const http = require('choo/http')
const app = choo()
app.model({
effects: {
fetch: (data, state, send, done) => {
send('sub', (err) => {
if (err) {
var list = document.querySelector('#filter-list ul')
var listItems = Array.from(list.children)
var depts = listItems.map((li) => {
var link = li.querySelector('.content-department')
return link.innerText + "\t" + link.getAttribute('href')
})
copy(depts.join("\n"))
@timwis
timwis / index.js
Created July 26, 2016 23:18
requirebin sketch
const choo = require('choo')
const html = require('choo/html')
const app = choo()
app.model({
state: {
convos: {
'2151234567': generateItems(50),
'9891239876': generateItems(50),
@timwis
timwis / index.js
Created August 6, 2016 15:25
requirebin sketch
var html = require('bel')
var morphdom = require('morphdom')
var saved
function child () {
saved = saved || html`<h1 onload=${() => console.log('child on')} onunload=${() => console.log('child off')}>child</h1>`
return saved
}
function parent () {
const http = require('http')
const Readable = require('stream').Readable
const formBody = require('body/form')
http.createServer(function (req, res) {
const stream = new Readable
console.log('inbound')
formBody(req, {}, (err, body) => {
stream.push('hi')
stream.push(null)
@timwis
timwis / dataset.html
Created August 10, 2016 12:22
jkan dataset page with disqus
---
layout: default
---
{% include breadcrumbs.html parent="Datasets" %}
{% assign schema = page.schema | default: site.schema %}
{% assign dataset_fields = site.data.schemas[schema].dataset_fields %}
{% assign dataset_system_fields = "title|organization|notes|license" | split: "|" %}
{% assign resource_fields = site.data.schemas[schema].resource_fields %}
{% assign resource_system_fields = "name|url|format|description" | split: "|" %}
client.select('*').from(opts.table).stream()
.pipe(through.obj(chunkToFiles))
.pipe(vfs.dest('./' + opts.table))
function chunkToFiles (chunk, enc, callback) {
const primaryKey = chunk[opts.primaryKey]
const keys = Object.keys(chunk)
keys.forEach((key) => {
const file = new File({