Autocomplete hostnames in bash gotcha

A while ago I figured out that bash can autocomplete hostnames that are in the hostfile (/etc/hosts). This works when you hit <Tab> after an @ symbol. For example, if you have something like "127.0.0.1 example.com" in /etc/hosts and in a bash prompt you type "ssh user@ex<Tab>", it will expand to "ssh user@example.com".

However, it occasionally seemed to fail. I just realized this is because bash will cache the entries in the hostfile, so if you open a terminal and add an entry to /etc/hosts, that session (and any that are already open) will not pick up the change! Any subsequently opened terminals will, of course. You can solve this issue with the stale terminals with "export HOSTFILE=/etc/hosts", which seems to reset the cache and give you the latest autocompletion options.

K Combinator in Scala

The K-combinator "manufactures constant functions: (K x) is the function which, for any argument, returns x". I wanted to add some logging in the middle of a series of transforms of a Scala collection, and this seemed like the right way to do it. For Rubyists, it works like Object#tap.

This implementation pimps objects to add a "k" method that takes a function. It executes the function, returning the base object. This lets you do convenient things like peer into a chain of transformations. You can use it like this:

 

scala> import Functional._

import Functional._

scala> List(1, 2, 3, 4, 5).k(println).map(_*2).k(println).filter(_>4).k(println)

List(1, 2, 3, 4, 5)

List(2, 4, 6, 8, 10)

List(6, 8, 10)

res0: List[Int] = List(6, 8, 10)

 

Throw { x => logger.log("Something interesting about x"+x.interestingFact) } in there instead of just (println) and you can see an example of more advanced usage.

Test Lists In-Order with Scala Specs

In Scala, you can test that two Lists are the same with sameElements:

List(1, 2, 3) sameElements List(1, 2, 3) // true
List(1, 2, 3) sameElements List(3, 2, 1) // false
List(1, 2, 3) sameElements List(1, 2, 3, 4) // false

So I wrote a test using Specs that was supposed to test that two lists had the same elements in the same order.

import org.specs.Specification
class FooSpec extends Specification {
    "these lists" should {
        "be the same" in {
            List(1, 2, 3) must have sameElementsAs(List(1, 2, 3)) // Pass, as expected.
            List(1, 2, 3) must have sameElementsAs(List(1, 2, 3, 4)) // Fail, as expected.
            List(1, 2, 3) must have sameElementsAs(List(3, 2, 1)) // ---> Pass, unexpected!!! <---
        }
    }
}

The trick is to use beTheSameSeqAs:

List(1, 2, 3) must beTheSameSeqAs(List(3, 2, 1)) // Fails, as expected :)

Windows 7 Outlook Cannot Open Attachment (Solution)

Windows users, have you seen this error when trying to open a picture from Outlook?

Cannot create file: photo.JPG Right click the folder you want to

create the file in and then check properties on the shortcut menu to check your permissions for this folder.

The problem is that your “temporary internet files” folder is filled to capacity. Right-click on “My Computer”, click “Disk Cleanup”, and make sure the temporary folders are checked. Click Okay and a progress bar will pop up showing the status of the files being deleted. Double-click the picture in Outlook again and it will open!

(This is the significantly easier version of the same solution that I’ve seen on the interwebs, that says to open regedit and find the OutlookSecureTempFolder and to clear it yourself.)

Selecting and Copying with Mouse in MacVim

In which I finally enable 1996-era functionality.

This has bothered me for a long time and I just figured it out. I started using MacVim a while ago but was unable to actually select and copy text like normal. I have had this mapping for ages:

vmap  "*y

which allows me to copy visual-mode-selected text to the system clipboard using Control-c (I haven’t been able to map the actually Command key). MacVim is supposed to give me that ability expect using the mouse and Command-C like every other Mac application. This never worked for me; instead it either did nothing (actually made some seemingly random text disappear because it was really just like hitting “c” in normal mode). Then I discovered this setting:

set mouse=a

That actually enables mouse support in any terminal that supports it, and MacVim is no exception. Just adding that simple set mouse=a gives me the expected mouse copy-paste. Finally I have caught up to 1996!

MacFUSE and TrueCrypt for Snow Leopard

TrueCrypt requires the MacFUSE filesystem extension. Unfortunately, the latest officially released version (2.0.3) is way out of date. It will install just fine, but after you try to open an encrypted volume in TrueCrypt, it will fail with an error like Failed to load /Library/Filesystems/fusefs.fs/Support/fusefs.kext - (libkern/kext) link error or Can't load kext com.google.filesystems.fusefs.

The fix for me was to install the 64-bit version, 2.1.7 (beta). You can get TrueCrypt 2.1.7 here. The MD5 hash of that dmg is e01786990111e7065a89cedf0a66ebbb. There appears to be another version out there, 2.1.9, but there are scattered bug reports and 2.1.7 works great for me.

Neo4j 1.3 community edition released under GPLv3 - same as MySQL

The excellent Neo4j graph database community edition has been released under GPLv3. This is the same license the MySQL has thrived under for years. The previous license license was too limiting for open-source developers to commit to neo4j. I believe there was a limit to 1 million nodes before one was forced to move to the commercial license. This is enough for small toy projects or to get a feel for the database, but not for a serious application or even a semi-serious nights-and-weekends project, and I think that for all its growth, this was a big barrier to adoption. Neo4j 1.3 Abisko Lampa supports up to 32 billion nodes/relationships and up to 64 billion properties -- all that is now available to any open-source developer. That's a big step up. I think neo4j's rate of adoption is going to skyrocket now. 

Google finishes ITA acquisition, turns flight search market into winner-take-all

Google's acquisition of ITA Software was cleared by the US Department of Justice. What does this mean for the many websites that use ITA's QPX flight query service? QPX searches a billion combinations of flight fares, schedules, and availability per query; this heavy lifting makes the nice, fast interfaces of Kayak and Hipmunk possible.

For the near future, nothing will really change since Google is supporting ITA's existing commitments and allowing customers to extend their licenses through 2016. After 2016, I imagine it will become a winner-take-all market because Google will just buy the best interface and shut off access to everyone else. Starting now, it's a race to see who can build the best interface to the QPX data. I believe Google would prefer to acquire based on quality of interface, not number of users, as they already have an enormous number of users.

This changes the rules of the flight deal search game, then. Rather than trying to acquire users to generate revenue, a company might want to focus 100% of its energy on building the flat-out best interface imaginable. Nobody is going to dump a large amount of money to acquire users in a market with a 5-year expiration date. This opens up possibilities for small players to out-innovate the existing websites and win the grand prize, being acquired. Alternatively, this opens up a possibility for someone to build an equivalent to ITA itself (no small task!). The latter option is particularly risky; if Google just continues to license ITA's software past 2016, then the market basically stays the same and there's no (less) space for a competitor.

Bonus question - what does this mean for Bing? Bing is a customer of ITA. Google could just shut them off, which is a big hit to Bing's goal of being a "decision engine".

It will be interesting five years from now to check back on this post and see how right or wrong I was.

Ten Rules for Entrepreneurs

Reid Hoffman's Ten Rules for Entrepreneurs

 

  1. Seek To Create Disruptive Change. Is this massive and different? Example: Skype
  2. Aim Big. It's the same amount of blood, sweat and tears to build a small company to flip as a big one to change the world.
  3. Build A Network to Amplify Your Company. Your network is a store of distributed intelligence that can enable you. It's important at the board and investor level and the rank and file.
  4. Plan for Both Good and Bad Luck. Opportunity will cross your path and you'll have to pivot to reach it. Plan Bs are intuitively easier to plan for.
  5. Maintain Flexible Persistence. Know when to be persistent, when to be flexible and when to be a combination of both.
  6. Launch Early Enough To Be Embarrassed By Your Creation. You'll probably be wrong about most of of your thesis, and you might as well get the feedback. Perfection is a myth. Get it into the mix. Don't undervalue the importance of time.
  7. Aim High But Don't Drink Your Own Kool-Aid. Find friends who will tell you when your baby is ugly.
  8. A Great Idea for a Product is Important. But a great idea for product distribution is more important.
  9. Pay Attention to Your Culture. Worry about getting hiring right from the very beginning.
  10. These Rules are Not Laws of Nature. You can break them.