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 »


Quicksilver trigger: open with Textmate

September 20, 2007

Just made my best trigger yet! For those not in the know, quicksilver can be used to create custom short-cuts that do something when you press a certain key combination.

I had already made a open Gmail trigger, so I can open Gmail just as simple as command+option+g. This ones pretty nice, but the one I did today combines my favorite Mac app (Quicksilver) with my favorite Mac editor (Textmate).

One nice feature of Textmate is its ability to open folders and display their contents on a side drawer. The part that always bothered me was getting to the right folder while in Textmate. I usually had it opened in the Finder, but then would have to re-navigate to it when I wanted to edit files in the folder.

But No More!

For this trigger I turned on the proxy objects in the Quicksilver section of the Catalog.

proxy-on.png

This Gives you access to the ‘Current Selection’ proxy object, which represents what you have highlighted at any given time. Folders, files, whatever. It’s a very useful proxy.

Now we are able to create a trigger that opens the Current Selection (i.e. a folder) in Textmate.

Quicksilver textmate trigger

Assign this to your keychord of choice (I picked command+option+m but I don’t know if thats a good one) and you’re ready to use Textmate, via Quicksilver, all the more efficiently.

Update:

I found a problem with the key combination I choose, namely option+command+m is used to highlight text in the best pdf viewer / editor : Skim. So, what to do? I don’t like having three modifier keys as part of the key combination, so I didn’t really want to move to control+option+command+m.

So I took advantage of another Quicksilver feature that lets you limit where your triggers are used. If you open the information pane for your trigger, and select the ‘Scope’ tab, you can set limits or exceptions to the validity of your trigger.

scope.png

I could have also just disabled it in Skim, but so far I can’t think of another place this would be useful except in the Finder…

Btw: You just type the name of the program you want to limit the scope to – so type it right.


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.


Record Player to Largest iPod Speakers Ever

November 8, 2006

Awhile back we found a good deal ($10) on an old Columbia Records Phonograph player that was cool looking, but not functional in the slightest. The speakers were blown out and the amp system was tube based.  It didn’t even hum when I plugged it in.  So I decided to gut it and add some newly acquired/free computer speakers to it, making it into the largest iPod speaker system on the block.

Old Electronics

Some of the original Electronics

The whole process wasn’t that hard at all.  All it involved was removing all the speakers and electronics that were in it previously, and fitting the new speakers and electronics in.  The hardest part was finding ways to attach the much smaller new speakers into the holes left by the old ones, without spending any money.  Attaching material I found include lighting fixture brackets and other random metal scraps from our house.  I also created some make-shift padding out of a ’super’  rag that we hadn’t used much.

new Speakers

New Speaker Setup

I think the whole process went pretty well, and the sound quality is about as good as you would expect from free computer speakers.  Luckily I’m not an audiophile.

This week, I’ve been trying to use the old Volume controls to control the volume of the new speakers, with limited success.  The original setup has three knobs: ‘Loudness’, treble, and bass.  What’s really going on under the hood is that the treble and bass loop back to the volume potentiometer to mess with the high and low ends.  This is unnecessary and non-functional, so I decided to use the volume knob to control the left channel and the bass knob to control the right channel.  This works, but the problem is that the change in resistance in these two devices is apparently not linear.  Meaning, there is not much increase in volume until you get towards the last bit of turning, and then it gets really loud, really fast.  I’m pretty sure this is a problem with the potentiometers and not with my wiring job, although I was just winging it and was using probably the worst soldering iron ever created.

So, now the next step is to go to radio shack and grab some volume knobs that are actually made to control volume and were produced in the last decade or so.  If I can get them to fit in the same spots, then that should make my modification a bit more functional.

Schematics

Schematics included 

pump up the jams

ready for jamming


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.


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.


Gmail as a Recipe Organizer

July 26, 2006

logo1.pngMy wonderful wife (of 13 months and one day, today) has come up with the brilliant idea to use a Gmail account to save recipes she finds online.

She had been using Yum, but got frustrated with trying to format the recipe correctly and stopped using it. It would try to be smart and convert the ingredient measurements to standard abbreviations, but usually didn’t get it right, and just made more work for her.

Now with her Gmail Recipe Book, she can log in, copy and paste the recipe and send it to herself. Auto-magically she has the recipe saved for future cooking.

But with Gmails tagging system, she can organize her recipes into categories like ‘chicken’ or ‘beef’. Since you can add multiple tags to an email, she can put recipes into different sections.

In the future, she could create two tags: ‘eaten’ and ‘uneaten’ to further differentiate from those recipes she has tried, and those yet to come.

She also came up with a good rating system. After trying a recipe, she can reply to that recipe and input our thoughts in the reply. That way each time she looks at that recipe, she can see all the replies (reviews) that go with it. Perfect! And if she wants a visual cue to the ratings, we could always use one of the alt symbols: ◊,†,•,‡ etc.


Control Your Subversion: Tips for Setting up Subversion on the Mac

July 4, 2006

subversion_logo_hor-468x64.pngThis is just a little post to help me remember how I got this stuff working.

Subversion is a revision control system that is being developed to replace older similar systems. Revision control lets you update your projects in an iterative fashion and allows you to keep track of these changes. This is perfect for when you have a bunch of people working on the same thing and want an easy way that everyone can work on the same stuff without stepping on other peoples toes.

I have used version control systems on a Java application we developed as a team last semester, and I plan on using it soon to develop web applications, but it really could be used for almost anything: a big proposal, documents for a conference, anything that you might work on in a step-wise fashion.

Plus, it doesn’t have to be a group project to use Subversion. You can use it as an easy backup system so you can work on your stuff from any machine and use it in case you want to revert to an earlier version of something.

They have a free book about how to use / setup Subversion, and there is a lot of info out there on how to use it.

Client

If you have the server set up, using a client to check-in and check-out projects is easy. For Windows there is a client called tortoisesvn that comes highly recommended. I guess it integrates with Windows Explorer to make things easy. For Mac you can use a precompiled command-line version (this one is the most popular and put out by Martin Ott of SubEthaEdit fame) or search for a GUI version. My favorite so far has been ZigVersion. SvnX is also recommended, but froze up when trying to connect to my server (probably because I was initially typing the location wrong).

Server

This is the tricky part. The easiest way to install it on a Mac that I’ve found is using Darwinports and this tutorial. I followed it excatly without any issues. Darwinports is so handy, everyone should have it installed by now. Then I used this section of the book to add basic authentication to my Subversion repository.

New Repository
Now to add a new repository I simply use:

sudo mkdir reposName

sudo svnadmin create –fs-type fsfs reposName

make template and import

cd ~

mkdir svn-template

cd svn-template

mkdir trunk branches tags

Import your template directory into the “reposName” repository using

svn import .http://localhost/svnrepo/reposName -m “Initial import.”

And you should be ready to go. Here’s a list of commands from the book commonly used in messing with the repository:

  • Initial Checkout

     

    • svn checkout http://name.of.host/rep/path

 

  • Update your working copy

     

    • svn update
  • Make changes

     

    • svn add
    • svn delete
    • svn copy
    • svn move
  • Examine your changes

     

    • svn status
    • svn diff
    • svn revert
  • Merge others’ changes into your working copy

     

    • svn update
    • svn resolved
  • Commit your changes

     

    • svn commit

So that brings together most of what you would need to set up a Subversion server on a Mac, and mess with it. Hope this can help somebody