Skip to content

Instantly share code, notes, and snippets.

View tjmw's full-sized avatar

Tom Wey tjmw

View GitHub Profile
@kubukoz
kubukoz / semiauto-vs-auto.md
Created October 5, 2021 17:36
Semiauto vs auto derivation

You mention that you would only use circe auto derivation in only a few limited cases - may I ask why? It looks like you are using semi-auto derivation instead. Why is this better/more stable?

The difference is where the derivation happens - in semiauto, you only have one place where a codec for a given type will be derived: at definition site, which is usually the companion object (it's the companion object in our case, but it could be anywhere really - point still stands that it's easier to track). In auto derivation, codecs are derived as needed by the usage - e.g. in the endpoint definitions or in a controller (depending on the tech stack you use). The problem here is that you need all the codecs of all the fields and all their fields (...and so on...) to be available there.

The centralization of the codecs in Semiauto mode allows us to switch to a different format at any time, while keeping the representation consistent across all usages of it. Additionally, it allows us to test the codec logic witho

@alexford
alexford / main.yml
Last active August 31, 2023 02:31
Running Rails tests with RSpec on GitHub actions with Postgres
name: CI
on: [push]
jobs:
rspec:
runs-on: ubuntu-latest
container:
image: ruby:2.6.5

TL;DR: what was the bug? (spoilers!): https://gist.github.com/trptcolin/6039cd454acfe6e820d13cbdce5e4064

@odlp
odlp / percentage_error.sh
Last active May 19, 2021 14:57
Percentage error output in tests
#!/bin/bash
# Save stdout & stderr to individual files:
bundle exec rspec > >(tee stdout.log) 2> >(tee stderr.log >&2)
# Calculate the percentage:
wc -l stderr.log stdout.log \
| ruby -e \
'err, _, total = ARGF.map(&:to_f); puts "#{(err/total*100).round}% error output"'
@nickcharlton
nickcharlton / README.md
Last active December 6, 2017 09:52
Installing postgis valid for PostgreSQL 9.6.2 w/Homebrew

Installing PostGIS valid for PostgreSQL 9.6.2

PostGIS marks PostgreSQL as a dependency. As I write this Postgres 10 has just been released, but we don't yet want that as it'd be far ahead of Heroku Postgres.

To be able to install a valid PostGIS for 9.6.2 we need to do something like this:

% cd $(brew --repo homebrew/core)
@jayphelps
jayphelps / package.json
Last active June 29, 2024 15:53
TypeScript output es2015, esm (ES Modules), CJS, UMD, UMD + Min + Gzip. Assumes you install typescript (tsc), rollup, uglifyjs either globally or included as devDependencies
{
"scripts": {
"build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015",
"build:esm": "tsc --module es2015 --target es5 --outDir dist/esm",
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
"build:umd": "rollup dist/esm/index.js --format umd --name YourLibrary --sourceMap --output dist/umd/yourlibrary.js",
"build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --source-map --screw-ie8 --comments --o yourlibrary.min.js -- yourlibrary.js && gzip yourlibrary.min.js -c > yourlibrary.min.js.gz",
}
}
@acdlite
acdlite / prefetch.js
Last active June 11, 2021 08:34
Prefetching in React
function prefetch(getKey, getValue, getInitialValue, propName) {
const inFlight = new Set();
const cache = new Map();
return ChildComponent => {
return class extends React.Component {
state = {value: getInitialValue(this.props)};
componentWillReceiveProps(nextProps) {
const key = getKey(nextProps);
if (cache.has(key)) {
// Use cached value
@mcmire
mcmire / bypass_broken_images_middleware.rb
Last active October 16, 2021 11:09
Ignore requests for broken images in Capybara tests
# Instructions
# ------------
#
# * Save this as app/middlewares/bypass_broken_images_middleware.rb
# * Add the following inside of the Rails.application.configure block
# in config/environments/test.rb:
#
# config.middleware.insert_before(
#  ActionDispatch::DebugExceptions,
#  BypassBrokenImagesMiddleware,
port module Spelling exposing (..)
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import String
main =
@Rich-Harris
Rich-Harris / footgun.md
Last active June 16, 2024 00:01
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological