Skip to content

Instantly share code, notes, and snippets.

Michael Hale mikehale

Block or report user

Report or block mikehale

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 csv-to-values.rb
#!/usr/bin/env ruby
# Read CSV data from STDIN, output a WITH clause containing the CSV data
require 'csv'
csv = CSV.parse($stdin, headers: true, converters: :numeric, header_converters: :symbol)
columns = csv.headers.join(",")
cte_name = ENV.fetch("CTE_NAME", 'temp')
mikehale /
Last active Jan 24, 2018
Share file descriptors between processes on the same machine using unix domain sockets. Thanks to for the inspiration.


Open 2 terminals, run server.rb in one and client.rb in the other. The tcp socket file descriptor will be created in the client, passed to the server, and then used in the server to read from the HTTP server.

View install-binary-on-heroku
curl -L | tar -zxv --strip-components 1 -C /app/bin
View gist:3699b64a007834200c4d7823d3ad069c
set -x
# A single user has 5000kbit upload for himself. But they want prioritizing.
# Variables
TC=$(which tc)
IPT=$(which iptables)
View script to run psql from url in env
`ruby -ruri -e 'uri = URI.parse(ENV["DATABASE_URL"]); puts %(env PGPASSWORD=#{uri.password} psql --dbname=#{uri.path[1..-1]} --host=#{} --port=#{uri.port} --username=#{uri.user} --no-password)'`
mikehale / gist:7a66ba17ba9f074046d9
Last active Aug 29, 2015
restore old syncthing versions
View gist:7a66ba17ba9f074046d9
# Specific dir
cd ~/Sync/.stversions
cp foo ~/Sync/foo
cd ~/Sync/foo
find . -name '*~20150604*' -type f |ruby -rfileutils -e 'mappings =$/).map{|s| s =~ /^(.+)~\d{8}-\d{6}(.*)/; d = [$1, $2].join; [s,d]}; mappings.each{|s,d|,d, noop: false, verbose: true)}'
# Scan for version files
cd ~/Sync
find . ! -path './.stversions/*' -name '*~20150604*' -type f
View display-drives
#!/usr/bin/env ruby
# Shows the physical location of each disk
DEVICE_NAME = "sata_sil24"
:scsi_id => 0..12,
:media => 13..20,
:bus => 21..29,
:model => 30..46,
View com.github.jasf.beamoff.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
View exceptions.rb
$ ruby
loop {
exit 1
p $!
raise "foo"
You can’t perform that action at this time.