Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
ENCODINGS = `iconv -l`.split(/\s+/)
PAIRS = ENCODINGS.permutation(2)
def iconv(input, from, to)
output = IO.popen(["iconv", "-f", from, "-t", to, :err => :close], "w+") do |fh|
fh.print(input)
fh.close_write
fh.read.force_encoding("ASCII-8BIT")
#!/usr/bin/env ruby
require 'pp'
DEBUG = false
class Board
class Impossible < StandardError; end
class Solved < StandardError; end
@wisq
wisq / gist:0fa021df52a3bd2485ac
Last active April 25, 2024 10:22
Protip: Bisecting a single commit

Situation: Some commit (on master, but not necessarily head of master) has broken things, but it's a big commit and it's not clear what part broke things.

% git checkout master
% git checkout -b bisect-branch
% git revert <offending commit>

(test here to make sure reverting fixed your problem)

% git bisect start
@wisq
wisq / no-env-functions.diff
Created September 25, 2014 23:05
My solution to the bash exploit
diff -ruN a/bash/shell.c b/bash/shell.c
--- a/bash/shell.c 2011-01-02 21:04:51.000000000 +0000
+++ b/bash/shell.c 2014-09-25 21:20:24.656725026 +0000
@@ -1703,13 +1703,8 @@
tilde_initialize ();
/* Initialize internal and environment variables. Don't import shell
- functions from the environment if we are running in privileged or
- restricted mode or if the shell is running setuid. */
-#if defined (RESTRICTED_SHELL)
@wisq
wisq / notes.md
Created June 1, 2015 21:58
Rakefile task for a git pre-commit hook
  • Unlike a lot of pre-commit scripts, it uses only the changes you've staged for commit, and doesn't touch your working tree (stash etc.).
  • I use skip 'slow' if ENV['FAST_TESTS'] == '1' in tests that needlessly slow down everyday rake testing, but this runs them all before commit.
  • Written in 10 minutes. Barely tested. YMMV.
  • See https://github.com/wisq/autocrew/blob/master/Rakefile for the latest version (e.g. if I find any bugs in this).
@wisq
wisq / slowlog
Created June 3, 2015 02:08
Tool to determine 50 slowest & 50 most rows-examined queries in MySQL slowlog
#!/usr/bin/env ruby
Entry = Struct.new(:duration, :rows, :data)
def trim(array, limit, &block)
too_many = array.count - limit
if too_many > 0
array.sort_by!(&block)
array.shift(too_many)
end
#!/usr/bin/env ruby
require 'digest/md5'
def random_hex(length)
bytes_needed = (length + 1) / 2
bytes = $urandom.read(bytes_needed)
hex = ("%02x" * bytes_needed) % bytes.bytes
return hex[0,length]
@wisq
wisq / gist:521731c3395810cb23db
Created November 17, 2015 00:56
Multifox .vimperatorrc snippet
command! home js set_multifox_profile("3");
command! work js set_multifox_profile("2");
" Get the multifox version hash by looking inside the multifox XPI file.
" (Look at the hash it uses in its own imports.)
:js << EOF
Components.utils.import("resource://multifox-88f97b0/commands.js");
function set_multifox_profile(id) {
event = {
target: {
#!/usr/bin/env ruby
require 'tempfile'
KNOWN_HOSTS = ENV['HOME'] + '/.ssh/known_hosts'
read_fh, write_fh = IO.pipe
command = ['ssh', '-oStrictHostKeyChecking=yes'] + ARGV + ['echo', 'Successful connection.']
// ==UserScript==
// @name RPS mixed-content defuckifier
// @namespace rps-img-https
// @include https://www.rockpapershotgun.com/*
// @version 1
// @grant none
// ==/UserScript==
var images = document.getElementsByTagName('img');
var length = images.length;