Jon Thysell

Father. Engineer. Retro games. Ukuleles. Nerd.

Tag: ubuntu

Using a batch file to launch Gtk# apps on Windows with Mono instead of .NET

Mono is great for cross-platform development – maybe not so great for cross-platform deployment. In working on Chordious, a Gtk# app written entirely in MonoDevelop on an Ubuntu machine, there’s been no greater struggle than trying to find a simple “double-click” launch of Chordious on Windows.

Yes, if you stick with just the “standard” libraries and write your GUI with Windows.Forms, all an end-user has to do is double-click on your executable, and let .NET run it. But what if you don’t want that? What if your app needs to be launched by the Mono Runtime?

Realistically, the bigger hurdle is getting your end-users to install Mono in the first place – but even if you can get them past that – you’ll still need a double-click way to start your app. You’ll never convince them to start up a Mono command prompt and manually launch your app with mono.exe. And unfortunately for us, the Mono installer for Windows isn’t so nice as to add itself to the PATH, so you can’t just get away with a one-line batch file.

Enter StartMonoApp.cmd:

@echo off
setlocal

rem Script: StartMonoApp.cmd
rem Author: Jon Thysell <thysell@gmail.com>
rem Date: 7/15/2014

set _MonoApp=YourMonoApp.exe

rem Checking for 32/64bit machine

if exist "%SYSTEMROOT%\SysWOW64" (
    set WOW6432=\Wow6432Node
) else (
    set WOW6432=
)

rem Find default Mono version

set _MonoBase=HKEY_LOCAL_MACHINE\SOFTWARE%WOW6432%\Novell\Mono

echo Looking for Mono registry key %_MonoBase%

for /f "Tokens=2*" %%I in ('reg query "%_MonoBase%" /V "DefaultCLR" 2^>nul') do set _MonoVersion=%%J

if "%_MonoVersion%" equ "" (
    echo ERROR: DefaultCLR not found!
    goto nomono
)

echo Default Mono is %_MonoVersion%

rem Find the path to where that version of Mono is installed

for /f "Tokens=2*" %%I in ('reg query "%_MonoBase%\%_MonoVersion%" /V "SdkInstallRoot" 2^>nul') do set _MonoPath=%%J

if "%_MonoPath" neq "" (
    if not exist "%_MonoPath%" (
        echo ERROR: SdkInstallRoot not found!
        goto nomono
    )
)

echo Mono %_MonoVersion% installed at %_MonoPath%

rem Check for the mono.exe binary

if not exist "%_MonoPath%\bin\mono.exe" (
    echo ERROR: mono.exe not found!
    goto nomono
)

set PATH=%_MonoPath%\bin;%PATH%

rem Launch the app

pushd %~dp0

echo Launching %_MonoApp%

start mono.exe %_MonoApp% %*

popd

goto :quit

:nomono
echo ERROR: Unable to find Mono. Please install Mono and try again.
pause

:quit
endlocal

So let’s say you’ve got yourself a nice little Gtk# app named GreatMonoApp.exe. To make a double-click launcher that uses Mono, simply:

  1. Copy the contents (minus the line numbers) of the script above into Notepad.
  2. Update line 8 with the name of your executable (in this example, the line should read set _MonoApp=GreatMonoApp.exe).
  3. Save the file into the same directory as your executable. (You can name the file whatever you want, just make sure you save it as a .cmd, not .txt, file).

There you go! Double-click on that new batch file and your app should launch via Mono. You might see a flicker or two of command prompts, but otherwise works quite well. If something does go wrong, the command prompt will stay open with an (hopefully useful) error message for you to debug.

How does the script work? Essentially it looks for the registry keys that the Mono for Windows installer created, and uses them to find where the mono.exe binary is. Then it adds that folder to your PATH (temporarily) so it can use mono.exe to launch your app. And as mentioned before, if there’s anything wrong (can’t find the registry keys, can’t find the folder or binaries) the script will show an error.

I hope someone out there finds this as useful as I do – I’ve spent forever trying to solve this problem, with progressively more and more complicated scripts. I’ve verified that the script works on Windows XP, 7, 8, and 8.1, 32 and 64-bit.

Happy coding!

/jon

P.S. I have no reason to believe the script won’t work on Vista, I just don’t have access to a Vista machine to test it. Sorry true believers.

What I use in 2012, Part 2: Software

I like to see how people work; especially for those whose work is mostly on the computer. In part 1 of this series, I listed all of the tech hardware I use at home; now I’ll list all of the software I use on a regular basis.

Note: I don’t endorse anything here beyond the implicit “this is what I actually use at home.”

The Basics

OS: Ubuntu w/ Gnome Shell

I played with Linux as far back as high-school, but despite multiple partitions and many early distributions, I always came back to Windows. In college I realized that if I was serious about learning Linux, I needed to use it exclusively. I liked Debian, but it was always just a bit out of date, and I hated that it installed a lot of redundant stuff (ten text editors, five desktop environments, etc).

Then I found Ubuntu.

I started with Ubuntu 5.10 “Breezy Badger” and Gnome with it; and despite some early dalliances with Ubuntu’s many derivations, I’ve been an Ubuntu user ever since. I was skeptical of the trends post-Gnome 2; Unity was slow, customization-poor and untested, while Gnome 3 was taking a risky move away from the Windows-clone icons, desktop and taskbar. I loved the abandoned pre-Unity “netbook launcher”, so I understood that a new UI paradigm might not be a bad thing- so I buckled down and tested both Unity and Gnome 3 extensively to see what fit.

I fell in love with Gnome 3 and the Gnome Shell. It lets me manage all of my personal work effortlessly, all from one laptop screen. Multiple virtual desktops, with previews exposed by the Super key, along with search and a preview of my open apps. I prefer it over every desktop UI that I’ve ever used. (Sounds like something worthy of discussing in its own post).

Browser: Firefox

I have jumped around from browser to browser over the years. In the early days I evangelized about Opera– but then everyone copied their feature set, and opened themselves in ways that Opera just couldn’t keep up with. I lived in the extension-heavy hell of Firefox for years, then leaned down with a focus on bookmarklets, then jumped to Chrome as the hot new thing.

I switched back to Firefox at the beginning of the year, wondering how far they’d come since I jumped to Chrome. I was very impressed. I have very few extensions; five in fact, and I sync all of my computers with the same settings. It’s not a memory hog anymore, and as far as I can tell, it’s no slower than Chrome. Chrome is extensible too- but Firefox has just the right set of tweaks that I want.

Productivity: LibreOffice

I started with OpenOffice.org even before I switched to Linux full-time; who didn’t want a free office suite with MS-compatibility and PDF export? I’m a big supporter of open formats, and OOo gave us the Open Document standard. One of my most popular software projects is my weight-tracking Open Document Spreadsheet, Weight Tracker ODS. When the majority of the development group moved to LibreOffice, I went with them. I use it for all of my regular Office needs.

Productivity: Microsoft Office Web Apps

I prefer open-source but I’m not evangelical; all I care is that I have the tools I need to get my work done. I use Microsoft Office often enough when I’m on Windows machines, but with the exception of OneNote (don’t get me started on how much I love OneNote for note organizing) there’s nothing about Office that really enables me beyond what LibreOffice offers.

However I have come to be blown away by the Microsoft Office Web Apps. I keep a few documents saved to SkyDrive (namely a couple OneNote notebooks), and it amazes me how much I can do with them in a browser. Plus I can access those docs on my phone. (Sounds like I need to write a post about how awesome OneNote can be).

Email: Gmail

I’ve used Gmail since college, primarily though the web interface, though occasionally I’ve used IMAP clients. I love its features, I love its hacks, and I couldn’t live without its spam filter. It maybe misses one or two emails a year- and I put my email address up everywhere, without obfuscation.

Chat: Google Talk

I don’t IM as much as I used to, but these days when I do, it’s on Google Talk. I think Jabber is a pretty sweet protocol- and having a Google account nabs this for free. I’ve also found that it has the absolute best AV stack I’ve ever used; it sacrifices clarity for faster frame-rates, which in real-life, low-bandwidth conversations, is a much better trade-off. I don’t need to see every pore to read someone’s facial expression: a smooth frame-rate without skipping or audio hiccups means I can follow all of the non-verbal communication and everything feels much more natural, even if it’s out of focus.

File Sync: Dropbox

I use Dropbox for syncing a select few files that I want on every machine, like my encrypted password database, or when I’m lazy for a quick transfer. I don’t trust them for anything else, as they don’t encrypt user’s files well enough. (They save space by not duplicating files that multiple people have, which they know because they keep a copy of the keys so they can decrypt your files.)

Password Management: KeePass

I’ve been using a password manager for a decade, and I use KeePass because it works well and has clients on a ton of platforms.

RSS: Google Reader

I read a lot of things via RSS, and I’ve used Google Reader for years. The web client is great on the PC, and pretty much every mobile ecosystem has a compatible client, so I don’t have to keep track of multiple subscription lists.

Finances: GnuCash

I have OCD when it comes to balancing my checkbook, and for years now have been using the free GnuCash to do so.

Social: HootSuite

I’m on Twitter and Facebook, and believe me, I’ve tried every possible app on every platform I have access to. Right now I live inside HootSuite. It lets me see only the columns I want, and most useful, it lets me space out my posts with AutoSchedule so I don’t flood my followers every time I hop on Google Reader and start sharing links.

Entertainment

Ebooks

Management: Calibre

Calibre is an amazing piece of software. It works with practically every e-reading device, lets you format back and forth between formats, pull down metadata, create new ebooks; the list goes on and on. I keep it running almost all the time, because then I can browse my library remotely with my phone, and pick and choose what books to download when I want to read them.

Really, once you have Calibre, you don’t need any other ebook software on your PC.

Store: Smashwords

I prefer to buy my books on Smashwords whenever possible. You can’t beat DRM-free with access to every format. It’s why I chose to sell my own ebooks through them too.

Store: Kobo Books

When I need to buy more “mainstream” books, I typically find them on Kobo for the same price as everyone else, but with the “benefit” that their DRM (though DRM is always a middle finger to paying customers) is the standard “every device can read it and it’s really easy to make go away” Adobe DRM. Nothing fancy.

Video

Playback: VLC

VLC has handled every media file I’ve thrown at it for a decade. No extra codecs to install, no hoops to jump through- it just works. If you’re new to computers, and the web, you have no idea what it means to have a video player that can, you know, actually play video files. It was the wild west a decade ago.

Encoding: Handbrake

I rip digital backups of my legally-owned DVDs for easy searching and playback on all of my devices, including my Xbox 360. Handbrake enables me to do that perfectly.

Streaming: uShare

I keep all of my video files on my Ubuntu-based home server, and with uShare, I can play those videos on my Xbox 360. It’s wonderful.

Music

Playback: Rhythmbox

Though my music lives on my home server, I do keep a full copy local to my laptop so that I can disconnect and still listen to my music. I’ve used Rhythmbox for years and love it for organizing and playing my music.

Encoding: abcde & lame

Yes, I’m one of those few guys that still buys CDs. And when I do, the very first thing I do is rip them to my hard drive and throw the disc into a box in the closet for safe-keeping. I use abcde because it’s set to the lame settings I like, and it’s one command from CD to MP3s.

Tags: EasyTAG

Everyone has their own rules about MP3 tags, even if the rule is “don’t care as long as they play and I know what they are”. I’m very meticulous about my collection (read: OCD), and EasyTAG rocks for getting those unruly music files under control.

Streaming: Subsonic

Subsonic runs on my home server, and the free version provides a web interface that lets me to browse and stream my music, create playlists, from any computer with a browser. Even from multiple computers at the same time, and with auto-transcoding for different file types and for different machines (if say you want to minimize bandwidth at work).

There are even a bunch of native clients on different platforms to let me access my Subsonic server, and even video support via flash (ala YouTube) if you pay for it. Sometimes, a paid program just really is worth it, and I’ve never regretted the purchase. I’ve tried all the open-source alternatives, but none come close.

Store: Amazon MP3

When I do buy digital music, I buy MP3, and I buy from Amazon. No special client, just give me my files. Like I said above, I usually buy CDs, but every now and then I see an album I’m on the fence about, and the MP3s are usually cheaper. It’s been a slow acclimation for me to buy digital files without the backup of a physical item, but Amazon does a good job.

Software Development

IDE: MonoDevelop

Working in the software industry means I have to use a certain set of technology for my job, and a certain list of programming languages. I also program way more at work than I do at home, so those languages tend to take precedence for me to know. And for a while now, the language to know has been C#.

Don’t get me wrong, I’m not complaining- in fact I love C# and the .Net stack. It just doesn’t seem very Linux.

The real problem is, despite all of its power tools, especially for developers, I have never been happy with any of the IDEs for developing in any language in Linux. It seems either you use some variant of Eclipse (which I hate), or a text editor plus a bunch of command-line tools.

Then they made MonoDevelop… and it is just glorious.

I live in Visual Studio at work, and in MonoDevelop I feel right at home. It makes compatible binaries, uses compatible project files, has Intellisense and nUnit and a real debugger- it’s basically everything I need in one place with nothing I don’t. It makes cross-platform development fun and not a game of “find the tool”.

Text Editor: Gedit

When I’m in the GUI and I need a quick edit, I use Gedit. It’s got just enough spunk for what I need.

Text Editor: Vim

When I’m working in the command-line, I use Vim to edit text files. Emacs users… to each his own.

Source Control: Bazaar

I plan on writing more in the future about Bazaar, but essentially it’s a cross-platform VCS that works in any workflow configuration, or several all at once. I use it for my little projects on my machine, then when I want it on my own server repository, and then again when I want to show off to the world on Launchpad. And every time all I have to do is copy the repository over, then pull down a new branch, a checkout branch, whatever makes the most sense for the project.

Writing

Note: I plan on writing about the open-source software I use for writing in greater detail at a later date.

Writing: FocusWriter

Once a year when I sit down to write a new manuscript, I send the developer of FocusWriter a donation. It’s customized to look exactly how I need it to, with progress bars and word sprints and timers and statistics- all of which melt away when I actually write, giving me a distraction free zone to get the words down.

Editing: Geany

Geany is technically an text-editor / lightweight IDE, but I can’t use it for that anymore, cause I’ve customized it so much to support my writing. I may spend a month in FocusWriter to get that first draft, but the next year is in Geany making it shine.

Notes: Zim

I mentioned OneNote above for note organizing, and while it’s true I do use it for some initial story brainstorming, any big writing project eventually makes its way into Zim. It’s cross-platform, uses plain text files, and even uses Bazaar for version control. Right now the entirety of my Guineawick Tales notes and plans are in one giant Zim wiki. I find it indispensable for keeping track of everything.

Web Services

Hosting: WordPress.com

I started using WordPress in the early days of blogging, installed by myself on hosting I paid for while I was in school. I’ve been in and out of its code, and customized the hell out of it for previous websites. Nowadays, I let WordPress.com handle all of the dirty work, pay for enough customization to make my site pretty, and let them take care of the rest. Which they do really, really, well.

Domain Registrar: Namecheap

I’ve been buying domains from Namecheap for years. They’re not always the absolute cheapest, but their dashboard gives me everything I want, with no funny business.

Phone

OS: Windows Phone 7.5

It surprised me that Windows Phone 7 really lived up to its “you don’t need apps, everything is built-in” mantra. In fact I have very few apps on my phone, nowhere as many as I did on Android or webOS. Email, Facebook, Twitter, photos, music, video, whatever- the base OS does pretty much every single thing I need it do, with just a couple of exceptions, which I list next.

Ebooks: Freda+

Freda is the new standard by which I hold all mobile ebook reader apps. It’s silky smooth to use, customized just how I like it, and lets me grab books over the net from my laptop running Calibre. I’ve read a dozen books on it this year, and I love it.

RSS: Nextgen Reader

I need my RSS fix, and Nextgen Reader gives it to me on the go. It syncs with my Google Reader account, so I don’t have separate lists of (un)read content to maintain. Fast and easy to use.

Twitter: Twitter

I’ve tried every single Twitter client on the Windows Phone platform, paid and free, and every single one was either slow, bloated, had a funky UI, or was way too power-user for what I need. I’m not a social media maven, I just want all of the Twitter functionality in a fast client that looks good. Surprisingly, the official Twitter client works really well for my needs.

Everything Else

Most pieces of software are specialized tools (especially in the Linux world), the use of which depends on the kind of work you do regularly. I could write a post ten times as long with every piece of software I’ve used at one point or another for specific, one-time tasks, but that would be tiresome and probably a waste of time. (Of course, who knows if anyone even read this far).

“Too Long, Didn’t Read” Summary

I run Ubuntu at home, and I prefer to use open-source, cross-platform software whenever I can. I don’t like paying for software or services unless the value they provide clearly outstrips any free or roll-your-own alternatives. I avoid vendor lock-in like a plague, preferring file formats that I can crack if the software stops working.

And just like in part 1, remember: this is just what I use at home, not necessarily what I use in my job at Microsoft.

/jon

P.S. So what do you use at home? Leave a comment below!

What I use in 2012, Part 1: Hardware

I like to see how people work; especially for those whose work is mostly on the computer. So in the spirit of Paul Thurrott‘s What I Use for Home and Office Technology, and Lifehacker‘s How I Work series, I present the following list of what technology I use at home.

Note: I don’t endorse anything here beyond the implicit “this is what I actually use at home.”

Computers

Hester: Lenovo ThinkPad T420 (Notebook)

Hester is my primary machine, and is named after the main character in my Guineawick Tales stories. It’s got a 2.6GHz Intel Core i5 CPU and 8GB of RAM. It boots from a zippy 80GB SSD, and has second 500GB hard drive for storage. It has a 14″ 1600×900 screen and a 9-cell extended battery; I like my machines light and easy to travel with.

I love and use the TrackPoint almost exclusively, only using a Microsoft Bluetooth Notebook Mouse 5000 when I want a mouse, since Hester has Bluetooth built-in and that means no USB dongle.

Hester currently runs Ubuntu 11.10 “Oneiric Ocelot”, and has never seen a copy of Windows outside of a virtual machine. But more on the software in Part 2.

Cortana: ASUS EeePC 1000HA (Netbook)

Cortana is my secondary “swings in to save the day” machine, named after the Halo character. It’s got a 1.6GHz Intel Atom CPU and 2GB of RAM. It came with a 160GB hard disk, which I replaced with a 32GB SSD. The model didn’t offer Bluetooth when I bought it, but that didn’t stop me from installing the radio from another laptop anyway.

Cortana has a 10″ 1024×600 screen, which, along with the poor Adobe Flash support, is really its only weakness. When the original battery died, I replaced it with a monster 12-cell that gives me a whopping 14 hours battery life (only 8 with WiFi on).

Cortana spent its longest time running Ubuntu 10.10 “Maverick Meerkat”, but has also run Ubuntu 11.04 “Natty Narwhal”, Windows XP Home, Windows 7 Home Premium and Ultimate, as well as Windows 8. Last I checked it’s running Windows 7 Ultimate (I flatten this machine so much it’s hard to keep track).

I’ve won three NaNoWriMos on Cortana. It’s saved my butt at work on numerous occasions. This little machine has proved its worth so many times I’m probably going to bronze it when it finally dies.

Serenity: Dell Vostro 200 Slim (Desktop)

Serenity was my primary machine for four years until I bought Hester, and is named for the Firefly ship. It has a 3.0GHz Intel Core 2 Duo CPU and 4GB RAM. It boots from its original 80GB hard drive, but has an additional 1TB drive for storage.

It powers two 22″ 1920×1080 Dell S2209W monitors with a GeForce 8400 GS video card, and I used a Logitech Trackman Marble Trackball along with a Logitech Classic Keyboard 200.

Serenity started its life running Windows XP Pro, but then moved on to a long life with Ubuntu, starting with 7.10 “Gutsy Gibbon” and surviving 8 in-place upgrades to 11.10 without a hitch. It is only after Hester became my primary machine that I put Windows 7 Ultimate on Serenity, namely as a joint machine for Anne and I. Unfortunately, I find my lifestyle doesn’t require a desktop these days (and the desk to support it), and so Serenity has migrated into the closet indefinitely.

Horatio: MSI Wind Nettop 100 (Server)

Horatio is my personal file/backup/utility server, named after Horatio Hornblower. It’s got a 1.6GHz Intel Atom CPU and 1GB of RAM. It has two low-power hard drives, for a total of 2.5TB of storage. As a nettop with green hard-drives, it uses only a miniscule 35W of power.

The primary purpose of Horatio is to be a backup server. All of my other machines backup daily to Horatio. I also store my entire media collection here, so that I can stream it to whatever machine I’m currently on.

Horatio runs Ubuntu 12.04.

Franklin: ASUS EB1007-B0410 EeeBox Mini (Server)

Franklin is my remote backup server, named after Benjamin Franklin. It’s got a 1.6GHz Intel Atom CPU (gotta love those Atoms!) with 1GB RAM and a 250GB hard drive.

The primary purpose of Franklin is to store backups of my backups, off-site from my home. As all of my machines backup to Horatio on a regular basis, so does Horatio backup to Franklin. Because of the lack of storage space (I wanted a tiny, silent machine)  I only backup my personal data and music to Franklin. Movies and other video content only live on Horatio for the time being.

Franklin runs Ubuntu 12.04.

Phone

Right now I carry an HTC Trophy running Windows Phone 7.5, which is named Jacobi after a character in my upcoming Guineawick Tales novel, Hester and the Kookaburra King. I’ve got an extended battery so I can go two days with heavy use and not charge.

I moved earlier this year, and as an experiment I used Jacobi as my primary computing device for a little over a month, while everything else was packed away. Email, web browsing, gaming, music, movies and reading. The phone held up remarkably well- enough that if I wasn’t a software developer or a writer, I could live pretty happy with just my phone. (You believe me, right?)

My previous phone was an LG Optimus S running Android 2.3.3, and the phone before that was the ill-fated Palm Pre. In general I like smaller phones; I for one am against the trend of larger, flatter devices.

Portable Devices

SanDisk Sansa Clip+

This $50 MP3 player is the best I’ve ever owned, and that’s including the Cowon iAudio5 that survived my service in Africa. My Sansa Clip+ has 4GB storage built-in, and I’ve added a 16GB card so I can carry my entire music collection plus podcasts and audiobooks.

While the original factory software was pretty good, I upgraded to the Rockbox open-source firmware, which really makes this little player shine. It lives mostly in my car, mounted to the dash, but I also clip it to my pocket when I go running.

Pocketbook 360

I’ve written about my PB360. Twice in fact. I still think that, even years after its original release, it still holds its own very well against the latest crop of Nooks and Kindles.

However, I’ll admit that the hassle of carrying a second device around means I hardly use my PB360 any more. I just want to read way more often than I want to carry around an e-ink reader. I do the majority of my reading on my phone these days; it’s a lot quieter and works in the dark.

Dingoo A320

I’m a big retro-gaming fan, and while I appreciate the strides in touch-screen based gaming on phones, give me a Sega Genesis and a controller any day. My Dingoo A320, on which I’ve installed Linux, lets me carry around pretty much every retro game, on every retro system, that I could ever want to play, and do it really well. When I want to play old games, this is where I go.

Fitbit

It’s amazing how quickly this little step counter as become “attached to my hip”. (Pun way, way intended). I’ve only had a Fitbit for a few months, but I think I’ve only ever forgotten to carry it once (and believe me, it bothered me all day).

I don’t put too much stock into its numbers- mainly it serves as a physical reminder for me to take the stairs over the elevator, to get up and take breaks from my desk at work. It’s just a really geeky string tied to my finger, but it works too well for me to give it up.

Home Technology

Internet, TV

I get Comcast High Speed Internet and average ~60Mbps down, ~15 Mbps up. I pay for TV service because it lowers my Internet bill, though I’m a cord-cutter in spirit: I have no cable-box and I haven’t hooked up a TV to the cable in several years.

Xbox 360

I work at Xbox, so it’s no surprise that I have an Xbox 360 in my home. Two, if you count Anne’s. Nothing special about it, other than a 250GB upgrade, though I do have a MadCatz Street Fighter IV Fightstick that I replaced the guts with a higher quality joystick and arcade machine buttons. I use it mainly for playing Pac-Man though.

My Xbox is set up in my game room / office with an Onkyo 5.1 surround system and (for now) a Insignia 32″ 720p HDTV. My 40″ Samsung 1080p HDTV is currently serving the living room, along with the other Xbox, an LG soundbar, and an LG Blu-ray player.

We have two Logitech Harmony 610 remotes, one for the living room, one for the game room. They’re perfect, and essential for keeping everything in sync. Haven’t had to touch the original remotes for anything in years.

Everything Else

These are just the things that I think of when I think of “what I use”. Believe me, I have lots more hardware lying around, though I try to regularly sell off or toss what I don’t use any more. Everything except cables: you can never have too many extra cables.

I have a Wii that’s ostensibly set up for retro gaming, though I haven’t powered it on more than a dozen times in the past couple years. I have a digital camera that I religiously charge the batteries for trips and events, but always forget to take pictures with.

“Too Long, Didn’t Read” Summary

I am a nerd with way too many toys and I’m rarely satisfied unless I’ve broken their warranty and made them do more than the manufacturer intended. Especially if it means getting a longer battery life. I prefer Linux over Windows, except with my phone.

And remember, this is just my personal stuff- none of this includes the tech I use for my work as an engineer at Microsoft. Hmmm, that might be an interesting post…

/jon

Update (9/22/12): Be sure to check out What I use in 2012, Part 2: Software.

P.S. So what do you use at home? Leave a comment below!

Setup a persistent local DNS cache on Ubuntu Jaunty with pdnsd and OpenDNS

Discalimer: I take no responsibility if you screw up your computer or can’t connect to the internet after following this! If you do mess things up, do what I do, head on over to Ubuntu Forums and ask for help.

What:

This howto will show you how to setup your Ubuntu Jaunty 9.04 machine to use OpenDNS to resolve DNS names, and keep local cache that will survive machine reboots. It’s a modified set of instructions that I first posted here.

Why:

There are several reasons why you’d want to to this.The quick one-liner: faster, more reliable web browsing. For a little more detailed response read on, otherwise, you can skip straight to the How below.

Need more info, okay. First, it might be a good idea to know what DNS is. Basically, it’s the address service that translates the domain google.com into it’s IP address 74.125.45.100. People generally find it easier to remember domain names than IP addresses. But the computer needs the IP address to load websites, so when you make a request for any files on google.com, your computer asks a DNS server for Google’s IP address. 99.9% of the time, your ISP provides DNS servers for your computer to use, and you don’t have to think about it.

But this address lookup takes time. Over the course of loading just one file, you might not notice it, but when browsing a web page, you’re probably loading dozens of files (images, scripts, etc.) This can mean lots of DNS requests if the files are on different servers. And ISP-run DNS servers don’t always have the best track records on being the fastest or the most reliable. Ever have your router tell you that you have an internet connection, but you can’t get to any websites? Usually, it’s because the ISP’s DNS server is having issues. So yes, technically your computer can access the internet, but you can’t really use it, unless you happen to know the IP addresses of everywhere you want to go. But, most of us get to Google through google.com, not by remembering 74.125.45.100.

So why use OpenDNS? Because generally it provides a faster, more reliable DNS service than what your ISP service provides. OpenDNS lets you setup filters, and much, much more. And why a persistent local DNS cache? Because even requests to OpenDNS take some time. And most websites rarely change their IP address, so why constantly lookup an address that isn’t changing? By using a local cache, your computer won’t have to keep asking the DNS server for addresses, because it will remember addresses that you’ve already been to. Sure, every now and then your computer will need to ask a real DNS server for an address, like when you go to a new website, or even occasionally for sites you visit often, just in case their IP address has changed.

Otherwise, even if your computer only remembers an address for 15 minutes, that’ll improve your browsing experience significantly. So, ready for faster browsing?

How:

Okay, so we’re going to install the local DNS server called pdnsd, and a support package called resolvconf. Pdnsd will be responsible for remembering DNS addresses, and resolvconf is responsible for letting your computer know to use pdnsd.

In a Terminal window, run the following to install both resolvconf and pdnsd in the correct order:

sudo apt-get update && sudo apt-get install resolvconf && sudo apt-get install pdnsd

When prompted during the pdnsd install, select “Use resolvconf”. Then run the following to create a config file for resolvconf:

gksudo gedit /etc/resolvconf/run/interface/opendns

In the new document, paste the following so that resolvconf will know how to use OpenDNS:

nameserver 208.67.222.222
nameserver 208.67.220.220

Finally save the document, exit gedit, and run this command in the Terminal:

sudo resolvconf -u

Congratulations, welcome to faster browsing. To check that everything is working, try the following:

dig google.com

Verify that the SERVER line shows 127.0.0.1#53(127.0.0.1), which means you’re pointed at your local cache. Look at the Query time, which should show how long it took to ask for google’s IP address from OpenDNS the first time.

Now, if you run that command again:

dig google.com

You should see a significant time drop, like Query time: 0 msec. That means that everything is working, that instead of asking OpenDNS for the IP address, pdnsd responded with the cached information, which took no measurable time.