Skip to content

Instantly share code, notes, and snippets.

const ref = useRef(null)
useEffect(
useCallback(() => {
console.log(ref.current)
}, [ref])
)
// useEffect(() => {
// console.log(ref.current)
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
// This is an example of a simple web app that uses a reducer via @pelotom's useMethods package.
//
// What I want to be able to do is use immer.js so I can just mutate a cloned state and
// also dispatch async request to imitate web requests.
// What I've worked out is simple: I use the useMethods package and wrap it into a custom
// useCustomMethods function which returns the state and the methods with logging.
// Besides that I just have one async function that takes a method as its argument and pipes
// its arguments into the action. This is for mocking HTTP requests that are not synchronous in nature.
//
// Because use-methods.js uses immer.js under the hood, this seems to work well.
@zaydek-old
zaydek-old / runner.go
Created July 11, 2019 10:14
100-line script that monitors changes and reboots the server if needed.
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
<html>
<head>
<!-- ... -->
</head>
<body>
<template class="codex-note-template">
<p class="codex-note" data-note-id="%noteID%">
<a href="/%noteID%">%title%</a>
<span style="color: hsl(0, 0%, 50%);">Edited %edited%</span>
<a class="delete-button" style="color: hsl(210, 100%, 62.5%);" href="#">Delete</a>
package main
import "fmt"
type voidSignal struct {
code int // The HTTP status code.
err error // The error.
desc string // The error's description.
}
create table users (
user_id text not null unique default url62(),
email_address text not null check (email_address ~ '^[^\s\@]+\@[^\s\.]+\.[^\s]+$'));
create table billing (
user_id text not null references users (user_id),
tier_id int not null references tiers (tier_id),
auto_renew bool not null, -- Not nullable because auto renew is exported.
balance money null,
stripe_customer_id text not null,
package routes
import (
"database/sql"
"api17/go/pg"
)
// VoidableTx is a voidable transaction. A transaction is
// voided when a method or closure emits a bad HTTP code and
// CreateUser has the following responsibilities:
//
// 1. Validate the intent.
// 2. Hash the passphrase.
// 3. Charge the token.
// 4. Create a user.
//
// FIXME: Confirm the user.
func CreateUser(w http.ResponseWriter, r *http.Request, vars *Vars) {
intent := &CreateUserIntent{}
package router
import (
"net/http"
"net/url"
"reflect"
"strings"
"api16/go/routes"
"api16/go/utils"