[% INCLUDE full_header.tmpl title="bits of code - sporkstorms.org" %]
Here you'll find various bits and pieces of code that I think others may find useful. They aren't full-fledged software, and aren't likely to be useful to you if you're not a programmer.
Objective C class
This was written for Yafca, but you might find it useful for other applications. It converts Pinyin marked with digits to proper Unicode with accent marks. (example: "zhong1 wen2" becomes "zhōng wén")
download the files
example.m shows how simple it is to use this class.
AppleScript "Script Menu" script
Apple's script menu comes with a script to combine all browser windows into a single tabbed window. It only combines the front-most tab of each window though, making it entirely useless to me. So I fixed it. This script combines all tabs in all windows into one tabbed window.
Caveats - Safari's "always show tabs" option must be enabled, GUI scripting must be turned on, and (obviously) the script menu must be enabled.
Stick the compiled script in ~/Library/Scripts/Applications/Safari/
(that's the Library in your home folder)
download the compiled script or its source
Objective C class
If you want an NSButton to respond to the arrow keys, your first
instinct will probably be to simply use setKeyEquivalent:.
Unfortunately, it's not this simple. If you've tried this, you found
that the button "clicks" twice every time you push the arrow key.
This is because the button responds to both NSKeyUp and
NSKeyDown.
To work around this, I created a simple subclass of NSButton that
ignores NSKeyUp. To use it follow these steps:
ArrowButton.h
and ArrowButton.m
Interface Builder, make a subclass of
NSButton called ArrowButton; set your
button's "Custom Class" to ArrowButton
awakeFromNib, invoke
[theButton setType:aType] where
theButton is an outlet to your button and
aType is one of ArrowButtonTypeLeft,
ArrowButtonTypeRight,
ArrowButtonTypeUp, or
ArrowButtonTypeDown
Objective C class
NSURLConnection is entirely worthless for making
asynchronous POST requests (probably GET too?). So, I wrote my own
wrapper around the Core Foundation's HTTP functions. It's not going
to handle anything fancy (like authentication), and
isn't meant to. It's served its purpose and done so admirably.
Before you even try to mention CURLHandle...
I hate curl, so naturally I hate that
bloated wrapper around libcurl (don't even try
to reason with me on this :-p)