Skip to content

Instantly share code, notes, and snippets.

Gary Bernhardt garybernhardt

Block or report user

Report or block garybernhardt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:55254ce390b87b2121cee69f1c2f61f6
function f() {
switch (x) {
case "1":
case "2":
return <div>
View gist:2f9dc11d5548943b8ac118341aa8bac9
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',
View print-leaked-events.js
// 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()
garybernhardt / gist:c2fceef67bcba989b2742dad88c9170b
Created Sep 17, 2018
Automatically fix rubocop errors, with one commit per error
View gist:c2fceef67bcba989b2742dad88c9170b
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"
View test.rb
#!/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.)
View inline.rb
#!/usr/bin/env ruby
require 'base64'
require 'nokogiri'
require 'uri'
def main
html = Nokogiri::HTML($
View types.markdown

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

View rebuild
#!/usr/bin/env bash
set -e
if [ -e static ]; then
rm -r static
mkdir -p static
sass src/sass/main.scss > static/application.css
$(npm bin)/browserify src/js/main.js > static/application.js
from collections import namedtuple
from datetime import date
# Here's a user defined using the usual "OO" style.
class UserClass:
def __init__(self, first, last, birthday):
self.__first = first
self.__last = last
self.__birthday = birthday
View gist:d6fa87a32ecca791ac7a
$ heroku pg:backups
Installing Heroku Toolbelt v4... done.
For more information on Toolbelt v4:
Setting up node-v4.1.1... done
Installing core plugins heroku-cli-addons, heroku-apps, heroku-fork, heroku-git, heroku-local, heroku-run, heroku-status...
Error reading plugin: heroku-apps. See /Users/grb/.heroku/error.log for more information.
Error reading plugin: heroku-cli-addons. See /Users/grb/.heroku/error.log for more information.
Error reading plugin: heroku-fork. See /Users/grb/.heroku/error.log for more information.
Error reading plugin: heroku-git. See /Users/grb/.heroku/error.log for more information.
You can’t perform that action at this time.