Adding LaTeX to Notes with Ruby

February 15, 2008

I’ve finally come up with a some what novel use of ruby that is saving me a bunch of time at school, so now I’ll pass the savings on to you!

The Problem:

I want to take notes in class using my Mac. More specifically, I want to use OmniOutliner (though this method should be adaptable to any editor that can embed images). However, in more than a few computer science classes I’ve had, the mathematics get pretty heavy. And thus far summations, fractions, large equations, etc. don’t like to be typed out. They hate it. This has limited my ability to use my afore mentioned Mac as a note taking center for those classes.

So how can I still use OmniOutliner to take notes that include a large mathematical component?

The Solution:

In a word LaTeX. Let me explain.

Hopefully everyone’s familiar with LaTeX – a markup language used to format books, papers, etc. What its really good at is creating equations. The syntax is different, but not difficult, and it allows you to basically write out as complicated mathematical formula as you like in plain text. This gets converted to your actual equation using the TeX typesetting program.

I’d used LaTeX before a semester or so ago for writing up my homework for a particular class. For this, I’d installed the requisite packages via MacPorts and used the best editor of all time, TextMate, to write up the document and convert it to pdf.

But how do we add formatted LaTeX equations to a program like OmniOutliner, which doesn’t know how to parse LaTeX? Well, thats what this post is about.

conversion

More after the break.

Read the rest of this entry »


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.


Picture Backup with Rsync

July 30, 2006

snapshot6.pngUtilizing the Rsync setup I created earlier to backup the Documents folders of our laptops, I came up with a method to backup my newly organized picture collection.

The situation is as follows: My Ubuntu machine keeps the working copy of my photo collection and I would like to back up all the pictures as often as possible to the G3 PowerMac, which has an extra hard drive and is on all the time (its the webserver, printserver, MySQL server, etc).

To accomplish this, I set up passwordless authentication between these two machines, like in the other Rsync setup and then used this shell script on the Ubuntu box to get things moving:

#!/bin/sh
rsync -e “ssh” -rca –delete-after ~/PicasaDocuments/ username@192.168.1.x:/Volumes/back/pictureBackup -vv

/bin/date > ~/backup_script/log.txt

There’s not much difference between this and the previous shell script. This will build a list of the folders / files in the PicassaDocuments folder on my Ubuntu machine, and then match that list on the extra hard drive in the PowerMac (/Volumes/ is the location of all the mounted drives). the “–delete-after” means that if an item was deleted in the original folder, it will be deleted in the backed-up folder as well (not delete the originals after backing-up, like I feared it meant).

After this completes, it should write the date to log.txt in my home directory on the Ubuntu box.

Since both of these machines will be on most of the time, I decided to add this script to Cron to get it working every night. I used KCron (shown above), the KDE GUI to Crontab. Gnome has a Crontab editor too. I set it up to run this script every night at 11:15. After the initial backup of all the pictures, the process seems to run in 5 – 10 minutes. Its a bit taxing to the Ubuntu system, but it can handle it when nothing else is going on.

So with this system, I keep two copies of all my pictures on two different hard-drives. Not a bad deal.


ibackup (Finally)

May 13, 2006

Picture 1.pngSo I finally brought automated backups to the household. It took awhile because I am lazy, and because most current backup systems I’ve seen didn’t seem quite right for our setup.

I wanted to be able to backup critical data (i.e. school papers, homework, etc) on our 3 Macs to a Ubuntu server in my office, upstairs. I like using a Linux-based server for this kind of stuff because of the reliability of the operating system, and the relatively cheap cost of the hardware. I have been using this particular system for a few months now to develop our RTS game, and actually got the entire machine for a total of 0 dollars.

What makes our set-up a little unique is that both of our primary computers are laptops. So a scheduled sort of backup wouldn’t work as the machines aren’t always on at one particular point. Also, my wife is more techy than most, but still wouldn’t be comfortable opening up the Terminal to run shell scripts.The backup system I came up with uses Rsync to transfer files and is setup so that we only have to double-click on an icon and the backup starts up.

I used this great tutorial to set it up so that my machines could connect to the Linux server using SSH without needing a password. Then I used this tutorial (by the same person) to formulate a shell script that will automatically backup our Documents folder and our Desktop folder. Here is basically the entire script I used:

#!/bin/sh
rsync -e “ssh” -rca –delete-after ~/Documents/ jim@192.168.1.9:/back/ibook -v
rsync -e “ssh” -rca –delete-after ~/Desktop/ jim@192.168.1.9:/back/ibook/DESKTOP -v

Then I found a great program called Platypus 3.3. This lets you make applications out of scripts. So I loaded my script into Platypus and out came a fully function program to put on each machine. (I modified the script slightly for each system so that they are backed-up into different folders inside of “back”)

Now I know this isn’t a perfect solution as we will still have to find the time to run the backup program (it takes around 5 minutes to work its magic), but its certainly better than no backup at all. I might create a separate script to backup other folders like images and bookmarks and what not. Also for redundancy, I think I’m going to have the Linux server backup the backup folder to another folder on another physical drive. And since the server WILL be always on, this can be handled by cron easily.

This system seems like it will work well for what we need. Once I tweak the script a bit to include a few other critical files, I won’t have to worry too much about our aging laptop hard drives failing any time soon.


Podcasts and itunes

August 28, 2005

So, you’ve downloaded the most recent version of itunes and installed it right? Good.
Open the program, and look around a bit. What we will be interested in is the new menu item that says “Podcasts” with that wierd purple icoon next to it. Click on it to take you to the podcast menu.
You will see an empty library as you have not gotten any podcasts yet, right? right.
In the lower left had corner of the main window you will see a link titled “Podcast Directory”.
Click on that, and you’ll be wisked away to the podcast section of the music store.
On the left you will see “Today’s Top Podcasts” and in the center is a few podcasts that apple wants to showcase for whatever reason.
Today’s Top section is a great place to look for good podcasts, as there are alot of crappy ones, and sometimes its hard to tell what’s worth downloading and whats not.
So try clicking on one of the top podcasts. I’ll try the “Ebert & Roeper” movie review one.
That will take you to a page where you can gain some more info about your podcast of choice.
In the lower section, you will see the podcasts that are availible for download. To the upper right is a link to the podcast’s website. And near the center, is a button that says “Subscribe” click on that.
FYI the word “subscribe” isn’t a very good choice as it implies that you will be purchasing something, like a magizine. But I ensure you most of these are free. They should have gotten a better word for that, or made up one of their own… like “Podscribe” or “Podgrab” or whatever.
They will pop up a little message asking “are you sure?” and click ok to start getting your podcast!
So it will return to your podcast library, but NOW you will actually have a listing in your directory. And your itunes will be churing to download your new podcast. Once it gets done, you can start listening to your hip new podcast right now.

To mess a little more, click on the “settings” button in the lower left hand corner, and see what you can see. I like changing the the “Keep:” option to “All unplayed episodes” but thats just cause I don’t want to fill up my new ibooks hard drive. But you do what you want.

IF you get bored with your podcast, or pick a lemon, simply select “unsubscribe” and its gone.
On the otherhand, if you want more of your podcast, click on the little black arrow next to it’s name and you can select other episodes to “GET”
so go getting!


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.