Thursday, February 27, 2014

Expedient way to move around Linux CLI

Hey all,

I have a solution for a common problem. When you're SSH'd into a server, it's a pain in the ass to cd around. Well, I wrote a small bash script that should make this much quicker.

It operates on the habit of bookmarking. If you're at a directory that you want to bookmark, you do this:

aguo@unix1:~/Documents/10605$ j add
Type an alias for the current working directory, or ^C to quit:
ml
and "j ml" -> ~/Documents/10605, etc.

To install, just save my .jrc file as "~/.jrc", and then ". .jrc" in your ".bashrc".


--Alex Guo

Tuesday, February 18, 2014

Cygwin -- Installing curl.exe

Hey all,

In this post, I'll be writing about a problem that took me a couple hours to resolve, especially since there was no other post that ran into the same problem.

So, this is the problem -- curl doesn't work:

$ curl
/usr/bin/curl.exe: error while loading shared libraries: cygcurl-4.dll: cannot open shared object file: No such file or directory

But I tried everything -- installing curl via setup.exe, apt-cyg install curl, etc. The source of the problem was that I was using the wrong terminal. I had a 64-bit machine, and I was using the 32-bit version of Cygwin. While working, it was incompatible in very important ways.

Even if you tried installing curl via setup.exe, you'd still have the wrong version of curl:

$ ls /bin | grep curl
curl.exe
cygcurl-3.dll

So you need to use the 64-bit Cygwin terminal, which will give you this output:

$ ls /bin | grep curl
curl.exe
cygcurl-4.dll

Sunday, February 16, 2014

Designing an online program to read from a stream

Consider the following scenario: you have a program that reads data from stdin.

Simple enough, right? But it's very easy to end up with a bad design, simply because, well, where do you start? What does this program really look like?

The idea is to have a Worker object handle each line, which will pass the line to a Parser object. The Worker will ask the Parser if the data is ready to be collected, and if it is, then the Worker will collect the data and do something with it.

This is the rough program skeleton, in Java pseudo-code:
That's the main outline. Everything can be easily built on top of that.

Notes:

  1. dataReady() is very good design, because it allows the parser to get the data in blocks of 2 or 3 or k at a time. If you were to handle the data immediately after each line was parsed, then you could only handle a block of 1!

Thanks to:
  1. Anthony Guo for reading drafts of this post.