Skip to content

Instantly share code, notes, and snippets.

@hawx
hawx / Guardfile
Created May 8, 2012 11:47
guard-shell with forking?
module Processes
extend self
def max
@max || 10
end
attr_writer :max
def processes
@processes ||= []
@hawx
hawx / config.h
Created April 9, 2012 16:35
My config for dvtm. Sets ^g as mod key, makes titlebar cyan & removes hash from titlebar
/* curses attributes for the currently focused window */
/* valid curses attributes are listed below they can be ORed
*
* A_NORMAL Normal display (no highlight)
* A_STANDOUT Best highlighting mode of the terminal.
* A_UNDERLINE Underlining
* A_REVERSE Reverse video
* A_BLINK Blinking
* A_DIM Half bright
@hawx
hawx / README.md
Created March 30, 2012 17:34
It's like the people who designed java didn't imagine reading files would be a common task...

SimpleIO

Really who, WHO? designed java. It's so verbose it makes [something verbose] look simple. The designers must have been in a meeting, I guess this can only be the product of a TON of meetings, and they were all like here's an idea "let's make common tasks simple", and some other guy (probably middle-aged, balding with a harley said "yeah, like reading and writing to files". And then everyone in the room gave him the death stare, Dr Cooper style, and one guy just said "what, who needs to do that?". Everyone in the room just nodded like sheep.

Anyway this class makes life easier, less java-like if you will:

@hawx
hawx / instance-class-def.rb
Created March 17, 2012 12:38
Define a instance method with a class method crazy-meta-ness
class Base
def self.method_missing(sym, *args, &block)
send :define_method, sym, (args.empty? ? block : args[0].to_proc)
end
end
class A < Base
intify :to_i
floatify :to_f
end
@hawx
hawx / google.com.js
Created November 4, 2011 16:45
Fix Google Reader, for people who read in All Feeds sequentially with j/k
// for https://github.com/defunkt/dotjs, put in ~/.js/google.com.js
// there may be side effects put I haven't really noticed any
$('body').css('font', '1em/1.5em Georgia, Serif');
$('#top-bar').css('height', '0').css('opacity', '0');
$('#nav').css('display', 'none');
$('#chrome').css('margin-left', '0');
$('#entries').css('padding-right', '0');
$('#viewer-header').css('height', '0');
$('#title-and-status-holder').css('display', 'none');
@hawx
hawx / NOTES.md
Created September 21, 2011 17:02
Run tests for all installed versions of ruby under rbenv

This took a while for me to work out, but essentially you need to remember two things:

  1. everything that needs to be prefixed with rbenv exec
  2. and everything that can be needs to be prefixed with bundle exec as well

The downside to this is that you need to add rake to your Gemfile. Just running rbenv exec rake will not work, for some reason.

@hawx
hawx / destructure.rb
Created September 16, 2011 17:37
Allow methods to use hashes or not as arguments
class Array
def destructure(*arr)
if size == 1 && first.is_a?(Hash)
arr.map {|k| first[k] }
else
self
end
end

Key-Value Store

Simplest key-value store that is usable (I think). Uses the stdlib [PStore][ps] for storage which is not suited to storing large pieces of data, but isn't that the point of a key-value store?

GET / returns a json encoded array of keys (each as strings).

POST /

@hawx
hawx / p_debug.rb
Created July 21, 2011 14:46
Find those debug statements
module Kernel
def p(*arg)
raise StandardError
rescue => e
$stdout.puts "p: #{e.backtrace[1]}"
end
def puts(*arg)
raise StandardError
rescue => e
@hawx
hawx / rspec_all_of.rb
Created March 30, 2011 15:55
All_of matcher for rspec
# Not the best example, but
#
# it "is an array of Hashes" do
# all_of(subject).should be_kind_of Hash
# end
#
class AllOf
def initialize(items)
@items = items