Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gist:214b3adf820b41a847c2
Last active August 7, 2022 18:53
Text processing tutorial: splitting files, rows to columns, line endings

For this tutorial, we have the following brief. That is: to take a file that contains many millions of lines of text, each one of them a single column — something that looks like this:

POPLKLMNE
GKITLOPOM
QASSLKOPI
== snip ==

...into multiple text files, each with a fixed number of lines in them, each with — instead of one column per line — several columns, separated with a comma. In other words, something that looks like this:

POPLKLMNE,GKITLOPOM,QASSLKOPI
@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 / 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 / code-generator.rs
Created July 30, 2014 09:45
Random code generation in Rust
use std::rand::{task_rng, Rng};
use std::os;
use std::collections::hashmap::HashSet;
fn main() {
let num_threads = 8u;
let args = os::args();
let usage = "Usage: code-generator NUMCODES CODEFORMAT";
@robmiller
robmiller / 003.rs
Last active August 29, 2015 14:03
Project Euler #3 in Rust
struct PrimeStream {
current: int
}
impl PrimeStream {
fn new() -> PrimeStream {
PrimeStream { current: 1 }
}
}
@robmiller
robmiller / metakoans.rb
Created June 19, 2014 18:27
Solution to Ara T. Howard's metakoans.rb Ruby Quiz: http://rubyquiz.com/quiz67.html
class Module
def attribute(attribute, &block)
case attribute
when Hash
name = attribute.keys.first
default = attribute[name]
when String, Symbol
name = attribute
default = nil
end
@robmiller
robmiller / gist:d32dc4826639b69c92e7
Created May 23, 2014 15:08
Script, designed to be run on a cron job, to scan for files (in this case PHP files) that have been modified and notify a Slack channel with the changes. Just for information, not for proper intrusion detection or anything
#!/usr/bin/env ruby
require 'net/http'
require "json"
require "pathname"
require "logger"
class Slack
attr_reader :account, :token, :channel
@robmiller
robmiller / golf.rb
Last active August 29, 2015 14:00
Yammer Ruby Hacknight Golf
class<<Golf=Class.new
n=0;'a.reduce :*
(?a..?z).to_a
(1..a).reduce :*
a.map{|s|z=s[0];z==?m?"hat(#{s})":z==?d?s[0..-2]+"(bone))":"dead"+s[3..-1]}
(1..4).flat_map{|n|a.each_cons(n).to_a}
(1..a).map{|a|a%15<1?"fizzbuzz":a%3<1?"fizz":a%5<1?"buzz":a}
p=0;a.slice_before{|n|t=p+1<n;p=n;t}.map{|n|z="#{n[0]}";n.size>1?z+?-+"#{n[-1]}":z}
i,j=0,1;(1..a).map{i=j+j=i}
a.split.map{|s|s.size>10?s[0,4]+?.*3+s[-3,3]:s}.join" "'