Skip to content

Instantly share code, notes, and snippets.

require "rubygems"
require "prawn"
require "prawn/measurement_extensions"
Prawn::Document.generate("badge_printing.pdf", :margin_top => 0.5.in) do
# our start_x position for the columns
[0.5, 4].each do |column_width|
# spacing between each "badge"
@wesmaldonado
wesmaldonado / gist:77207
Created March 10, 2009 23:43
Bookmarklet to find any links with tinyurl.com in their name... good for finding random links to click by searching twitter for "tinyurl" then clicking this bookmarklet. Made for my friend Dan who obviously can't waste enough of his time through standard
javascript:(function(){var%20x,n,nD,z,i;%20function%20htmlEscape(s){s=s.replace(/&/g,'&amp;');s=s.replace(/>/g,'&gt;');s=s.replace(/</g,'&lt;');return%20s;}%20function%20attrQuoteEscape(s){s=s.replace(/&/g,'&amp;');%20s=s.replace(/"/g,%20'&quot;');return%20s;}%20x="tinyurl.com";%20n=0;%20if(x!=null)%20{%20x=x.toLowerCase();%20nD%20=%20window.open().document;%20nD.writeln('<html><head><title>Links%20containing%20"'+htmlEscape(x)+'"</title><base%20target="_blank"></head><body>');%20nD.writeln('Links%20on%20<a%20href="'+attrQuoteEscape(location.href)+'">'+htmlEscape(location.href)+'</a><br>%20with%20link%20text%20or%20target%20url%20containing%20&quot;'%20+%20htmlEscape(x)%20+%20'&quot;<br><hr>');%20z%20=%20document.links;%20for%20(i%20=%200;%20i%20<%20z.length;%20++i)%20{%20if%20((z[i].innerHTML%20&&%20z[i].innerHTML.toLowerCase().indexOf(x)%20!=%20-1)%20||%20z[i].href.toLowerCase().indexOf(x)%20!=%20-1%20)%20{%20nD.writeln(++n%20+%20'.%20<a%20href="'%20+%20attrQuoteEscape(z[i].href)%20+%20'">'%20+%20(z[i].inne
class PushIt
def initialize
@whatsits = []
end
def <<(*args)
@whatsits << args
end
require 'rubygems'
require 'appscript'
include Appscript
ab = app("Address Book")
group_name = "Missing Phone Numbers"
if ab.groups['Missing Phone Numbers'].eq(:missing_value)
tell application "Address Book"
make new group with properties {name:"No Phone Numbers"}
repeat with i from 1 to number of items in people
set thePerson to item i of people
if properties of phones of (thePerson) is {} then
add thePerson to group "No Phone Numbers"
@wesmaldonado
wesmaldonado / redis-eventmachine-toy.rb
Created May 14, 2009 18:49
Me learning eventmachine basics... a redis client.
require 'rubygems'
require 'eventmachine'
class RedisClient < EventMachine::Connection
include EM::Protocols::LineText2
include EM::Deferrable
unless defined? Rcrlf
Rcrlf = "\r\n".freeze
jetpack.tabs.onReady(function onNextPage(doc) {
if (!doc.defaultView.frameElement) {
doc.addEventListener('DOMNodeInserted',function(e){
jetpack.notifications.show("Inserted node containing:" + jQuery(e.target).text());
}, true);
jetpack.notifications.show("Loaded " + doc.location.href);
//jetpack.tabs.onReady.unbind(onNextPage);
}
wesmaldonado:~/workspace/logging-redis-appender$ irb
>> require 'lib/logging-redis-appender' #=> true
>> ra = Logging::Appenders::Redis.new #=> Appenders::Redis:0x2de4d4 name"redis"
>> ra2 = Logging::Appenders::Redis.new('floogle') #=> Appenders::Redis:0x2d70da name"floogle"
>> r = Logging.logger.root #=> Logging::RootLogger:0x2d0e6a name"root"
>> r.add_appenders(ra,ra2) #=> Logging::RootLogger:0x2d0e6a name"root"
>> r.info "bloogle" #=> true
>> ra.read #=> [" INFO root : bloogle\n"]
>> ra2.read #=> [" INFO root : bloogle\n"]
>> r = Redis.new #=> #<Redis:0x55b43c @password=nil, @port=6379, @sock=#<TCPSocket:0x55b39c>, timeout5, db0, host"127.0.0.1"
>> class OpenStruct
>> attr_accessor :id
>> end
=> nil
>> os = OpenStruct.new(:id => 1)
=> #<OpenStruct id=1>
>> os.id
=> nil
>> os.id = -1
=> -1
def page_name_defined?( ad_position, options )
return false if !options.include?( "admin_page_name" )
apn = options.fetch( "admin_page_name" )
if options.include?("brand")
bnd = options.fetch("brand")
begin
return $ad_placements["BRANDS"].fetch(bnd).include?(apn)
rescue
return false
end