Skip to content

Instantly share code, notes, and snippets.

View spiffytech's full-sized avatar

spiffytech spiffytech

View GitHub Profile
@spiffytech
spiffytech / attr_replace.py
Last active August 29, 2015 13:56
Replaces nested attributes on namedtuples
def attr_update(obj, child=None, _call=True, **kwargs):
'''Updates attributes on nested namedtuples.
Accepts a namedtuple object, a string denoting the nested namedtuple to update,
and keyword parameters for the new values to assign to its attributes.
You may set _call=False if you wish to assign a callable to a target attribute.
Example: to replace obj.x.y.z, do attr_update(obj, "x.y", z=new_value).
Example: attr_update(obj, "x.y.z", prop1=lambda prop1: prop1*2, prop2='new prop2')
Example: attr_update(obj, "x.y", lambda z: z._replace(prop1=prop1*2, prop2='new prop2'))

Keybase proof

I hereby claim:

  • I am spiffytech on github.
  • I am spiffytech (https://keybase.io/spiffytech) on keybase.
  • I have a public key whose fingerprint is 0528 73D9 49FE B3AC 3734 C80A 5243 7EC7 D25A CEB9

To claim this, I am signing this object:

@spiffytech
spiffytech / import.rb
Last active October 31, 2023 18:44 — forked from evanwalsh/import.rb
Imports a Squarespace dump into Jekyll
# coding: utf-8
require 'rubygems'
require 'hpricot'
require 'nokogiri'
require 'fileutils'
require 'safe_yaml'
require 'time'
require 'uri'
require 'open-uri'
@spiffytech
spiffytech / websharper.patch
Last active August 29, 2015 19:08
Patches an F# Scaffold project with basic WebSharper support
diff --git a/Web.config b/Web.config
new file mode 100644
index 0000000..053354f
--- /dev/null
+++ b/Web.config
@@ -0,0 +1,358 @@
+<configuration>
+ <configSections>
+ <sectionGroup name="elmah">
+ <!-- NOTE! If you are using ASP.NET 1.x then remove the
@spiffytech
spiffytech / index.js
Last active October 1, 2015 18:00
requirebin sketch
var beautify = require('js-beautify').js_beautify;
var pretty = require("js-object-pretty-print").pretty;
function show(el, val) {
document.getElementById(el).innerHTML = pretty(val, 4, "HTML");
}
// Declare our initial value
var original = {
a: 1,
@spiffytech
spiffytech / machine.js
Last active December 23, 2019 12:31
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@spiffytech
spiffytech / machine.js
Last active December 23, 2019 12:44
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@spiffytech
spiffytech / components.ts
Created December 16, 2020 12:38
Experimental HTML custom element library
import * as h from "hyperscript";
import morphdom from "morphdom";
import { nanoid } from "nanoid";
abstract class Coordinator<
Attrs extends Record<string, any> | null,
State extends Record<string, any>
> extends HTMLElement {
static readonly forwardedAttrs: Map<string, unknown> = new Map();
static attrsAttr = "data-attrs";