Tuesday, June 22, 2010

random points within a circle

Make randomly distributed points within a circle. Circle radius and origin can be anything. Points are validated to be in the range of x,y +/- radius and also to be within radius of the origin.


Thursday, June 3, 2010

PDF object dissection with macruby

irb(main):001:0> framework 'Quartz'
=> true
irb(main):002:0> url = NSURL.fileURLWithPath('/Users/Tim/Desktop/SU.pdf')
=> #<NSURL:0x2006e94a0>
irb(main):003:0> pdf = PDFDocument.alloc.initWithURL url
=> #<PDFDocument:0x2006cf5a0>
irb(main):006:0> select = pdf.findString("Shinya", withOptions:NSLiteralSearch)
irb(main):014:0> pdf.pageCount
=> 18
irb(main):014:0>

puts (PDFDocument.new.methods(true, true) - Object.new.methods(true, true)).sort

PDFDocumentPrintJobTitle
allowsCopying
allowsPrinting
annotationSubclassForClass
beginFindString:withOptions:
beginFindStrings:withOptions:
cancelFindString
cleanupAfterPrintOperation
cleanupFind
commonInit
coreFindString
coreFindStrings
createInfoDictionary
createPageArray
dataDetector
dataDetectorQueue
dataProvider
dataRepresentation
dataRepresentationWithOptions
delegate
didMatchString
documentAttributes
documentRef
documentURL
enqueueDataDetectionForPage:forPDFView:
exchangePageAtIndex:withPageAtIndex:
findOnPage
findString:fromSelection:withOptions:
findString:withOptions:
findStrings:withinSelection:withOptions:
formData
freePDFData
getNearestOutline:forDestination:
getPrintOperationForPrintInfo:autoRotate:
hasMarkupAnnotations
hasOpenPopupAnnotations
hasText
hasTextAnnotations
indexForPage
indexOfLastPageRemoved
initWithData
initWithPDFDocumentRef
initWithURL
insertPage:atIndex:
isEncrypted
isFinding
isLocked
majorVersion
minorVersion
normalizeFindOptions
originalPageCount
outlineItemForSelection
outlineRoot
pageAtIndex
pageClass
pageCount
pageForOriginalIndex
pageFromPageDictionary
pageSubrange
permissionsStatus
quickString
removePageAtIndex
scheduledFindOnPage
selectionForEntireDocument
selectionFromPage:atCharacterIndex:toPage:atCharacterIndex:
selectionFromPage:atPoint:toPage:atPoint:
setAutoRotate:forPrintOperation:
setDelegate
setDocumentAttributes
setDocumentRef
setOutlineRoot
setPageSubrange
setPrintScalingMode:forPrintOperation:
setUseCorePDF
string
unlockWithPassword
useCorePDF
writeToConsumer:withOptions:
writeToFile
writeToFile:withOptions:
writeToURL
writeToURL:withOptions:
=> nil


Thursday, May 20, 2010

OMG, why are there so many Strings in ObjectSpace?!?

hash = {}
ObjectSpace.each_object.collect{|t| t.class}.uniq.each{|cla| hash[cla]
= ObjectSpace.each_object(cla).to_a.length}
hash

{Tiger=>1, Gem::SourceIndex=>1, Gem::Version=>601, String=>57656,
RubyToken::TkNL=>1, Gem::Dependency=>206, Proc=>127, NoMemoryError=>1,
UnboundMethod=>1, IRB::WorkSpace=>1, Rational=>10, Mutex=>1,
Thread=>1, IO=>5, Object=>64965, Binding=>3, Array=>3761, Float=>18,
OptionParser::Switch::NoArgument=>2,
IRB::Notifier::CompositeNotifier=>1, Range=>51, Bignum=>2, fatal=>1,
OptionParser::OptionMap=>2, Gem::CommandManager=>1, IRB::Locale=>1,
RubyLex::TerminateLineInput=>1, Date::Infinity=>2,
Gem::Requirement=>554, SystemStackError=>1, Module=>495, Hash=>130,
YAML::Syck::Resolver=>2, ThreadGroup=>1, Gem::Specification=>173,
IRB::SLex=>1, Gem::GemPathSearcher=>1, File=>2, Class=>438,
IRB::Notifier::LeveledNotifier=>4, RubyToken::TkLPAREN=>1,
OptionParser::List=>1, OptionParser::CompletingHash=>1,
RubyToken::TkRBRACE=>1, Enumerable::Enumerator=>10, Method=>1,
IRB::ReadlineInputMethod=>1, IRB::StdioOutputMethod=>2, RubyLex=>1,
IRB::SLex::Node=>78, Gem::ConfigFile=>1, MatchData=>4,
IRB::Context=>1, Regexp=>353, IRB::Notifier::NoMsgNotifier=>1,
IRB::Irb=>1, Gem::Version::Part=>481, Time=>176}

And if I do:

ObjectSpace.each_object(String).each{|str| hash[str.object_id] = str}

I find that most of these strings appear to be paths to ruby files. I
am curious if everyone has a similarly large set of string objects in
their ObjectSpace, or is this a result of my personalized setup?


Saturday, May 15, 2010

Test Blogo

This was a test.