Skip to content

Instantly share code, notes, and snippets.

@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]
#!/bin/sh
ORIGIN=`basename "$0"`
BRANCH=${1:-master}
set -e
git fetch "$ORIGIN"
REV1=`git rev-parse "$ORIGIN/$BRANCH"`
REV2=`git rev-parse "$BRANCH"`
#!/usr/bin/ruby
require 'pathname'
file, project = ARGV.take(2).collect do |p|
if p.empty?
nil
else
Pathname.new(p)
end
class ObjectSocket
BLOCK_SIZE = 4096
def self.pair
Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM, 0).map { |s| new(s) }
end
def initialize(socket)
@socket = socket
end
@wisq
wisq / iterm-vim.rb
Created December 8, 2011 17:21
Run vim in a new iterm tab
#!/usr/bin/ruby
require 'tempfile'
APPLESCRIPT = <<EOF
tell application "iTerm"
activate
tell the first terminal
set new_session to (make new session at the end of sessions)
@wisq
wisq / knife.rb
Created March 7, 2012 05:32
knife 0.9.18 wrapper with suppressed warnings
#!/usr/bin/env ruby
# Optional: Force a particular Ruby version & gemset.
if ENV['BUNDLE_GEMFILE'].nil?
ENV['RBENV_VERSION'] = '1.9.3'
ENV['BUNDLE_GEMFILE'] = "#{ENV['HOME']}/ops/kitchen/Gemfile"
exec('bundle', 'exec', $0, *ARGV)
end
# Suppress iconv deprecation warning.
% ls
cache-fm/ crawl/ git-up/ misc/ ruby-build/ ssh-ride/ zsh-completions/
% ruby -e 'p IO.popen("echo *", &:read)'
"cache-fm crawl git-up misc ruby-build ssh-ride zsh-completions\n"
% ruby -e 'p IO.popen(["echo", "*"], &:read)'
"*\n"