Skip to content

Instantly share code, notes, and snippets.

View ssured's full-sized avatar
🙊
\> say "ssured"

Sjoerd de Jong ssured

🙊
\> say "ssured"
View GitHub Profile
@mjepronk
mjepronk / form.js
Last active November 12, 2022 23:09
Serialize an HTML form to JSON
var form = document.querySelector('form');
form.addEventListener('submit', function(event) {
event.preventDefault();
submitForm();
}
function submitForm(form) {
var data = serializeForm(form);
var json = JSON.stringify(data);
var xhr = requestPost(url, json);
@paulshen
paulshen / natto-eval.js
Created April 13, 2021 16:11
natto.dev eval pseudocode
const f = useMemo(() => {
try {
return new Function('inputs', `return ${expression}`);
} catch (e) {
return [e];
}
}, [expresssion]);
// input atoms
const express = require('express');
const htm = require('htm');
const vhtml = require('vhtml');
// create an html`` tag function for vhtml:
const html = htm.bind(vhtml);
const App = (props) => html`
<div class="app">
<h1>This is an app</h1>
@ZempTime
ZempTime / xstate-getting-started.md
Last active September 12, 2019 07:25
Statechart doc example

Thinking in State Charts

  1. Determine your states
  2. Determine your events
  3. Determine your side effects (resulting changes in state)

You can store information in two ways:

  • State nodes (each state node can have one value)
  • Context (can hold arbitrary values because js object)
@danielkcz
danielkcz / formik-mobx.js
Last active July 26, 2023 21:51
Formik with MobX
function useFormik(props) {
// useState to keep the same observable around without recreating it on each render
const [formik] = React.useState(() =>
mobx.observable({
values: props.initialValues || {},
touched: {}
})
)
// just mutate state, this function itself can be considered an action+reducer
@tgriesser
tgriesser / formik.tsx
Last active March 12, 2021 10:58
Formik w/ Hooks
import React, {
useContext,
createContext,
createElement,
useEffect,
useRef,
useCallback,
useState,
} from 'react';
import isEqual from 'react-fast-compare';
@gcanti
gcanti / io-ts2form.ts
Created August 25, 2018 13:37
Automatically building a form from a `io-ts` type
import * as t from 'io-ts'
import * as React from 'react'
import { render } from 'react-dom'
type Field = t.StringType | t.NumberType | t.BooleanType
interface Form extends t.InterfaceType<{ [key: string]: Field }> {}
const toReactElement = (f: Form | Field): React.ReactElement<any> => {
// f is a tagged union
switch (f._tag) {
@DesignByOnyx
DesignByOnyx / README.md
Last active December 26, 2021 02:11
A script for setting up a project to use semantic-ui-less

This script was inspired by this blog post - however I found the technique to be a little insufficient. Many thanks to Artem Butusov as I would not have been able to do this without his blog post.

This script is intended to be used with semantic-ui-react projects. If you are just using semantic-ui, then you may need to do some other troubleshooting... I don't know as I haven't tested. From what I can tell everything should work just fine.

Before we get started

This process is completely different from the one described in the blog post above. This script is intended to do everything for you - no manual copying or updating code is required. If you have already followed

anonymous
anonymous / instructions.md
Created September 25, 2017 22:53
Trying out wohali's couchdb netdata plugin

Installing

  1. Install couchdb per http://docs.couchdb.org/en/2.1.0/install/unix.html#installation-using-the-apache-couchdb-convenience-binary-packages
  2. $ sudo apt-get install zlib1g-dev uuid-dev libmnl-dev gcc make git autoconf autoconf-archive autogen automake pkg-config curl
  3. $ cd ~ && git clone https://github.com/wohali/netdata
  4. $ cd netdata && git checkout couchdb
  5. $ sudo ./netdata-installer.sh
  6. $ sudo vi /etc/netdata/python.d/couchdb.conf and set admin username/password
  7. $ sudo service netdata restart
  8. Browse to http://localhost:19999/
export function drained$<T>(pullStream: Function): Rx.Observable<T> {
return Rx.Observable.create(function subscribe(observer: Rx.Observer<T>) {
const drain = function drain(read: Function) {
read(null, function more(end: any | boolean, data: T) {
if (end === true) {
observer.complete();
return;
}
if (end) {