Getting to know TextMate | Part 1

March 4, 2007

At work, I was lucky enough to have them get me a copy of TextMate to be used for our up-coming experiments / projects with Ruby on Rails. TextMate is recommended by all the big RoR gurus and for good reason. It makes working with Rails all the more enjoyable and easy. Here’s some info on some of the things you should know about TextMate to make it worth the crazy money they charge for it.

Mac Key Notation:

It’s important to be on the same page, so here’s what all the icons you see here /everywhere mean.

key_icon_command.gif This is the command or apple key.

command The alt or option key.

key_icon_control.gif The control (ctrl) key.

key_icon_shift.gif The shift key.

Basics:

First, its a very good idea (especially in editing Rails applications) to open up a whole folder at a time, instead of single files. The great thing about TextMate is that it shows you the contents of the folder in a drawer, and you’ll be able to get to all the files in that directory via short-cut keys (as we’ll see in a bit). To open a folder, simply use the open pane to select a folder but no particular file inside that folder.

I like my drawer on the right side, but the initially, the drawer always seems to open on the left for me. To correct this

  • select View » hide project drawer
  • move the TextMate window over to the far left-hand corner of the screen
  • select: View » show project drawer

TextMate opens files as tabs in the main window. Navigating these tabs can be done easily via shortcuts. Check out the Navigation section for the details.

Top of the Window:

Hitting the ‘x’ for a tab will close this tab. This will also be the result of hitting : key_icon_command.gif+w

The circle which replaces the x on a tab indicates that the file has been modified but not saved.

Side of the Window:

Quick, go to : View » Gutter » Line Numbers
to turn on line numbering on the side. Don’t turn this off.

Bottom of the Window:

At the bottom of the window are a few fields that give you info about how you are editing the document:

picture-1.png — This indicates which ‘bundle’ package you are currently using. The bundle determines what short-cut keys are available to you as well as some other aspects of how the program functions, so its good to make sure this is correct for the file type you are using. Initially, when opening up a .rb file, TextMate sets this just to “Ruby”. If you are actually using TextMate for Rails, you’ll want to change that default. Once you change the bundle package for a particular file type, it is maintained for all files of that type

picture-2.png — This indicates what gets inserted when you hit the tab key. “Soft Tabs” indicates that its actually inserting spaces instead of tabs for indentation. Apparently 2 spaces is all the rage for Rails indenting.

Bracket Completion:

TextMate tries hard to make tedium disappear when writing code, and one spot that in which this is immediately apparent is when it starts adding closed parens / brackets / squiglies to your open ones automatically. Usually this is a good thing, but there are times when you need to get around these added brackets and not grab for the mouse. These will help:

  • key_icon_command.gif + return : Moves down one line but doesn’t move characters behind the cursor position down to that new line
  • key_icon_control.gif + f : Moves cursor to the right one position
  • Sometimes you just want one bracket, in these cases its best to be on the right-hand side of a word or hit : key_icon_shift.gif + right-arrow to select that rogue bracket.

File Navigation:

All the files opened in your drawer are accessible with a few button mashings.

  • key_icon_command.gif+t : opens the ‘go to file’ window. Just start typing the name of the file you want to go to and then hit return
  • key_icon_command.gif+key_icon_shift.gif+t : opens the ‘go to symbol’ window. This means different things for different file types, but in, for example, a Rails controller file, this will allow you to skip around the different methods (actions) in the file.

More to come:

We could write a whole blog on TextMate short-cut keys, but this will be enough for now. Next time will go into a bit of formatting and how to actually use the bundles provided.


OpenVPN Server on Mac

September 26, 2006

Spurred by a unhelpful digg post on setting up an OpenVPN server on Windows, I decided to finally get OpenVPN working on my Mac, which is currently running as my web server / other servers. I eventually found some help, but it took awhile, so why not gather it all up here.

What is OpenVPN?

A VPN or Virtual Private Network essentially connects a remote machine to a network, over the Internet, securely. A common use for VPN is to let a user at home or on the road make an encrypted connection to his office’s network as if he/she were actually in the office. In this type of setup, you would be able to connect to file servers, mail servers, or printers remotely, without having to worry about someone on the Internet watching what you do and snagging private information.

I wanted to use it so I could use VNC to connect to some of my home machines on my laptop at school.

OpenVPN utilizes SSL, the same technology used to encrypt websites to make its connection secure. Its also OpenSource and free, which are two good reasons for using it. It is also fast and very powerful, once you get things set up.

One alternative to OpenVPN commonly cited is Hamachi. It seems easier to set up and can run on the major 3 OS platforms. The main reason I shyed away from Hamachi, as many people do, is because it is closed source, and owned by a company. That means you just really can’t be sure about what its doing or how its doing it. Sometimes this is acceptable, like when using Skype, but sometimes, you’d just rather have the open software. Plus, OpenVPN is a much cooler thing to have running on your system anyways.

Configuring The Server

This was where there isn’t a lot of Mac specific info. Most tutorials deal with using Linux or Windows. Thats fine, probably what most people have as servers. But I wanted it on a Mac! The ever useful Darwinports has a port of OpenVPN, labelled “openvpn2”. They have the regular openvpn port, but it is an older (1.6) version, and that won’t due.
Install it by using the command

sudo port install openvpn2

This will get you most of the packages you need to get things going.

Now we turn to the OpenVPN site for configuration instructions. You can follow the Linux instructions pretty closely, and things will work out well with a few exceptions:

  • The easy-rsa folder can be found at /opt/local/share/doc/openvpn2/easy-rsa . I copied the openvpn2 folder to someplace easier to find like /opt/local/etc/openvpn . You could make it easier and put it in /etc/openvpn too, but sometimes I forget to check there…
  • The sample server and client configuration files can be found at /opt/local/share/doc/openvpn2/sample-config-files. I also grabbed the server.conf file and copied it to my simplier openvpn folder. Making these copies will also ensure your changes won’t be overwritten when OpenVPN is updated.
  • according to this hint from macosxhints.com,tunnelblick might be needed to get OpenVPN working correctly. Download tunnelblick here,the current version I got was 3.0 RC3. We will be using it as our client as well, so more info in that section below

So with the help of the OpenVPN manual and the nice tip about tunnelblick, we should have a working version of OpenVPN on our server.

Configuring the Client

Like I mentioned, we need tunnelblick to connect to our server. Tunnelblick is a very elegant and easy to manage GUI front end to OpenVPN. The 3.0 RC3 version comes with everything bundled together, and all you need to do is drop it into your Applications folder.
Run it and you should see a little tunnel in the upper-right hand corner of your screen.
It should also add the folder ~/Library/OpenVPN. In this folder I copied the ca.crt, client.crt, client.csr, and client.key which were created on the server during the PKI section of the tutorial. I used fugu to move stuff over from the server.
Now you can click on the tunnelblick tunnel icon and then click on “details” to get to the meat of the program. Select “edit configuration” to modify the important stuff. I basically copied OpenVPN’s sample client configuration, and pasted it into here. Modifying the destination IP address and the location of the crt and key files. I had to use the entire path file to get these to work correctly for some reason, namely:
/Users/username/Library/openvpn/ca.crt . I don’t know why I couldn’t use realitive file names, but it wasn’t having it.
Also, I started by using the local IP address of my server to make sure things were working correctly before trying to connect to it from the Internet.
When that was all finished, I selected “Connect” and you should be connected to your own VPN server!

If you have file sharing turned on, you can check your connection by hitting apple + k to go to the connection dialog and connecting to afp://10.8.0.1 (if you followed the tutorial exactly, else use the IP address you set it up for). This should connect to your server.

The next step is to get more machines from your intranet on the vpn. But that is for another post, as I haven’t quite figured it out yet…


Automatic Network Photo Transfer

August 1, 2006

picture-2.pngThe last part of my photo management project was to have an easy way to move images into Picasa. While we will use the Ubuntu box to view and edit pictures, most of our time is spent on our Macs. So there will be times when we have a folder of pictures on a Mac, and want to get that to Picasa as easily as possible.

I used Automator to create a stand alone application that should accomplish just that. First I needed a way to connect to the Ubuntu box. In Automator there is the option to connect to a server, but you have to make sure that that particular folder was shared and enter a password and bla bla bla… too much. Since I had passwordless entry through ssh set up already, why not leverage that to get to the Ubuntu machine?

With a little searching I found an upload with scp Automator action. Perfect! scp is an extenstion of ssh, and this Automator action takes care of moving the folder over too. To use it in Automator, I went to ~/Library/ and created the folder “Automator” then moved the .action file to this folder. When you restart Automator, the upload with scp action will be there. So the Automator workflow first uses “Ask for Finder Items” to select a folder and then “Upload with scp” to copy it to the correct directory on the Ubuntu machine. I have it set up to copy the folder into the “My Pictures” folder inside “PicasaDocuments”. That way, Picasa will automatically add the folder to its listing. It’s so easy!

I then saved the workflow as an application called “PhotoDrag”. Now when I want to copy a folder of pictures over to Picasa, I simply ctrl + space to open QuickSilver, type “phtod” to open PhotoDrag, select the folder, and thats it. PhotoDrag will use scp to move it over to Picasa, and Picasa will automatically add it to itself.

In order to use PhotoDrag on other Macs, you have to grab the scp .action file as well and put it in that ~/Library/Automator folder.

As an aside, I used Mikon to quickly / freely / easily change the ugly default Automator icon into something more relevant.


Picasa on Linux

July 27, 2006

snapshot4.pngWell I finally got around to installing Picasa onto my Ubuntu box. Coming back from a 2 week vacation with a few hundred pictures got me interested in photo organization again. In my opinion, iPhoto is a dog. I wish this wasn’t true. I wish I could gloat over Windows users with the speed and ease of iPhoto, but I can’t. Each time I open that thing up I get frustrated. It organizes pictures in a convoluted date based system, it takes forever to start up, forever to scroll through pictures, and two forevers to do anything else.

I have avoided using iPhoto by trying out iView Media Pro for awhile. While it can organize photos in a much more systematic way, its still slow. Plus, every time I want to do something in that program, it takes me 30+ minutes to get it done. The UI is not very friendly to me, and options that I think should be obvious (like copying a picture to the desktop by dragging it there) aparently don’t exisit. Plus now that Microsoft has bought out iView, I don’t think this program is going to get any new exciting features any time soon.

And so I installed Picasa on Ubuntu. I found instructions which made the process trivial, so that was nice. I wish I could say that all my photo organization problems have been solved through Picasa, but alas, this is not the case. While I have seen Picasa work incredibly fast on very outdated Windows XP machines, on Linux on top of Wine, it remains sluggish and CPU intensive. However, this performance hit seemed to decrease after sitting there for awhile (I couldn’t tell you why). But while editing photos, I probably won’t be able to do much else. Picasa also seems to add extra folders to its viewer that it should be ignoring (the “originals” folders that appear after editing an image).

Even with the slowness, I think I will continue to use Picasa because its organization features are just that good. It takes the best of both worlds of sequential and event organization. The folders are arranged by date, and separated by year, but within this date system, you assign meaningful names to the folders. Plus all the image folders are stored at the same level. So instead of drilling down to specific days like you have to in iPhoto, i.e. 2006 >> 12 >> 25, you have folder names like “Christmas 06”. Plus you can tag your photos with keywords to help you find them later.

I know that iPhoto has some tagging features and the folder setup has gotten better, but it still doesn’t seem nearly as intuitive or easy to use as Picasa is. Plus, with 8,000+ photos, Picasa still moves faster than iPhoto on my iMac that has … 25 pictures.

Google: we’ll buy anything you want us to if you get a team of developers to make a Cocoa version of Picasa, I promise.

I also came up with a decent backup system and automatic-remote-picture-addition system that I will detail in the next few blogs.

Update: Aparently others have problems with iPhoto as well.  Not many solutions yet.


The Time-sink of a new web site

March 26, 2006

Over the Spring Break, I spent some time developing a new web site for my mother's RV park and campground business. Over all I'm pretty happy with the results (especially considering what it used to look like). The main drive for making the site over was to make it easier for people without much web experience to navigate through it. I made the buttons very simplistic (and most are based on signs you would see in parks), and over all the site is very picture driven.

I also wanted my mother to easily add her own content without having to email me every time she wants to update. I found a hosting service which allowed me to easily install wordpress and gallery. Now she can post news updates and pictures easily through the application interfaces or even by email (with wordpress that was easy, haven't figured a way to email with gallery yet). I think the wordpress "news" sections will really allow her to get info out quickly, and it shouldn't be too hard for her to manage.

I wrote most of the site by hand using Textwrangler and later with Taco HTML Edit. Both really great and free text editors. Textwrangler is my new favorite, and I use it for just about everything. But Taco has some nice features and I can see how it would be a good idea to keep it around. I used a great CSS template to not have to worry a lot about the basic layout.

One thing I am still frustrated about is that my mother uses a lot of punctuation, namely: "", ', &, and !'s. I've found that these characters don't transfer over to HTML very gracefully and so have been trying to find a quicker way to replace them with the correct codes, besides doing it all by hand.

I think Textwrangler is powerful enough and scriptable enough to do this, but I couldn't figure out an easy way to search and replace multiple characters at one time (although it did a good job when finding and replacing just one character at a time).

I am still looking for a good solution to this problem. I tried "MassReplaceit" and "iReplace" but neither worked very effectively. I would think there is an easy solution to this kind of problem. What do professionals do when they get a large amount of text from a higher up to be placed in a web site? Is there a trick I'm missing, or an industry standard I don't know?

I'll keep looking, and hopefully find a better solution than, "use dreamweaver".

Any suggestions about the new site? Tell me

Update:  I remembered that Textwrangler has the ability to "Open from ftp/sftp" which allows me to just edit and save directly to the site.  This should make updates for the base pages go a lot quicker.  Thanks Barebones software for the awesome free-ness that is Textwrangler. 

 


Java: a new adventure in programming

February 1, 2006

I’m taking a Software Engineering class this year, and the entire semester will be spent developing and coding a RTS game in Java.

I’m really excited about this oppurtuniaty, but it’s also a bit intimidating. We’ve only been using C++ up until this point, and the lectures will not focus on learning Java, instead, we are expected to learn on our own.

Right now we are just in a primitive planning stage, but I’m still trying to get as much Java experience as possible.  The game engine we are using looks very cool: Golden T.

We are also using eclipse to develop it, which I wish I had known about earlier
It’s going to do a lot of the work for us, but it will still be very tough.

Any ideas for a theme to our game?  Has to have 15 units per team, and will probably be straight top-down perspective.  We don’t have to worry about resource gathering, and instead will focus on just the fighting part.  Kind of like Myth III, or Warcraft, without the buildings.

We’ve got a couple of ideas, but it would be great to have something “really out of the box”, if such a theme exists for a RTS game.  All and all, this should be a very interesting semester.


VMware: my new co-worker

January 8, 2006

A couple of days ago I got to try the recently-made-free VMware Player on my work computer.  This software allows you to play virtual machines on your system, and with a little hackery from digg, you can create your own VMware systems.

Basically this allows you to run any operating system on top of Windows XP, as if it were on a separate computer.

I used the instructions from the hackery site to get Ubuntu Linux running in around 20 minutes.  They also have a bunch of ready-mades on their website that should work instantly.

You can install a complete operating system, everything from formatting the “drive” to changing the IP address, without affecting the actual system it is running on. I don’t know all the details about how this works, only that the player uses a file that acts like the hard-disk and the rest of the system.

The really cool thing about this software is that it creates virtual network cards for your virtual machines, so it should be possible to create a little virtual network of “computers” that could all communicate with each other and could be used for learning and testing how a network is set up.  I set up an Apache web server on my virtual machine and was able to access it from the real computer it was running on.  Pretty fun.

I’ve read a lot about network systems, but haven’t gotten a chance to really implement anything on a larger scale, but this program might allow me to do just that.

One issue though is that your real machine has to be pretty kickin to handle multiple virtual machines.  I almost crashed my work computer, which is the fastest system I’ve used, with two virtual pc’s, itunes, and our ticket management program open.  But you can control how much RAM each virtual machine you create uses,  which I didn’t really mess around with yet.

If you have a XP (or Linux) machine that is wasting most of its clock cycles just idling, try some of the ready-mades out.  Next work day, I am going to try to get a few virtual machines networked together and then finally start implementing a firewall with ipcop, or perhaps openbsd.

You could also install an unpatched version of XP or 98 as a virtural machine and see how long it takes to get infected with the Mblaster worm.  Or try out that new Sasser worm that was emailed to you out, just to see what it does to your system.  I won’t hurt your real set-up one bit, and clean up is as easy as clicking “delete”.


RSS is the future Today!

April 25, 2005

Perhaps not entirely, but its a good start. RSS stands for “Really Simple Syndication” (at least it does now) and is a great way to read sites that update often. Using a RSS aggregator such as NetNewsWire Lite, one can compile dozens of sites into one common interface which allows you to read new information really fast, and get a lot of new information at one time.

Say you’ve got a bunch of blogs you read everyday, plus you’ve got to get your news fix from yahoo or google news or whatever. Why go to each individual site when you can get all that reading done in one swoop?? Plus with all the free time you save, you can subscribe to more blogs and more news and stuff your head even more in the same amount of time!

Set up NetNewsWire Lite:
First download and install it to you applications folder. Then Drag it to your dock. Start it up, and you’ll have a bunch of feeds that you probably aren’t too interested in, but thats ok, because they show you how it works. Click on the NetNewsWire Lite drop down menu and click on “Preferences” Click on the “Browsing” tab and check the “Open links in background” option. Click the “Downloading” tab and change the Refresh rate to “Every 30 Minutes” Close out of the Preferences window

The hardest part of setting up the aggregator is actually finding the feeds to the sites you want. There’s got to be an easy way, I just don’t know it. For xanga sites, you can use the afore mentioned rss helper since xanga can’t do it on there own. Just type the username into the box and it will find the URL for the feed. Copy the URL and go back to NetNewsWire Lite. Click on the “Subscribe” button at the top and the link should appear. Hit ok, and you’ve got some feeds to read! For news sites, you can usually find a link somewhere on the page. Like at news.yahoo.com there’s a section on the left call “News via RSS” . Click on the yellow box, copy the URL and subscribe to it in the RSS aggregator of your choice.

You can delete the feeds you don’t like by selecting them and hitting the “delete” key. You can even group your feeds into different folders by clicking “File” and then “New Group”. Then drag similar feeds to that folder. Pretty nice.

What’s cool is that you can let your unread feeds build up and then read them all at once. As long as NetNewsWire Lite is running it will check every 30 minutes for new feeds, and it keeps a running total on the dock icon, which is very cool.

Shortcut keys:
hitting the spacebar will move through each new feed entry. It will also page-down for longer blog entries. This is the easiest way I’ve found to navigate through your feeds. Command + k will mark all in the particular fee as “read”. Sometimes necessary because the technology isn’t perfect.