Skip to content

Instantly share code, notes, and snippets.

@ahobson
ahobson / tsp.sh
Created September 20, 2023 14:42
prepend timestamps
#!/usr/bin/env perl -p
use POSIX strftime;
$|=1;
select((select(STDERR), $| = 1)[0]);
print strftime "[%Y-%m-%d %H:%M:%S] ", localtime
@ahobson
ahobson / batch_update.sql
Created September 18, 2023 14:49
code golf for batch update in postgresql
-- this is a naive way that seems plenty fast
DO $$
DECLARE
rec record;
BEGIN
RAISE INFO 'Starting %', now();
FOR rec IN SELECT id
FROM addresses
WHERE country = 'United States'
LOOP
@ahobson
ahobson / playwright-convert.rb
Created December 16, 2022 15:23
cypress to playwright helper script
#!/usr/bin/env ruby
# using ruby since it is already installed on macOS
if ARGV.length != 1
STDERR.puts "Usage: #{$0} cypress_test_file.js"
exit(2)
end
File.readlines(ARGV[0]).each do |line|
@ahobson
ahobson / permissions.diff
Created October 4, 2022 17:55
use permissions from session
diff --git a/pkg/handlers/authentication/auth.go b/pkg/handlers/authentication/auth.go
index 3e2cb5af15..6cb99e5d1f 100644
--- a/pkg/handlers/authentication/auth.go
+++ b/pkg/handlers/authentication/auth.go
@@ -58,13 +58,12 @@ type APIWithContext interface {
Context() *middleware.Context
}
-func PermissionsMiddleware(appCtx appcontext.AppContext, api APIWithContext) func(next http.Handler) http.Handler {
+func PermissionsMiddleware(api APIWithContext) func(next http.Handler) http.Handler {
@ahobson
ahobson / spa_handler.go
Created October 4, 2022 14:34
SPA Handler with neutered filesystem to not show directory listings
package handlers
import (
"net/http"
"os"
"path/filepath"
"github.com/transcom/mymove/pkg/logging"
)
@ahobson
ahobson / cra-uswds-sccs-test.sh
Last active April 8, 2022 15:29
cra 5.0 + sass + uswds = ???
$ npx create-react-app uswds-sccs-test
$ yarn add sass uswds nprogress
$ mv src/App.css src/App.scss
# edit App.js to change App.css to App.scss
$ yarn build
# everything is ok
$ echo "@import '~nprogress/nprogress';" >> src/App.scss
$ yarn build
# everything is ok
$ echo "@import '~uswds/src/stylesheets/theme/_uswds-theme-general.scss';" >> src/App.scss
@ahobson
ahobson / makefile_not_for_me.md
Created August 12, 2021 20:53
Makefiles are not for me

I'm not a big fan of Makefiles as entrypoints for a project.

  1. There's no way to pass command line arguments other than environment variables and there's no way to report per subcommand options
  2. There's no code reuse. If you have common functionality that you want to share (e.g. starting a dev db vs a test db) but with some parameters slightly different, there's no good way to do that in a Makefile
  3. The syntax is inscrutable. How do you run a shell command sending it a multi line command (for readability)? I tried for about an hour before giving up and writing an external shell script. MilMove has an entire directory of scripts for this reason. Even better, on MilMove those scripts call back out the the Makefile.
  4. Makefiles were needed for C/C++ because you recompiled individual files. There's even a command $(CC) $(CFLAGS) -MM that generates Makefile compatible syntax so that only necessary files are rebuilt. Modern languages don't work that way: they provide a single command that recompiles all n
import accessabilityNewSprite from 'uswds/src/img/sprite.svg#accessibility_new'
export const icons = {
accessibilityNew: accessabilityNewSprite,
}
version: 2
jobs:
build:
docker:
- image: circleci/node:12.16.2
working_directory: ~/react-uswds
steps:
- checkout
- restore_cache:
keys:
@ahobson
ahobson / docker_commands.txt
Last active July 15, 2020 20:56
Dockerfile show interaction between entrypoint and cmd
# This is what the Dockerfile looks like
$ cat Dockerfile
FROM bash
ENTRYPOINT ["/bin/ls"]
CMD ["-l"]
# Build the image so we can experiment
$ docker build -t mybashls .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM bash