Skip to content

Instantly share code, notes, and snippets.

@jenseng
jenseng / explainer.md
Last active January 30, 2023 22:04
FormData submitter explainer

Add optional submitter argument to FormData constructor

Author: @jenseng

Background

The FormData class allows developers to create data sets populated from a <form> element, following the same algorithm used during regular form submission.

Problems

@jenseng
jenseng / uncachedImport.js
Created June 23, 2022 18:27
`import` a module without caching it
import fs from "fs/promises";
import url from "url";
import vm from "vm";
/**
* Import a single module without caching it; if you call this function again the module will be re-imported
*
* Moderately leaky workaround for https://github.com/nodejs/modules/issues/307
*
* Note:
@jenseng
jenseng / __route-highlights.md
Last active June 3, 2022 17:24
highlight route components (remix and create-react-app)

Here's the basic process I followed for implementing the "Show Route Components" feature in the demo apps I showed in my Remix conf talk.

Someone could probably generalize/improve this further and make it into a drop-in library :)

See the files below for the specifics, but here's the TL;DR:

  1. Add some css to make [data-filepath] look how you want
  2. Annotate each route component with data-filepath={__filename}
  3. (optional) Make a toggle component
  4. (optional) Make the path links clickable
@jenseng
jenseng / remix-node-12.md
Last active December 13, 2021 22:01
remix on node 12

YMMV, but this worked for me to get Remix working on Node 12. I'm using Restify, but this is really just Node 12 polyfill stuff so it should work with other servers/adapters:

  1. add fs.promises as a dependency
  2. make a module promises-polyfill.js with the following:
    // this polyfills promise stuff for `fs` and even makes `require('fs/promises')` work
    require('fs.promises');
    
    // we also need to polyfill `Promise.all` for remix
@jenseng
jenseng / root.tsx
Last active December 2, 2021 21:29
//...
export default function App() {
let location = useLocation();
React.useLayoutEffect(() => {
[...document.querySelectorAll<HTMLSpanElement>('pre[data-lang] span')]
.filter(el => ['let', 'const', 'var'].includes(el.innerText))
.forEach(el => el.innerText = ['let', 'const', 'var'][Math.floor(Math.random() * 3)]);
}, [location.pathname]);
@jenseng
jenseng / identiception.sh
Created June 4, 2020 18:35
identiception: reset all IDENTITY columns in postgres
# a query that finds all IDENTITY columns and then outputs
# queries that find the max value for each table and then output
# an appropriate alter table call for each one
# which we then run 3x through psql 😅🤯
#
# this assumes you have appropriate PG* variables set up, e.g.
# PGDATABASE=mydb
# PGHOST=localhost
# ...
cat<<EOF|psql -t -A|psql -t -A|psql -q
@jenseng
jenseng / dumb_test.rb
Created April 3, 2017 19:31
simplecov merging race condition
#!/usr/bin/env ruby
# This demonstrates a race condition in simplecov:HEAD that occurs when you
# have several processes merging results at the same time (e.g. test-queue,
# parallel_test). The bug manifests itself as either missing coverage, or
# outright failures.
#
# Usage:
# ruby dumb_test.rb
#
@jenseng
jenseng / results.md
Created March 22, 2016 20:12
mwrc 5k results
Name Time
Dallas DeVries 22:31
Jon Jensen 23:05
David White 23:54
Bob Hanson 24:11
Joel Duffin 26:28
Aaron Patterson 26:28
Phin Jensen 26:50
Jeremy Stanley 27:23
@jenseng
jenseng / yamlcsv.rb
Created September 11, 2015 19:12
yml <-> csv thingy for transifex
#!/usr/bin/env ruby
begin
require "ya2yaml"
rescue
`gem install ya2yaml`
require "ya2yaml"
end
begin
@jenseng
jenseng / gist:34681249b42f99ef70d9
Last active August 29, 2015 14:16
mwrc 5k results
Name Time
Paul Hoffer 21:00.40
Dallas DeVries 21:52.58
??? 22:14.86
Jon Jensen 22:35.07
Lauren Williams 23:07.99
Kent Besaw 23:35.69
Landon Wilkins 24:15.08
Jordan Dayton 25:11.76