Skip to content

Instantly share code, notes, and snippets.

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 Feb 28, 2014
message passing to processes, threads, or any combination is über simple in ruby
View a.rb
# 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
View favicon.sh
#! /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
View trash.rb
class Trash
include Mongoid::Document
field(:type => String)
field(:data => Hash)
index(:type => 1)
def Trash.destroy(document)
View broken.md

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 Apr 9, 2014
listing of ahoward's ruby gems
View a.sh
# ruby -r gems -e 'puts Gems.gems.map{|g| g["name"]}.sort'
alib
arrayfields
attributes
autorequire
bj
coerce
configuration
dao
View 3.1.6.txt
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
View sattr.rb
module SafeAttr
def SafeAttr.included(other)
other.send(:extend, SafeAttr::ClassMethods)
super
end
module ClassMethods
def code_for(name, options = {})
code = []
View model.rb
class Model
def Model.new(*args, &block)
allocate.instance_eval do
@attributes = {}
initialize(*args, &block)
self
end
end
View a.rb
# 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 Aug 29, 2015
make it print all 'true'
View a.rb
# 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