Recently in programming Category
I've been messing around with OCR for a possible new project. To train Tesseract, I had to decompress and rename a bunch of .tif files. Rather than deal with Photoshop, I decided to hack a little bash script using tiffcp. This also gave me a chance to play with the regex powers of Bash.
#!/bin/bash
for fname in *.g4.tif
do
if [[ $fname =~ (.*)\.g4\.tif ]]done
then
tiffcp -c none $fname ${BASH_REMATCH[1]}'.tif'else
echo "foo"fi
While building out my new lifestream, I ran into a wall, and needed a function to map a variable from one coordinate space (specifically arrays). I remembered that Proce55ing had just such a function. OpenSource Software FTW!
function map(value, istart, istop, ostart, ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));}
During the past week or so, I've been hacking away on iPhone native app dev. It's been a challenge, as I have very little experience with C, C++, much less obj-c. This entry is more a list of points that have helped me become comfortable than anything else - mostly gleaned from the docs put out by Apple.
File extensions
| .h | header files contain class, type, function, and constant declaration |
| .m | source files contain obj-c and c code |
use #import to include header files in source code - they will load files only once (as opposed to #include)
Strings
NSString* myString = @"My String";
Classes
defined in two parts:
interface (declares methods and instance variables, defines superclass)
@interface ClassName : ItsSuperclass
{
instance variable declarations
}
method declarations
@end
implementation (defines the class, contains the meat)
@implementation ClassName : ItsSuperclass
{
instance variable declarations
}
method definitions
@end
Methods
The names of methods that can be used by class objects, class methods, are preceded by a plus sign
+ alloc;
The methods that instances of a class can use, instance methods, are marked with a minus sign:
- (void)display;
Messaging
think of objects as actors
instead of calling an objects methods, send a message to an object requesting it to perform one of its methods and ask for a return
concentrate on behavior
to send a message:
[receiver message]
to recieve:
objc_msgSend(receiver, selector)
... and with arguments:
objc_msgSend(receiver, selector, arg1, arg2, ...)
