Another Re-Design

Over the next few weeks the website will be going through another re-design. This time I am going to be re-writing the back end code for the website rather than the interface. Regular viewers of the site will notice some speed increases. Non-regular viewers probably won’t see anything different. The reason for the re-write is that, after writing reams of Java code, I wish my website code looked nicer and worked better. So that’s what i’m going to do. The website will go offline for a period during the transistion, but it shouldn’t be for too long.

TextMate, Java & Compiling [Updated]

For those of you that do not already know TextMate is a brilliant text editor for Mac OS X, including syntax highlighting and the most useful snippets system I have ever come across. If your a budding coder and want to try it out visit: macromates.com, and download a copy.

This post illustrates some of the bundle items I have either modified or added to TextMate to make it easier to use for Java development. If you use TextMate already then hopefully you will know how to use the bundle editor if you don’t then there is some good documentation available here.

In the code snippets below a ‘\’ at the end of a line indicates the code continues but is illustrated on the line below.

  • Compile, but no run.
echo "<h2>Compiling $TM_FILENAME</h2>"
cd "$TM_DIRECTORY"
javac -encoding UTF8 "$TM_FILENAME" &> >("${TM_RUBY:-ruby}" -rtm_parser -eTextMate.parse_errors)
  • Run in terminal.
osascript <<EOF
  tell application "Terminal"
    activate
    try
      close front window
    end try
    do script "cd '$TM_DIRECTORY'; java '${TM_FILENAME%.java}'"
  end tell
EOF
  • Compile and run in TextMate.
echo "<h2>Compiling $TM_FILENAME</h2>"
cd "$TM_DIRECTORY"
javac -encoding UTF8 "$TM_FILENAME" &> >("${TM_RUBY:-ruby}" -rtm_parser -eTextMate.parse_errors)
if (($? >= 1)); then exit; fi

{ java -Dfile.encoding=utf-8 "${TM_FILENAME%.java}" echo -e "\nProgram exited with status $?."; }|pre
  • Compile and run in terminal.
echo "<h2>Compiling $TM_FILENAME</h2>"
cd "$TM_DIRECTORY"
javac -encoding UTF8 "$TM_FILENAME" &> >("${TM_RUBY:-ruby}" -rtm_parser -eTextMate.parse_errors)
if (($? >= 1)); then exit; fi

osascript <<EOF
  tell application "Terminal"
    activate
    try
      close front window
    end try
    do script "cd '$TM_DIRECTORY'; java '${TM_FILENAME%.java}'"
  end tell
EOF
  • Compile and run package item. This also relies on you setting a CLASSPATH variable in you .bashrc, and will only work for packages one deep, still useful if you are just starting out with Java.
echo "<h2>Compiling $TM_FILENAME</h2>"
cd "$TM_DIRECTORY"
javac -encoding UTF8 "$TM_FILENAME" &> >("${TM_RUBY:-ruby}" -rtm_parser -eTextMate.parse_errors)
if (($? >= 1)); then exit; fi

export CURRENT_DIR=`pwd | sed -n 's/.*\///p'`

{ java -Dfile.encoding=utf-8 $CURRENT_DIR."${TM_FILENAME%.java}" echo -e "\nProgram exited with status $?."; }|pre

This post was just an illustration of how to make compilation in TextMate for Java more useable, in the next post I will be adding some new snippets, the ones that are missing from the original TextMate bundle.

Update: I have now (finally) expanded on this post, you can read about more changes here.

Java Programming

Well, it was bound to happen eventually, i’ve turned to the dark side and accepted Java as a programming language. It was sort of inevitable being as I have to learn Java for uni and I now have a complete game to program for an assessment. As for iSyncIt, progress is slow, really slow, but it is getting done, I might release 1.0 as an incremental rather than a large change release. Sorry to disappoint but I really haven’t got time (it will be my primary focus again around christmas when I go home from uni). I may however try to write something Mac & Java in the mean time, to keep all you freeware hungry vultures going.

Progress

I thought it was about time that I posted again to show that I am still alive and kicking. I am making progress with the 1.0 release of iSyncIt but the progress has been slow due to the fact I have to learn Java for university, don’t worry I will be keeping my applications in Obj-C for now but any new applications will probably grow a Java back end. I haven’t really done much work on the previously announced Aliquando but I will try and do some more soon because I could really do with the program for myself. Well, I hope that’s enough to keep you going for now.

Anti-DRM

Well, today, or at least some time around today in GMT time is Anti-DRM day. As a sideline to my normal ramblings I thought I would have a go at making my position clear. By the end of this post my position will probably be about as clear as mud due to my lack of writing skills, bit I’ll give it a go anyway.

In my general opinion DRM is a bad thing, or at least having many different forms of DRM is a bad thing. I don’t think that anyone would be so against DRM if it was compatible across devices & softwares, for example it really wouldn’t bother me as long as I could listen to Windows Media DRM’d files on my iPod and iTunes DRM’d files on Media Player.

In the original formats used to distribute media the fact that they were physical objects with, at first, no way to copy them provided some sort of built in protection. You could lend an LP to someone but if they wanted a copy they would have to go out and buy it themselves. With the advent of cassette recorders bootleg copies could be easily made, but it wasn’t necessarily the nicest way to listen to the music. CD’s at first could also be copied onto tape, then onto other CD’s but it was time consuming and expensive. The internet and MP3 (generally) has however opened up a massive way to ‘share’ files with other people. The main issue though is this word ‘share’.

If sharing were truly what was going on then it wouldn’t be so bad. You could lend someone a file but after a while it would expire, essentially giving it back, much as it was initially with LP’s, cassettes and CD’s, but when people stop buying music then income for companies decreases.

We all know that in reality artists are paid too much but if music was just given away all we would get is cheap & shoddy bands with records no one really wants.

I suppose what I am trying to say is that DRM should really be unified and refined and until this happens, get rid of it. I want to listen to my music the way I want, without restrictions.

University

I am finally at university & I have managed to get my internet working. As soon as I am settled in and I know where I am going work on iSyncIt will continue. The 1.0 release will be as stable as I can get it to be, but I will also be adding as many new features as I can possibly think of. I can’t imagine it being more than a few weeks until the next release is ready, so say tuned.

We're Almost There

iSyncIt 0.9 has been released, the last minor update before the big 1.0 & feature unfrozen release. If you have any particular requests for features then you can contact me and I will see what I can do. I cannot see any obvious problems withe 0.9 release but if there are bugs then they will be corrected in incremental 0.9 upgrades then the necessary code migrated to 1.0.

For those of you that are interested, the current features that are in the works for 1.0 are:

  • Scheduled Syncing
  • Localization
  • Dashboard Widget

Not many features but hopefully enough to keep you users happy for a while.

(I am trying to get .Mac to sync as well but this is proving to be more difficult, if I can work it out, this will also be in the 1.0 release.)

Another New Month

These months just seem to come round faster and faster. First of all I will start of by saying that iSyncIt development is moving along steadily and I will be implementing a few features that people have emailed me in the next few releases, especially in the 1.0 release that will be coming up very soon.

Secondly, development will slow down a little at the end of this month as I will be moving to Aberystwyth University to do Internet Engineering. Hopefully this will give me the grounds to write some even better applications.

Thirdly, because of my move to Aberystwyth I have decided that I need to be more organized and, being the geek that I am, I decided to write an application to do it all for me. Of course, it will be published and made available to everyone, hopefully sometime this month.

Finally, if anyone that reads this blog attends or will be attending Aberystwyth Uni let me know through the contact page. I want to know if any one (soon to be) local to me finds my stuff useful.

Downtime (Sort Of) [Updated, And Again]

Over the next few days I will be updating the website to the new stylesheet. This means that initially the current stylesheet will be removed at the website will be left plain and boring. As I start coding the new CSS in components should start to arrange themselves. The website should remain fully functional during this time but may look a bit odd.

Update: Well, the new stylesheet is in, quicker than expected. It will be in beta status possibly for the next few weeks but for now the website is back to it’s working(ish) condition.

Update 2: The first issue has emerged, the fact the the logo, being a PNG, does not display correctly in Internet Explorer. I can either hack it to work, switch it to a slightly worse looking GIF or use a nice bit of Flash. We’ll see, for now it’s going to stay the same.

Rich Text File (RTF) Into NSTextView, Cocoa & Obj-C

I was searching for an example of how to do this for ages and came up with nothing. All the pros out there will probably say it is easy and give shorter ways of doing this but for noobs and people not in the know I wrote this little snippet. This is especially useful for creating easy to maintain change logs or for adding simple read-me and help files to your application.

First of all you will need to create a NIB file with some sort of controller class in it. In the controller class create an outlet of type ‘NSTextView’, for this example I will call it ‘controller_Out_TextView’. Then generate the files for this controller so they appear in your Xcode project.

Secondly, create a window and add an NSTextView to it from the palette, connect the NSTextView to the outlet in the controller.

You will then need to create your rich text file with the necessary text in it, make sure it is added to your project and will be copied to the application bundle. For this example the text file will be called (rather originally) file.rhtml.

Finally add the following code to the ControllerName.m file between the @implementation and @end, or in your awakeFromNib method, if you already have one.

- (void)awakeFromNib
{
  NSBundle * myMainBundle = [NSBundle mainBundle];
  NSString * rtfFilePath = [myMainBundle pathForResource:@"file" ofType:@"rtf"];
  [controller_Out_TextView readRTFDFromFile:rtfFilePath];
}

Compile and run, hoepfully all of your text will be displayed.

It's Finally Out The Door

At last iSyncIt 0.8 has been released. The main issue fixed with this version are the crashes that occurred, especially when syncing more than once, if you find any more problems don’t hesitate to contact me. I have also created new icons for the software, a more dock friendly (if you choose to put it on your dock) and more ‘Mac’ main icon and a more individual menu bar icon, unfortunately it is still not animated but i’m working on it. So download and enjoy.

It's All Gone Web 2.0 [Updated]

Along with solving the iSyncIt problems I have decided to give the website a makeover (not that it’s really out of date). The makeover is not a serious attempt at making the website look more professional, more of an attempt to make it as ridiculously Web 2.0 like as possible. The main aim is to give the software pages a better appearance and allow images to feature more heavily in the website.

P.S. For legalities sake and the fact I don’t really know what’s going on with the Web 2.0 name, as far as I know O’Reilly own some stake in the name so I thought best to give them a shout.

Update: Turns out O’Reilly only own the trademark “Web 2.0” in the context of conferences so I should be safe, phew.

iSyncIt Crashes

I have now got to the bottom (I think) of the iSyncIt crashes that seem to affect a few versions of the software. I am currently in the process of fixing the bugs and a new release should be out within the next few weeks. Development is a little bit slower than normal at the moment because my brain is still in holiday mode and I am making plans for university.

Textilize Alternative

The textilize methods in Rails has never really been what I wanted. When it wasn’t adding paragraphs it was messing with my line brakes but it made such a good job of making HTML and XHTML that validates. In order to make it work better I re-wrote the method to be more suitable.

Put the following in the application_helper.rb file and call it using custom_text(“String”).

def custom_text(text)
  if text.blank?
    ""
  else
    text = RedCloth.new(text).to_html
    if text[0..2] == "<p>" then text = text[3..-1] end
    if text[-4..-1] == "</p>" then text = text[0..-5] end
    text = text.gsub("<p>", "")
    text = text.gsub("</p>", "")
    return text
  end
end

Job done, you should get correct HTML and XHTML but no paragraphs and no messing with line breaks.

Ruby on Rails Update

For all of you Ruby on Rails users out there make sure you have upgraded Rails to version 1.1.6. I know that most people don’t like to install these incremental updates because they tend to break things quite easily but this one really is a major update.

For those of you that do not know, versions of Ruby on Rails up to version 1.1.5 have suffered from a problem by which even an amateur hacker can type a URL and create a process that hangs and basically shuts down the website. I’m not going to be irresponsible and publish the affected URL’s but make sure you upgrade.

I'm Back

Well, i’m back from my holiday and already working hard on iSyncIt (well not really, but in the next few days). I am also getting around to fixing the problem with month changes on the blog which are not currently handled very well. Just thought I had better keep you informed and show that I haven’t disappeared off the face of the planet.

Downtime & Absence

I’ve just received notice from my hosting provider that the website will experience some downtime tonight (27th July) between 23:00 and 3:00 GMT. Just thought it would be best to let you know so you’re not left wondering where this wonderful website has gone.

I am having a break for the next two weeks starting Saturday morning. During this time there will be no new posts or new software releases and I will not be contact-able through the contact form or by email. If you have any serious problems with any of the software or the website not functioning contact me in the next 24 hours and I will try and sort the problems before I leave.

Have a good summer everyone. I will be back soon.

Localization

Recently, I have had a closer look at the website logs and noticed, to my surprise that I am getting a lot of hits from German users, especially to the software pages. I have therefore decided to start work on localizing iSyncIt, my primary application, into German. I am aiming to have the localization integrated from the 1.0 releases for now, the 0.x releases will remain in English only.

If you are German speaking and what your name in the credits for iSyncIt then; use the application, translate all of the strings and messages in it and contact me with the localized strings. If nobody comes forward to help with this momentous task then I will be performing the translations with Babel Fish.

On a side note, iSyncIt 0.7 has just been released, there aren’t many changes in this release, just the ability to add iSyncIt to your ‘Login Items’. You can download it here.

An Email Form with Ruby on Rails

The one thing that I’ve been struggling with the most during my Ruby on Rails learning curve is how to create a simple email form for any web applications I may want to create. There was nothing to be found on Google so in my initial attempt I worked through the ActionMailer documentation on the RoR wiki website. I put it all together and, feeling really pleased with myself, clicked the send button. Nothing at all, just lists of errors, so I modified it and still more errors. After posting on Ruby Forum and with the help of a talented member I finally got it working.

This post is for all the people like me who don’t know what to do.

First of all, this tutorial assumes that you already have a basic RoR web application set up with a ‘Contact’ controller and a main view for the index in the controller.

Now the real work starts. Open up a terminal session (or SSH) and navigate to your rails application’s directory (for this tutorial the rail application will be ‘rails_app’).

cd /rails_app

Then create the mailer, ‘Emailer’ is the name of the model that will be produced.

./script/generate mailer Emailer

Now, that’s all the terminal work done. Lets start the setup.

In your chosen editor open the file ‘/rails_app/config/environment.rb’ and place the following inside the ‘Rails::Initializer’ block customizing all the necessaries to your SMTP server’s configuration.

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => 'localhost',
  :domain => 'website.co.uk',
  :port => 25,
  :authentication => :login,
  :user_name => "smtp_username",
  :password => "smtp_password"
}

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_charset = "utf-8"

Now open the file ‘/rails_app/app/models/emailer.rb’ and make it look like the below, again customizing the necessaries (but do not touch the variables).

class Emailer < ActionMailer::Base
  def contact_email(email_params)
    # You only need to customize @recipients.
    @recipients = "[email protected]"
    @from = email_params[:name] + " <" + email_params[:address] + ">"
    @subject = email_params[:subject]
    @sent_on = Time.now
    @body["email_body"] = email_params[:body]
    @body["email_name"] = email_params[:name]
    content_type "text/html"
  end
end

In the controller for your contact page you will need to make the following changes, basically, adding a definition for ‘send_mail’.

def send_mail
  Emailer::deliver_contact_email(params[:email])
end

Go to the ‘/rails_app/views/emailer’ folder and create a file called ‘contact_email.html.erb’. In this file place the following code.

<p>Name:</p>

<p><%= @email_name %></p>

<p>Message:</p>

<p><%= @email_body %></p>

The final step is to create a form on the ‘Contact’ page that will allow the website to user to input and submit the email. An example for is illustrated below.

<% form_for :email, :url => { :controller => 'contact', :action => 'send_mail' } do |f| %>
  <%= f.label :name %><br />
  <%= f.text_field :name, :size => 60 %><br />
  <%= f.label :address %><br />
  <%= f.text_field :address, :size => 60 %><br />
  <%= f.label :subject %><br />
  <%= f.text_field :subject, :size => 60 %><br />
  <%= f.label :body %><br />
  <%= f.text_area :body, :rols => 10, :cols => 60 %><br />
  <%= submit_tag "Send Email "%>
<% end %>

That’s about it really, you may want to add your own error handling as this example only covers the basics. If you go to the contact page you can see a working example of the above tutorial in action. There are probably easier ways of doing this than the method I have described, but I like my method and hopefully it will work for you.

Update: The code in this post was updated for Rails 2.0.x on 17th March 2008.

Update: Modified the settings code to be ‘smtp_settings’ rather than ‘server_settings’, thanks goes to Lyle for discovering the problem (below).

Update: Modified the code to work for Rails 2.3.x onwards (but not Rails 3).

Little Snitch, iSyncIt & The Website

The first topic of todays post is Little Snitch. For those of you that do not know this Mac OS X software, it is a small utility that warns of outgoing connections and allows them to be blocked if necessary. It can be downloaded here. The main reason I am mentioning it is that I have received an email today from a worried user of iSyncIt that was informed by Little Snitch of iSyncIt checking in with boycie.primehosting.co.uk. This is perfectly normal as this is the websites hosting server so it is OK to allow the connection with Little Snitch, iSyncIt is just checking for updates.

Version 0.6 of iSyncIt is out with the advertised bug fixes. I have also rewritten all the code so the memory footprint is much smaller. The general appearance of the application (especially the preferences panel) has also been improved.

I have also received an email from my web host to inform me that my account may be moved to a different hosting server. This may cause a very short amount of downtime in the coming days. It could also cause Little Snitch to report a different server, but it is still OK.

I Use This

Whist I was browsing my favorite blog (TUAW) today an interesting post popped up. It seems that some guys known only as Arne and Marcus have started a website that is sort of a cross between MacUpdate and del.icio.us. I think it’s a brilliant idea and should be supported so hop on over to iusethis.com, get registered and get adding. Plus if your a user of iSyncIt you can let me know. (See there is always another motive for blog posts).

Feature Frozen

Version 0.5 of iSyncIt is now in the wild. I can’t actually think of anything else to add to it at the moment so this will be the feature frozen release for now. Any subsequent releases, probably up to version 1.0 (if I get that far) will just be bug fix releases, I also plan on optimizing the code in these releases to give a smaller memory footprint and a faster run time.

Hidden Dock Icon

Unfortunately (primarily due to my lack of programming knowledge) I have not yet found a way to give the user an option of choosing whether or not to show the dock icon. I personally think that the menu bar item is more useful for iSyncIt so the dock icon will remain hidden for now. If any programmers out there know how to achieve the choice of dock hiding in Obj-C then feel free to contact me.

On that bombshell, iSyncIt 0.4 has now been released. All of you using automatic updates in 0.3 should receive it straight away but for everyone else it is available from the software section or you can get it from MacUpdate and let me keep track of the number of downloads. All the changes in this version are on the software page.

iSyncIt 0.3

iSyncIt 0.3 is now available in the wild. The most obvious changes in this release are the removal of iSyncIt’s dock presence and the introduction of a menu bar item instead. This also means that iSyncIt can be added to your login items and you can have much easier access to your syncing. Future updates of iSyncIt will now be handled through the Sparkle update engine. View more about iSyncIt here.

Everything on MacUpdate & iSyncIt

I have now uploaded all of my applications onto MacUpdate and to my surprise they appear to be getting quite alot of downloads. Luckily it does not appear to be affecting my bandwidth yet even though my hit count has risen rapidly.

I am now in the progress of updating iSyncIt to version 0.3. The major changes that will feature in the next release are; a dock menu and menu bar item for easier syncing and a properly compiled application instead of an AppleScript application.

(Apologies to anyone who has already recieved this post, or something similar too it, the original disappeared off the server for some reason so I have had to re-write it to restore it.)