Archive for the ‘Programming’ Category

iPhone 3.0 OS announced; thoughts and reactions

Monday, April 6th, 2009

Update: changed to reflect new iPhone 3G S.

In light of Apple’s recent announcement of what will be coming this summer in the iPhone 3.0 OS, I thought I’d revisit some of my wish lists / complaints from previous posts and recap what’s “solved”, what I’m hoping to see, and what still appears to be broken / missing.
(more…)

History and the exploring of it

Tuesday, August 5th, 2008

I’m not very good at remembering lists of names, dates, and so forth. I think that history is fascinating and agree that it should be studied, lest it be repeated (or forgot), etc. But I’ve always had a hard time with it.

I think that a lot of that has to do with my learning style. I am a pretty visual learner, at least about things like this. Reading history like it’s a story is one thing, but usually it’s a bit too dry and factual to be taken as a story. I’m sure it was with the best intentions that my high school humanities teacher tried to get us to read Michner’s The Source, but it was like pulling teeth at the time.

Below I list some of the ways that I’ve imagined using modern tools like Google Earth or dynamic flowchart-style graphs.

(more…)

Company Browser – an infoviz idea

Wednesday, April 2nd, 2008

Did you ever wonder where your money was really going when you bought your favorite products?

(more…)

Some iPhone app ideas

Saturday, March 8th, 2008

The release of the iPhone SDK has everyone excited, myself included. Here’s some of my app ideas.

(more…)

Compile me a River

Sunday, April 8th, 2007

I like to think that I understand why Apple does Software Updates the way they do. There are choices that have to be made, and it’s often better to err on the side of caution.

I wish that there were a system or process by which I could indicate that I wanted certain libraries left alone — or to more carefully examine what was going to be changed by the updates before they were installed.

Of course, if I were willing to invest more time in the process, then I could patch only the development servers first, see what broke, and run before-and-after diffs to see which files had changed, then apply those patches, and so on and so forth.

But I’m just trying to keep up to date, and most of what I do is not ‘five nines’ mission critical or anything like that.

So I run an update, then I see what it broke. Usually it’s PHP. Apple has written over PHP so… many… times. It’s always with a client library of MySQL that’s like 3.23. (Isn’t version 5 stable by now? It’s kind of sad.)

Anyway, so it makes me mad because even though I’ve written a compiler config script to simplify things, I have to re-run that, and usually there’s a newer, more patched version of PHP, so I say to myself, “Oh, I’ll just get that.” Except then I have to re-apply the stupid PDFlib patch, and of course there’s usually a newer version of that, and I have to download and compile it, then remember how the heck to copy the proper files into the PHP source tree so it’ll compile against the new library, yadda yadda. I’m currently watching that compile in another window…

I’m sure that there are probably much more efficient ways to do what I’m doing, and I fully realize that all I had to do was ‘sudo make install’ over again to just re-put my version of PHP back in place of the one Apple put there. So I guess that this process is a good thing because it forces me to update.

I just wish I could do it on my own time once in a while.

Side rant —

OS X has had this terrific ability to generate and read PDFs built in at a very low level for a long time now. If I were programming in Carbon or Cocoa I’m sure I could take advantage of that in my code. So why do I still need to download PDFlib, which is intentionally vague and cryptic about compiling the ‘Lite’ version, because they want me to buy the full version? Maybe if I looked around I could find some detailed instructions for telling PHP how to compile using some of that built in OS X functionality to produce PDF output, instead of PDFlib. Just a thought…

Omnioutliner to BBCode conversion – my PHP script

Thursday, July 13th, 2006

The following is adapted from an email I sent to the OmniOutliner-users mailing list. I should also add that after fighting with this stupid WP editor, I’m having a very hard time convincing it that I really want to display ‘raw’ html instead of it helpfully converting it right back to entities for me. I also understand that the code is probably very hard to read, so if you’re interested in checking it out, I would recommend that you download the attached file, convert; hopefully that will make much more sense.
In my email, I asked:

Is there an SDK for developing OmniOutliner export plugins? If so, or if not, would there be sufficient interest in creating a BBCode export option from OmniOutliner? Just throwing it out there.

I ask, because I was asked to post some notes I took in OmniOutliner Pro… on a web discussion forum where they use BBCode instead of regular HTML to format stuff.

Embedded lists in BBCode look like this:

[list]Item 1
[list]Item 1a
Item 1b[/list]
Item 2
Item 3
[list]Item 3a
Item 3b[/list]
Item 4

The above would produce this output:

  • Item 1
  • Item 1a
  • Item 1b
  • Item 2
  • Item 3
    • Item 3a
    • Item 3b
  • Item 4
  • Fairly simple and straightforward, but I was kind of racking my brain as to how to get my OmniOutliner document into this format. So I wrote this PHP script, called ‘convert.’ In my example below, I copied this script into my Documents -> planning folder, where I’m keeping the rest of my files.

    ---------------------------------convert----------------------
    #!/usr/bin/php
    
    // Take first command line argument as the filename
    $fa = file($_SERVER["argv"][1]);
    
    $prevtabs = 0;
    
    $ent_table = array("-" => "−", " " => " ", "+" => "√");
    
    // test it out first
    //for ($i=0; $i < 10; $i++)
    
    for ($i=0; $i< count($fa); $i++)
    {
      $match_array = array();
    
      $itworked = preg_match("#^([\t]{0,})(- \[[+\- ]\] )(.*)$#", $fa[$i], $match_array);
    
      if ($itworked)
      {
        $curtabs = strlen($match_array[1]);
    
        $thediff = $curtabs - $prevtabs;
    
        if ($thediff > 0) // means we indented inwards.
        {
          if ($i > 0) // not on the very first line
          {
            print "&#8711; " . $prev_line;
          }
          print str_repeat("[list]", $thediff);
        }
        else if ($thediff < 0)
        {
          if ($i > 0) // not on the very first line
          {
            print "&#8226; " . $prev_line;
          }
          print str_repeat("[/list]", $thediff * -1);
        }
        else // same, no change
        {
          if ($i > 0) // not on the very first line
          {
            print "&#8226; " . $prev_line;
          }      
        }
        // set this as the previous line amount now
        $prevtabs = $curtabs;
    
        $prev_line = "[" . $ent_table[$match_array[2][3]]. "] " . $match_array[3] . "\n";
      }
      else
      {
        // The match failed, so err on the side of caution and print the previous line with a bullet,
        // then set the new previous line to be the whole line we couldn't match
        if ($i > 0) // not on the very first line
        {
          print "&#8226; " . $prev_line;
        }
        $prev_line = $fa[$i];
        // $prevtabs // not gonna change it, hope it stays the same. ack.
      }
    }
    // last line has no children, by definition, so:
    print "&#8226; " . $prev_line;
    
    if ($prevtabs > 0)
    {
      print str_repeat("[/list]", $prevtabs);
    }
    ?>
    -------------------------------------------------------------------

    Usage:

    Export your OmniOutliner document as tab-separated values (a .tsv file. Except OmniOutliner’s export insists on making it end in .txt. Ugh. Can we please get a ‘Hide file extension’ checkbox to uncheck, and then override the default?)

    In the Terminal, change directories to the folder containing this script, and your TSV file.

    unixprompt> cd ~/Documents/planning

    I called my exported file, planning_notes.txt
    And I want my output file called, ‘output.txt’:

    unixprompt> ./convert planning_notes.txt > output.txt
    If it doesn’t work – remember to make the script executable first:

    unixprompt> chmod 755 convert

    If you don’t redirect the output into a file, it will just print right in the terminal
    window, which may be preferred:

    unixprompt> ./convert planning_notes.txt

    [b]∇ [ ] Intro[/b]
    [list][b]∇ [ ] Who are we[/b]
    [list][b]• [ ] and what are our goals while we’re here?[/b]
    [/list]∇ [ ] Thom
    [list]• [ ] Tech Team Director
    • [ ] How can tech team help?
    [/list]
    [/list]
    etc.

    * * *

    Some notes about the code and formatting -

    I chose to use the • entity, whose code is • for all of the ‘leaf’ items, and I decided to use the ∇ (∇) entity, the downward pointing triangle, to represent ‘branches’ (rows with children).

    I did this by not printing each line immediately; instead I saved it until the next time through the loop, where I could see whether the next line indented further. Based on this, I knew whether to make it a bullet or an open ‘disclosure triangle.’ ;)

    After either the triangle or bullet, I kept the square brackets containing either a space (unchecked), a ‘minus’ entity (−) or a “√” (which is √), for a ‘checked off’ item. The conversion table is near the top, in the $ent_table array.

    Note that I commented out a ‘first ten lines only’ version of my for-loop — I’d used that earlier so I could test and see if it would work, before turning it loose on my whole document!

    One frustrating thing was, choosing to start from the tab separated values format didn’t give me any style information. So I still ended up going through my document once it had been exported and converted, and [b]re-bolding[/b] certain lines after the fact. This is obviously not the most ideal solution, but it’s a solution. (I made a custom BBEdit Glossary folder called ‘BBCode’ with a ‘bold’ file in it, simply containing [b]#select#[/b] and I assigned that to a key. Then I selected each line I wanted to bold and hit my hotkey.)

    I started out with a much simpler version of this script, but then I fell victim to ‘feature creep’ and I kept making it better… and now I’m really happy with the results.

    Anyway, hope this script is of use to someone out there.

    SubEthaEdit – BLOGZOT thingy

    Tuesday, April 25th, 2006

    I’m writing about a pretty cool piece of software, SubEthaEdit from CodingMonkeys, which I have used a few times in the past. It’s a collaborative text editor that makes it pretty painfully easy to open a document with one or more people simultaneously, and co-write a document. One person ‘hosts’ the document on their computer and sets access rules, then other people can log in and be given access to only read or to read/write to portions of the file. Pretty nifty stuff.

    It uses a series of color coded sections to show who’s written what and where each person’s insertion point is, and so forth. It also has grep/regexp find and replace, which comes in quite handy, and lots of other nice features.

    So today I overheard someone on an IRC channel talking about this BLOGZOT 2.0 on MacZOT.com thing. Apparently, MacZOT and TheCodingMonkeys will award $105,000 in Mac software through this promotion if myself and a bunch of other folks blog about the software, as I’m doing, just mentioning a few of the things that they like about it. It’s a neat way to get the word out and establish a user base for them. Now, of course, I liked it when the thing was free, but I understand that these guys have got to make a living. And I hope that they continue to make strides forward with new features and bug fixes.

    Cocoa Books

    Tuesday, April 19th, 2005

    I just received my new copy of Aaron Hillegass’ “Cocoa Programming for Mac OS X,” second edition. Also got Scott Anguish (et al)’s “Cocoa Programming,” but haven’t really started digging into that yet.

    I’m glad I got the second edition because it has a chapter on making apps scriptable, something I plan on doing to vdVHS one of these days… all in all it’s well-written and makes things pretty clear (to me anyway.)

    foreach his own

    Friday, March 18th, 2005

    I recently did a system software update in which Presumptuous Apple decided to once again clobber the PHP install. I really dislike how arrogant that is; they just assume that the version they compiled will have anything you could possibly want, so they don’t check to see whether the currently installed version is in any way different from that last one they think they installed, etc. Bleah.

    Anyway, enough with the sidebar. I recompiled PHP and got it working, in 4.3.10, only to realize that some of my code was broken now. Great. Further investigation revealed that code which looks like this:

    $php_devs = array(“Zeev”, “Andi”);
    foreach($php_devs as $this_jerk)
    {
    print $this_jerk . “\n”;
    }

    …will fail. In previous versions of PHP, the variable $this_jerk from this example would be a string, and the code above would work. But now, the variable $this_jerk is apparently being assigned an array, which would look something like,

    (0 => “Zeev”, 1 => 0)
    (0 => “Andi”, 1 => 1)
    etc, etc.

    So I am forced now to go back and find all of my code containing foreach statements, and change it so it will look like this:

    foreach($php_devs as $crap_index => $this_jerk)

    and that will work. Obviously, ‘$crap_index’ is a throwaway, since I don’t care about the index.

    I could understand if this were done with great fanfare and many warnings, in PHP5. And from looking into it, it appears as if this were backported into the PHP4 source tree as an attempt to make the code execute more quickly. But to break existing code like that? That’s just moronic, and it makes me want to do less with PHP.

    Virtual DVHS, Part III

    Friday, March 18th, 2005

    So I hacked in the menu items, and they worked fine… sort of. I clicked ‘Play’ (or pick the menu item… or hit ‘P’, heh heh) while Input 5 (compy) was selected, and the i.Link mode ‘took over’ the display. Sweet. Then I hit ‘Stop’ (Actually, I had to press ‘S’, etc.) and it stopped. Sweet.

    Except when it stopped, it didn’t return to the last Input. It just went to the digital TV tuner. Which I guess makes sense, because i.Link MPEG Transport Stream decoding is almost the same thing as showing live digital TV, there’s just a slightly different source for the stream.

    This made me realize that the last thing I wanted to add was the integration of serial port control, strictly optional of course… since I’d already had success with that. But I opted to make it a little more generic, in case anyone else wants to use this for some other purpose.

    I added a few NSStrings to hold paths to a user’s ~/bin directory, plus ‘vdvhs_on_stop’ or ‘vdvhs_on_play’, and matching bools to note whether there was an executable at that location. The applicationDidFinishLaunching method is where those checks are performed.

    Then I created methods to execute the shell scripts, if they existed, by using the system() call. I initially had problems with these because I didn’t realize I had to retain the strings after I set them. So I was having an autorelease problem. Trying to access my NSStrings’ contents, and conver them to cStrings, was causing the program to crash with signal 11, SIGSEGV. When I went in with the debugger, I was able to see that the contents of my NSString was ‘Invalid’, and that was a big clue.

    Once that was fixed, it worked pretty well! I’m on the fence about whether to use the ‘play’ script in my personal setup; if you switch to i.Link mode using the remote, or serial controls, it puts up the on-screen transport control (play, pause, etc.) and that’s kind of annoying. I did program the universal remote with the i.Link button (so as to get it off the screen) but I don’t know if I’ll use it that way or just disable the ‘play’ command shell script. Either way, I was pretty geeked when stopping the program also switched the TV’s Input back to the Mac. So, mission accomplished!

    This is fun, but also kind of scary. I actually found myself looking over this page, which is Seth Mattinen’s recounting of his own experiences hacking on vdVHS, and wondering, “Hmm, how would *I* implement those features… wonder if he’d give me some advice…” Heh.