Skip to content

Instantly share code, notes, and snippets.

View ahoward's full-sized avatar
💭
probably outside if i'm not hacking.

ara.t.howard ahoward

💭
probably outside if i'm not hacking.
View GitHub Profile
@ahoward
ahoward / a.rb
Created February 28, 2014 19:29
message passing to processes, threads, or any combination is über simple in ruby
# it's easy, in ruby, to setup a worker farm that utilizes processes, threads,
# or any combination. the following code sets up three processes, each with
# three worker threads, and a super simple, message passing api, to send
# messages to any process, which will use one of it's threads to do work
#
#
slaves = Array.new(3){ Slave.new{ Worker.new }}
workers = slaves.map(&:object)
a, b, c = workers
@ahoward
ahoward / favicon.sh
Created March 10, 2014 15:03
~/bin/favicon
#! /bin/sh
# file : ~/bin/favicon
#
# usage: favicon foo.png
convert "$@" -resize 16x16 favicon-16.png
convert "$@" -resize 32x32 favicon-32.png
convert "$@" -resize 64x64 favicon-64.png
convert "$@" -resize 128x128 favicon-128.png
class Trash
include Mongoid::Document
field(:type => String)
field(:data => Hash)
index(:type => 1)
def Trash.destroy(document)

you say this

but the url resolves

a:~ $ curl --dump-header /dev/stderr http://orgdev.com/fonts/146266
HTTP/1.1 200 OK
@ahoward
ahoward / a.sh
Created April 9, 2014 18:15
listing of ahoward's ruby gems
# ruby -r gems -e 'puts Gems.gems.map{|g| g["name"]}.sort'
alib
arrayfields
attributes
autorequire
bj
coerce
configuration
dao
a:~/git/mongoid/mongoid $ ruby -r mongoid ~/a.rb
3.1.6
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (0.7300ms)
MOPED: 127.0.0.1:27017 COMMAND database=test command={:count=>"tables", :query=>{}} (0.2592ms)
MOPED: 127.0.0.1:27017 INSERT database=test collection=rooms documents=[{"_id"=>"5361d11faf481ca059000001"}] flags=[] (0.0758ms)
MOPED: 127.0.0.1:27017 INSERT database=test collection=tables documents=[{"_id"=>"5361d11faf481ca059000002", "parent_id"=>"5361d11faf481ca059000001", "parent_type"=>"Room"}] flags=[] (0.1209ms)
MOPED: 127.0.0.1:27017 QUERY database=test collection=tables selector={:_id=>"5361d11faf481ca059000002"} flags=[] limit=-1 skip=0 batch_size=nil fields=nil (0.2699ms)
MOPED: 127.0.0.1:27017 UPDATE database=test collection=tables selector={"_id"=>"5361d11faf481ca059000002"} update={"$push"=>{"chairs"=>{"_id"=>"5361d11faf481ca059000003"}}} flags=[] (0.0961ms)
MOPED: 127.0.0.1:27017 UPDATE database=test collection=t
module SafeAttr
def SafeAttr.included(other)
other.send(:extend, SafeAttr::ClassMethods)
super
end
module ClassMethods
def code_for(name, options = {})
code = []
class Model
def Model.new(*args, &block)
allocate.instance_eval do
@attributes = {}
initialize(*args, &block)
self
end
end
@ahoward
ahoward / a.rb
Last active August 29, 2015 14:01
# make this script run, update your gist with the running script, and it's
# output in a separate gist. the entire quzi should take 1-3 minutes, but you
# get 5.
#
# the meat - take < 5 minutes to do this
#
assert :hash do
x = nil
@ahoward
ahoward / a.rb
Last active August 29, 2015 14:01
make it print all 'true'
# fork it
#
# make it print all true with only ONE LINE OF CODE
class A
def A.foo
@foo ||= (
if self == A
'42.0'
else