Skip to content

Instantly share code, notes, and snippets.

@robmiller
robmiller / rows2cols
Last active August 29, 2015 14:05
rows2cols — transpose rows of text into columns, with custom separators. e.g. `rows2cols -c 3 -s ' '` will convert "foo\nbar\nbaz\nfoo\nbar\nbaz" to "foo bar baz\nfoo bar baz". Works on files and standard input
#!/usr/bin/env ruby
def run
ARGF.each_slice($options[:columns]) do |values|
puts values.map(&:chomp).join($options[:separator])
end
end
require "optparse"
@robmiller
robmiller / png.rb
Last active August 29, 2015 14:05
A parser for PNG files, for my own education.
require "zlib"
class Png
class ChunkError < StandardError; end
attr_reader :filename, :file, :signature, :chunks
SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a].pack("C8")
def initialize(filename)
@robmiller
robmiller / keybase.md
Created September 23, 2014 17:38
keybase.md

Keybase proof

I hereby claim:

  • I am robmiller on github.
  • I am robmil (https://keybase.io/robmil) on keybase.
  • I have a public key whose fingerprint is 56A1 8D07 7155 50C6 2AAF 00D1 6524 6485 80D1 168E

To claim this, I am signing this object:

@robmiller
robmiller / refresh-skim.scpt
Created November 24, 2014 13:33
An AppleScript to tell Skim to refresh the PDF with the given filename. I use it with `rego` (https://github.com/ahoward/rego) to automatically regenerate and then refresh the PDF whenever my source files change.
tell application "Skim"
repeat with n from (count of documents) to 1 by -1
set doc to document n
-- change "book-screen.pdf" to the filename of the PDF
-- that you want to refresh
if name of doc is "book-screen.pdf" then
revert doc
end if
end repeat
end tell
@robmiller
robmiller / Guardfile
Last active August 29, 2015 14:12 — forked from Integralist/Guardfile
require "terminal-notifier-guard"
guard :shell do
watch(/src\/(.*\/)?(.*)\.rs$/) do |path, folder, file|
p "Path: #{path}"
p "Folder: #{folder}"
p "File: #{file}"
binary_name = File.read("Cargo.toml")[/name = "(.*)"/, 1]
@robmiller
robmiller / gist:ce072c37df914adec0ac
Last active August 29, 2015 14:19
Ruby one-liner to replace URLs in a CSV with their bitly-shortened versions. Assumes you have a bit.ly account
$ gem install bitly
$ export BITLY_USERNAME="your bit.ly username" BITLY_API_KEY="your bit.ly API key"
$ ruby -rcsv -rbitly -e 'b = Bitly.new(ENV["BITLY_USERNAME"], ENV["BITLY_API_KEY"]); CSV.filter { |r| r.each { |f| f.replace b.shorten(f).short_url if f =~ /^https?:/ } }' urls.csv > urls.shortened.csv
@robmiller
robmiller / cleanup-users.zsh
Created September 21, 2015 11:58
Delete unwanted users from your system (prompts before each one)
for user in $(cat /etc/passwd | cut -d: -f1); do; read "DELETE?Delete $user? "; [[ "$DELETE" =~ ^[Yy]$ ]] && echo "Removing $user"; done
extern crate plist;
use std::process::Command;
use std::io::{Read,Seek,SeekFrom,Cursor};
use plist::StreamingParser;
fn main() {
println!("Profiling system.");
let profiler = Command::new("system_profiler")
@robmiller
robmiller / gist:3153350
Created July 20, 2012 21:25
The Nexus 7

I've only spent half a day with it, but my first impressions are thus. It's partly about Android, since this is my first Android device, and partly about the Nexus itself.

The good

  • It's small! It's comfortable to hold in one hand, and the keyboard is a great size — where touchscreen phones are too small for proper two-thumbed typing, and where it can sometimes (with my tiny hands at least) be occasionally difficult to reach the middle of the keyboard on iPad, I've found the keyboard on the Nexus to be a great size. Swype adds some icing to the already-nice cake.

  • Build quality is excellent; it has a satisfying heft without being heavy, the leathery-plastic back is nice and grippy, and it just generally feels solid and well-constructed — in absolute terms, not just for its price point.

  • The screen is lovely; side-by-side with a retina iPad it's perhaps slightly inferior but as general usage goes it's an absolute pleasure. When you consider the cost, it's absolutely phenomenal.

@robmiller
robmiller / gist:4037534
Created November 8, 2012 08:22
Error when installing consular-iterm gem
This file has been truncated, but you can view the full file.
ERROR: Error installing consular-iterm:
ERROR: Failed to build gem native extension.
/Users/rob/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
extconf.rb:44: Use RbConfig instead of obsolete and deprecated Config.
create /Users/rob/.rvm/gems/ruby-1.9.3-p194/gems/rb-appscript-0.6.1/src/osx_ruby.h ...
create /Users/rob/.rvm/gems/ruby-1.9.3-p194/gems/rb-appscript-0.6.1/src/osx_intern.h ...
creating Makefile
make