Skip to content

Instantly share code, notes, and snippets.

View garybernhardt's full-sized avatar

Gary Bernhardt garybernhardt

View GitHub Profile
const webpack = require('webpack');
const path = require('path');
const StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const production = process.env.RACK_ENV == 'production'
const config = {
mode: production ? "production" : "development",
entry: './build/client/app.js',
It's a subscription-based screencast site, where I post a new five- to
ten-minute screencast every week. For this, people pay a nominal fee
around $3 per month, giving them access to the full archives and new
screencasts as they happen. The style would be similar to the
screencasts I've posted on my blog: just me and the computer, recorded
in one take, although with much practicing. I'd focus not on new
languages and tools, but on the minute-to-minute mechanics of
effective programming practices, with an obvious bias toward the stack
and practices that I use.
// This has been updated. You'll have to go back in time in the gist history to
// see older versions.
const { writeSync } = require("fs")
const async_hooks = require("async_hooks")
async function printLeakedEvents(f) {
// Track all active event IDs
const eventIDs = new Set()
# I don't really see any services here. What I see is:
# - Normal HTTP boundary stuff (params flash, redirect).
# - Model creation and retrieval.
# - Warden manipulation, which is an odd done but smells like boundary.
#
# I left all of the HTTP boundary stuff in the controller (and only the
# controller). I moved the model creation/retrieval into simple class methods
# in the models. I moved the warden manipulation stuff into
# ApplicationController (with caveats that I'll discuss inline).
#
@garybernhardt
garybernhardt / gist:c2fceef67bcba989b2742dad88c9170b
Created September 17, 2018 18:34
Automatically fix rubocop errors, with one commit per error
rubocop | egrep ' (W|C): ' | cut -d ' ' -f 3 | sort -u | sed 's/:$//' | while read cop; do
git checkout .
rubocop -a --only "$cop";
if [[ $(git diff --stat) != '' ]]; then
git add --all
git commit -m "fix rubocop cop $cop"
fi
done
#!/usr/bin/env ruby
require 'base64'
require 'nokogiri'
require 'uri'
def main
html = Nokogiri::HTML($stdin.read)
inline_all_images(html)
inline_all_css(html)
# Has your OS/FS/disk lost your data?
# cd to the directory containing your project repositories and run the command
# below. (It's long; make sure you get it all.) It finds all of your git repos
# and runs paranoid fscks in them to check their integrity.
(set -e && find . -type d -and -iname '.git' | while read p; do (cd "$(dirname "$p")" && (set -x && git fsck --full --strict)); done) && echo "OK"
# I have 81 git repos in my ~/proj directory and had no errors.
#!/usr/bin/env ruby
# This script tests par2 recovery when the par2 files themselves are corrupted.
# Process:
# 1. Generate a file containing all 256 possible bytes.
# (More would be better, but it gets slow fast.)
# 2. Generate par2 data for the file.
# 3. Individually corrupt each par2 file at each offset.
# (Write byte 0 unless the offset already contains byte 0; then, write byte 255.)
# (Writing each possible byte would be better, but it gets slow fast.)
# This is a stripped-down example based on Selecta's TTY handling. We store the
# TTY state in `tty_state`, then go into an infinite loop. When the loop is
# terminated by a ^C, we try to restore the TTY state. It's important that this
# work, but it doesn't in some subtle situations, and I don't know why.
#
# Save this file as test.rb and run it via this command, where `stty` should
# successfully restore the TTY state:
# bash -c 'echo | ruby test.rb'
#
# Next, run it via this command, where `stty` should fail to restore the TTY
Turning The Design Clock Back
Object-oriented design principles haven't had the effect we hoped for. The
SOLID principles are excellent design guidelines, but experience shows that
programmers find them difficult to follow. What do we do about this?
Surprisingly, the Structured Design literature of forty years ago contains
compelling solutions to many current design problems. They're simple and easy
to understand, but were lost in the noise as OO rose to popularity. We'll
reinterpret these simple design ideas in a modern context, finding that many of
our most promising new design ideas resemble them. Rapid web application