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 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
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"
fi
done
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($stdin.read)
inline_all_images(html)
inline_all_css(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
fi
mkdir -p static
sass src/sass/main.scss > static/application.css
$(npm bin)/browserify src/js/main.js > static/application.js
View user.py
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: https://github.com/heroku/heroku-cli
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.
View gist:538c8b8111fe68164c26
failbowl:~(master) $ curl 'http://maps.google.com/?saddr=St.%20Petersburg%20Shavrova%2015&daddr=St.%20Petersburg%20Sadovaya%2030&dirflg=r&output=json'
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://maps.google.com/maps?saddr=St.%20Petersburg%20Shavrova%2015&amp;daddr=St.%20Petersburg%20Sadovaya%2030&amp;dirflg=r&amp;output=json">here</A>.
</BODY></HTML>
failbowl:~(master) $ curl 'http://maps.google.com/maps?saddr=St.%20Petersburg%20Shavrova%2015&amp;daddr=St.%20Petersburg%20Sadovaya%2030&amp;dirflg=r&amp;output=json'
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
View gist:b42c020fdea9b504863f
CyBurTaz: i programed my comps memory to read my own lang
RAVERgrl34: LoL... oh muh god!
CyBurTaz: FOXXY STFU
RAVERgrl34: you are a piece of shit!
RAVERgrl34: ROFL
RAVERgrl34: LMAO
RAVERgrl34: oh muh god!
RAVERgrl34: you are lamest mother fucking i have ever seen!
RAVERgrl34: oh muh god, you are lame.
You can’t perform that action at this time.