Rick DeNatale's complete blog can be found at: http://talklikeaduck.denhaven2.com

Items:   1 to 5 of 55   Next »

Sunday, July 24, 2011

I took the plunge this weekend, and installed Lion on my personal MacBook Pro.

First I made sure I had a bootable backup of my Snow Leopard install. Then I jumped in and pressed the continue button in the Lion installer.

All in all it went rather smoothly. Only one real problem, which I managed to fix, see below.

Lion for the Ruby/Rails developer

When I installed Snow Leopard my development environment was broken. Partly because the install wiped out packages I'd installed with macports, but mostly because of the transition from 32-bit to 64 bit. So far Lion has been much kinder. My brew installed stuff seems to have survived the transition, although I needed to install the XCode 4 update, which is once again free for folks with Lion via the OS X App Store.

Admittedly I haven't pressed very hard on the old development tool chain, but, knock on wood, things look decidedly better the day after the Lion install than they did the last time.

More Flashbacks

A few days ago, I wrote about my pre installation thoughts on Lion. Not that I've been using it for a bit over a day, the new scrolling is a blessing and a curse. Although it does work the same was as my iPad and iPhone, there's a fundamental difference between dragging your finger on the 'page' itself and controlling that 'page' remotely using the trackpad. Some of that is no doubt the result of using a mouse for the past 35 years or so. I'll stick with the Lion way and see what happens, no doubt I'm going to have to learn to adjust back and forth as I use different machines, just like I still have to make an adjustment going from my MBP, to my wife's old MacBook due to the latter having a trackpad button while the newer machine does not.

This dredges up another old memory. Back in the 1980s when the PCs got mouse envy, the initial mice for PCs simply generated cursor keystrokes, and many users thought of mice as just being that, devices to quickly generate up, down, left, and right arrow keystrokes. Nowadays I'd guess that most computer users would think this was a silly idea. In reality, the way the user interacts with a computer is affected in ways both drastic and subtle by the device or devices used. Trackpads are neither mice nor are they touchscreens. Interacting directly with a touchscreen, where your finger is the pointer, and there is no separation between pointing at something and clicking on it, is inherently different than interacting indirectly through a trackpad or mouse. And a multi-touch trackpad is different than a mouse no matter how many buttons the mouse has.

While we're on the subject of scrolling, some apps in Lion. Safari for example, don't show scrollbars until you start to scroll, then when you're done they disappear. I haven't seen this kind of scrollbar behavior since Smalltalk-80. By the way scrollbars work this way in Lion in Textmate!

Oh Yeah, I Did Mention A Problem Didn't I

Just about a year ago I wrote about my my spit and baling wire linux Time Machine server. Well, after the Lion install, my Time Machine backups stopped working.

It took me a while to find the answer, but eventually I found the 'cheat' in this post to the Ubuntu forums.

I also saw reports about problems with Time Machine under Lion and third party commercial NAS products including Drobos

It turns out that Time Machine in Lion is using some new features which Apple put into AFP, the Apple Filing Protocol. Netatalk the open-source implementation of AFP, doesn't support the latest AFP 3.3 protocol, except in a beta version.

The Ubuntu forum article, followed carefully, got me back to having my MBP backing up with Time Machine to my Ubuntu box.

It also pointed to this blog post by the maintainers of Netatalk, dated 2 July, which explained their plan to hold back the source of the final version of Netatalk because "...many corporations are using and making money from Netatalk, but in the past none of these cared that the cow they’re milking gets fed, Netgear Inc. being the one exception, thanks for that." As an open-source contributor who has reaped little in the way of pecuniary reward from open-source, I can understand the sentiment. It does come across as a bit of a ransom note, but they are free to do as they want.

But I suspect Lion turned the tide here as the Netatalk article ends with an update dated 23 July (3 days after the release of Lion) saying "Thanks to the new commitment of Data Robotics, Western Digital Corporation and QNAP, there’s hope! Also, we’re reopening development, pushing all sources to the official Netatalk git VCS at Sourceforge. We expect Netatalk 2.2.0 sourcecode tarballs to be available at the Sourceforge download site soon."


Original article writen by Rick DeNatale and published on Talk Like A Duck | direct link to this article | If you are reading this article elsewhere than Talk Like A Duck, it has been illegally reproduced and without proper authorization.


Thursday, July 21, 2011

So Lion has been downloaded from the App Store and waits to be installed on my personal MacBook Pro. I'm waiting a few days to see how much smoke appears on the horizon as early adopters run into issues.

There are some interesting aspects of Lion, some of which bring back old memories. This should be a quick top of the head article. But I may well follow up with one or more which go down some of these paths in more detail.

I don't want to come across as one of those old codgers, even though I probably am one, who think everything now has been done before. On the other hand, as they say "past is prologue."

I've been reading John Siracusa's excellent, as usual Ars Technica review of Lion. as I get into the technical details I can't help but think about some of my prior experiences

Lion's new Document and Versioning Model

Lion has a new take on saving documents and the lifecycle of applications. OS X 10.7 now keeps a trail of revisions to documents, provides a Time Machine like UI to view the history, and decouples saving documents from quitting the application. It also saves enough application state to make applications appear as if they never had stopped when they are restarted. All the same documents are re-opened in the state where the user left them, etc. Now where have I seen that before?

I've had the pleasure, well usually a pleasure, of working with a couple of programming language environments which worked like this to a large extent. The first of this was APL, another was Smalltalk. The usual implementation of these languages provides a workspace or image which holds not just the source code of programs, but the actual running state. In both you did need to save the image or workspace before quitting, but both would start up again just where you left things. This was more obvious in Smalltalk since it is a graphical environment so there's more visible state.

Another aspect of Smalltalk was that the source code was managed by having meta-information in the class and method objects in the image which simply pointed to the source code which actually 'lived' in a single file. Whenever a method was saved, or class definition was saved, the changes were simply appended to this 'change log' in chunks, which were just code fragments which could be compiled or evaluated. The browsers just used an index saved in say a method object to determine the offset of the methods source code in the change log.

Of course it wasn't long before people started to build tools to go back and look at, old versions of methods and class definitions. At IBM in the early days, we used a change log browser written by either Jerry Archbald or David N. Smith, actually probably by the pair.

Later things got more sophisticated, OTIs Envy developer provided concurrent access to what was effectively a shared change log and provided both version and configuration control to teams of Smalltalkers. Today Smalltalkers use tools like Monticello which looks to me to be the logical successor to Envy.

Today, many developers, including your humble author, use git as the weapon of choice for version control. A common thread is the use of a write only repository. A little bit more sophisticated than a single linear change log, but ...

Lion's document model appears at first blush to be related. I saw someone speculating on Google+ about whether Lion might be using git. Somehow I doubt it, but I'm sure it was an influence.

The UI in Lion for browsing the history of a document looks pretty cool. I wonder if something like that would work for git?

Garbage Collection

One of the exciting things I had heard about Lion was that it would be improving the recently added garbage collection in Objective-C. As I read the garbage collection section of the Ars Technica report, which comes right after the section on security which got me all excited, my excitement started to fade a bit.

As Siracusa explains it, the Objective-C "garbage collector", which is really called "Automatic Reference Counting" or ARC, looks more like automatic generation of the formerly manual retain and release pragmas used in Objective-C programs before ARC.

The problem with hybrid languages like Objective-C, or C++, which have both managed and non-managed memory objects, is that the garbage collector can't tell whether a 'pointer' in a non-managed memory block which happens to hold the address inside a managed object space, really references a managed object or not, it might just be an integer, or a consecutive run of bytes in a string.

The real memory kicker for me was when in this section Siracusa pointed to a a series of articles he has written for Ars over the years, calling for Apple to move from Objective-C to a language or languages with truly automatic memory management.

Siracusa uses Apple's Copland operating system project, as an example of failure partially caused by not having automatic memory management when it is called for.

The predecessor of Copland was Pink, which was to be the new Mac operating system written in C++, and providing an application API in the form of a framework. There were lots of such plans floating around the industry back then, Microsoft had a similar project, and IBM was looking at all of these, along with Steve Jobs NeXTStep. Because of what I was doing at the time, I found myself on a series of IBM corporate task forces, and I got to visit the Pink developer team, which was cool since they were living in the Bandley 3 building which had been occupied by the band of pirates put together by Steve Jobs to develop the original Macintosh. A lot of those goodies were still there, including the Bösendorfer grand piano.

I had some interesting meetings with lots of interesting people at that time, including Steve Jobs, and Bill Gates.

In talking with the Pink developers, it was obvious that they were suffering from a lack of GC, they talked about all the rules they had for using C++ constructors and destructors at method interfaces, which led to a lot of code bulk, and sub-optimal performance. That's a whole story in itself, but I totally agree with Siracusa here.

For what it's worth, Apple pushed Pink off onto a new joint venture with IBM called Taligent, with IBM investment and management. Taligent eventually failed. In the meantime, what was left of Pink at Apple morphed into Copland, only to be killed when Ellen Hancock, who I used to work under at IBM before she was lured away to National Semiconductor by Gil Amelio who then left his CEO job at National Semi to become CEO at Apple and lured her away again.

Hancock was hired to save Copland but decided it was hopeless, and started a search for a replacement. Eventually NeXTStep was chosen for the replacement bringing Jobs back to Apple.

NeXTStep, which was written in Objective-C is the main gene pool for today's OS X Cocoa.


Original article writen by Rick DeNatale and published on Talk Like A Duck | direct link to this article | If you are reading this article elsewhere than Talk Like A Duck, it has been illegally reproduced and without proper authorization.


Friday, July 15, 2011

One of my current work rails projects at SciMed Solutions has a requirement to use an Oracle database.

I just spent a frustrating day or so installing Oracle on my MacBook running the current Snow Leopard. One of my colleagues suggested this how-to blog article by Raimonds Simanovskis, to which all roads starting from a google search "install oracle snow leopard" seem to lead. He said it worked for him, with no problems not too many days before.

Not so for me. I'm not sure why, but I had lots of problems getting Oracle to create a database. First I ran into permissions problems, perhaps from missing something in Ray's excellent walk-through, then I had to deal with problems getting the Database Configuration Assistant to talk to the server when creating the first database.

I eventually found another article which gave the solution to this problem, once I figured out what it was saying, and where and when in the installation process to make the crucial patch.

So to document this, and hopefully save some frustration for others, here's what I did.

Background

As far as I know, the only version of Oracle for OS X which has ever been released is "Oracle Database 10g Release 2 (10.2.0.4.0) for MAC OS X on Intel x86-64" which was released shortly before Apple released Snow Leopard(10.6), and which won't work on OS X 10.6 without tweaks. The main source of information on these tweaks is Ray's blog article, but that article is nearly two years old at the time of this writing, and things have changes a bit in Snow Leopard since then.

My steps

  1. I already have Xcode installed. If you don't you'll need it.
  2. Follow along with the first steps of Ray's blog article, to create an oracle user, oinstall group, create a home directory for the oracle user, and set the oracle user's password, using the dscl, mkdir, chown, and passwd commands.
    sudo -i
    dscl . -create /groups/oinstall
    dscl . -append /groups/oinstall gid 600
    dscl . -append /groups/oinstall passwd "*"
    dscl . -create /users/oracle
    dscl . -append /users/oracle uid 600
    dscl . -append /users/oracle gid 600
    dscl . -append /users/oracle shell /bin/bash
    dscl . -append /users/oracle home /Users/oracle
    dscl . -append /users/oracle realname "Oracle software owner"
    mkdir /Users/oracle
    chown oracle:oinstall /Users/oracle
    passwd oracle
          
  3. Again following Ray's article, edit /etc/sysctl.conf to add the kernel parameters recommended by Ray:
    kern.sysv.semmsl=87381
    kern.sysv.semmns=87381
    kern.sysv.semmni=87381
    kern.sysv.semmnu=87381
    kern.sysv.semume=10
    kern.sysv.shmall=2097152
    kern.sysv.shmmax=2197815296
    kern.sysv.shmmni=4096
    kern.maxfiles=65536
    kern.maxfilesperproc=65536
    net.inet.ip.portrange.first=1024
    net.inet.ip.portrange.last=65000
    kern.corefile=core
    kern.maxproc=2068
    kern.maxprocperuid=2068
          

    Note that using "sudo -i" in the prior step left the shell in sudo mode, you might prefer as I did, to use sudo for each command instead.

  4. Ray's next step, to create a symbolic link so that Java version 1.4.2 will resolve as Java version 1.5.0 is no longer needed nor desirable. Since the article was written, shortly after Snow Leopard release (possibly using a developer pre-release at that), OS X 10.6 already does that link albeit in a slightly less direct manner.
  5. Pro-Tip: I you haven't set it already, while you are still logged in as an admin user, you might want to use System Preferences>Accounts>Login Options, and turn on the "fast user switching menu" which lets you log in as multiple users without logging out from the existing user.
  6. Reboot to make the kernel parameter changes take effect, and then log in as the oracle user.
  7. Now I edited /Users/oracle/.bash_profile as directed by Ray. Actually I'm pretty sure you might as well go ahead and make the latter changes to this file as well at this point. I had to retry the installation several times, removing installed directories and such, but never altered .bash_profile again after the first time. So here is the full .bash_profile for the oracle user:
    export DISPLAY=:0.0
    export ORACLE_BASE=$HOME
    umask 022
    ulimit -Hn 65536
    ulimit -Sn 65536
    
    export ORACLE_HOME=/Users/oracle/oracle/product/10.2.0/db_1
    export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
    export ORACLE_SID=orcl
    PATH=$PATH:$ORACLE_HOME/bin
        
  8. Next I executed the bash profile, alteratively you could open a new terminal window.
  9. The next step was to download the oracle software. The link in Ray's article is obsolete, you want "Oracle Database 10g Release 2 (10.2.0.4.0) for MAC OS X on Intel x86-64" which can be found here.
  10. Now unzip the db.zip file and cd to db/Disk1, as per Ray
  11. Now run the installer make sure you run it with the -J-d32 optionI kept forgetting this when I made my various attempts.
    ./runInstaller -J-d32
  12. You should see the error Ray mentions “Error in invoking target ‘all_no_orcl ipc_g ihsodbc32’ …” (message truncated). Follow his instructions, don't press any buttons in the warning dialog. Leave the installation program running, and edit the file ~/oracle/product/10.2.0/db_1/rdbms/lib. Find the line containing "$(HSODBC_LINKLINE)" and comment it out with a hash("#").
  13. Now we come to the patch in the second article, which fixes the ORA-03113 error when you try to create a database later. The oracle server is crashing because without this patch it's being built incorrectly for Snow Leopard, something you might never know from the error message unless you happened to look at ~/Library/Logs/CrashReporter in the OS X console app. The reason we needed to wait to edit this and the last file is that they are apparently created by the installer. I guess it's a lucky thing that the $(HSOBC_LINKLINE) problem is there, otherwise it would be much more difficult to fix this. So edit the file "$ORACLE_HOME/rdbms/lib/env_rdbms.mk" find the line which sets the variable ORACLE_LINKER, and insert the parameters "-mmacosx-version-min=10.5 -Wl,-no_compact_linkedit" after the -flat-namespace parameter so you end up with:
    ORACLE_LINKER=gcc -flat_namespace -mmacosx-version-min=10.5 -Wl,-no_compact_linkedit $(OLAPPRELINKOPTS) $(LDFLAGS) $(COMPSOBJS)
  14. Now go back to the installation program and press the retry button.
  15. At the end of the install process copy the command it asks you to run as root, which should be "/Users/oracle/oracle/product/10.2.0/db_1/root.sh". Then either in the same terminal window/tab or a new one use the su command to switch to your regular admin user with sudo privileges and run it the command by either pasting it or typing it after sudo:
    su - username
    sudo /Users/oracle/oracle/product/10.2.0/db_1/root.sh
          

    Substitute your user name for username.

    If you didn't open a new window or tab for this use the exit command to get back to the oracle user.

  16. You should now be at the "Creation of Database" step in Ray's how-to. We already made the additional changes to /Users/oracle/.bash_profile, so we can skip that step.
  17. You do need to modify $ORACLE_HOME/jdk/bin/java and add the -d32 parameter to the java command. This was another step which I forgot several times in my repeated re-tries, since it isn't really highlighted well enough in Ray's article for my aging eyesight.
  18. Now run netca and select all the default options as Ray suggests. Again, as I made my repeated attempts netca would tell me that the listener already existed, I then used netca to delete the listener and created it again. This is the kind of thing I'm trying to save you from by documenting these steps.
  19. Now run dbca and follow Ray's selections. through running sqlplus to verify that you can connect to the new database.

I haven't made any other of the changes in Ray's article, yet. But...

Giving access to Oracle from YOUR user

In order to get at the oracle database and use the oracle commands like sqlplus, you need to do two things:

  1. Set the same environment variables in your shell environment, either by adding them to .bash_profile, or whereever you set your shell environment variables. Again these are:
    export ORACLE_BASE=$HOME
    export ORACLE_HOME=/Users/oracle/oracle/product/10.2.0/db_1
    export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
    export ORACLE_SID=orcl
    PATH=$PATH:$ORACLE_HOME/bin
                

    I don't think you need to export your X11 display, or use the umask and ulimit commands in your own profile, although I might be wrong.

  2. Add your user to the oinstall group.

    This was another stumbling block, Snow Leopard introduced changes to user/group administration. The trick is to use the dseditgroup command

    dseditgroup -o -edit -u `whoami` -p `whoami` -t user oinstall

    This should prompt you for your password, and add you to the group.

The Punchline

So now I can run the Oracle DB on my MBP, and I can access it from my login.

Then at the end of the day, I got an email saying that the representative data dump from the client's Oracle DB was available, but when I tried to import it using the oracle imp command, I got this.

IMP-00010: not a valid export file, header failed validation

Google tells me, and I have 99 44/100% confidence, that this is because the dump came from an Oracle 11g system, and as I pointed out at the top of this article the only version of Oracle that runs on the Mac is Oracle 10g. Oracle dumps are not compatible across versions. So back to the drawing board.

Don't you just love "Enterprise Quality" software?


Original article writen by Rick DeNatale and published on Talk Like A Duck | direct link to this article | If you are reading this article elsewhere than Talk Like A Duck, it has been illegally reproduced and without proper authorization.


Wednesday, May 18, 2011

A few weeks ago I noticed that there was some recent maintenance activity on the old rails-footnotes gem. I used to use this years ago. Among other things it manipulates the backtrace you get when a rails app raises an exception in development mode so that each line in the backtrace is actually a link which will bring up your favorite editor to the appropriate line of the sourcefile. It also adds links to get to the source for the controller, views, etc for the page you are displaying in development mode. I was disappointed that the backtrace links didn't seem to work with Rails 3. So I forked the code on github, and fixed that. This morning I noticed that the backtrace code had been removed from the official code, but there were some other fixes. So I merged the official branch back to my forked version, and it seems to be working. Getting this to work with Rails 3 required a bit of ahem duck-punching of the Rails::BacktraceCleaner, and there arent any tests for this, but it seems to be working. My version is in github in a repo owned by my employer Scimed Solutions , and I've sent a pull request If you're using Rails 3, you might want to check it out, and provide feedback

Original article writen by Rick DeNatale and published on Talk Like A Duck | direct link to this article | If you are reading this article elsewhere than Talk Like A Duck, it has been illegally reproduced and without proper authorization.


Wednesday, May 18, 2011

One of the oldest Rails plugins is annotate_models which was originally written by Prag Dave Thomas. For those few of you who might not have run across it, it adds a comment block at the top of a rails active record model class with the relevant section from db/schema.rb.

I'd fallen out of using it, just falling into the habit of opening up schema.rb and searching for the model name. But I got the yen the other day to start using it again.

Google alerted me to what seems to be a popular, modernized fork, maintained by Cuong Tran, who gemified it and expanded the function. It now annotates things like model specs, fixtures (if you are still using them) and various fixture replacement files like machinist blueprints. It also provides a separate command/rake task for annotating your config/routes.rb with the output from rake routes.

Installing the gem provides an annotate gem binary with which you can manually produce these annotations.

The readme claims that installing it as a plugin also modifies the the db:migrate rake tasks to automatically run schema annotation to keep in sync with what your migrations are doing to the schema. But plugins are a bit passé in Rails 3. I wanted to install the gem with bundler, after which it took me a bit of experimentation to get automatic annotation.

After playing around with it for awhile I came up with this. First I added the annotate gem to the development group in my Gemfile. Then I added the following file which I called 'annotations.rake' to lib/tasks in my Rails 3 project:

 namespace :db do
  task :migrate do
    unless Rails.env.production?
      require "annotate/annotate_models"
      AnnotateModels.do_annotations(:position_in_class => 'before', :position_in_fixture => 'before')
    end
  end

  namespace :migrate do
    [:up, :down, :reset, :redo].each do |t|
      task t do
        unless Rails.env.production?
          require "annotate/annotate_models"
          AnnotateModels.do_annotations(:position_in_class => 'before', :position_in_fixture => 'before')
        end
      end
    end
  end
end

It's pragmatic, it works, although I guess I'm a bit exposed to changes in the annotate gem. I think the right way to do this would be to fork annotate on github, and change it to register the rake task using a railtie, and then issue a pull request, but I guess I'm being lazy.

Update

Some have reported problems with this. I just checked and my current lib/tasks/annotations.rake looks like the above.

Note that the strings in the require statements should both be "annotate_models", for some reason the code formatter in typo is changing the underscores to spaces, no time right now to debug that.

This version only requires the annotate_models gem code for the migration tasks, and also only in a non-production environment.


Original article writen by Rick DeNatale and published on Talk Like A Duck | direct link to this article | If you are reading this article elsewhere than Talk Like A Duck, it has been illegally reproduced and without proper authorization.


Items:   1 to 5 of 55   Next »