Author Archive

Setting up Emacs, Ensime, SBT for Scala code

Ensime is an amazing plugin for developing Scala code in Emacs – it is very similar to the way Slime for lisp works, and works on the same swank RPC system that slime uses. It stands for “ENhanced Scala Interaction Mode for Emacs”, and provides many features that are commonly found only in IDEs, such as live error-checking, symbol inspection, package/type browsing, and basic refactoring. It’s pretty cool!

Here’s a series of steps that should get you on the path to nirvana programming scala with Emacs. Leave a comment if something doesn’t work for you! These steps are for OS X.

Install Scala

The best way to install scala is to follow the instructions here : Download Scala

Install SBT

SBT is the scala build tool – an excellent tool that integrates very well with a bunch of other tools. On OS X, the best way to install SBT is to use either MacPorts or HomeBrew. A simple,

sudo port install sbt

Install the scala-mode for emacs

The best editing mode for Scala is scala-mode2 for emacs. To install, add the following to your init.el script and evaluate the buffer using C-x C-e

(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(unless (package-installed-p 'scala-mode2)
(package-refresh-contents) (package-install 'scala-mode2))

Install Ensime

Download the latest version of Ensime from here.

Once this is unpacked into a directory of your choice, add the following into an emacs buffer and evaluate.

;; load the ensime lisp code...
(add-to-list 'load-path "ENSIME_ROOT/elisp/")
(require 'ensime)

;; This step causes the ensime-mode to be started whenever
;; scala-mode is started for a buffer. You may have to customize this step
;; if you're not using the standard scala mode.
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)

At this point, ensime is installed.

Install the ensime-sbt plugin

Download from here. To add an sbt plugin, the best place to do so is your home directory. Add the following snippet to your plugins.sbt file in /Users//.sbt/plugins/plugin.sbt,

addSbtPlugin("org.ensime" % "ensime-sbt-cmd" % "VERSION")

(Replace VERSION with 0.1.1 or the current version)

Alright – at this point, we have ensime, emacs and sbt integration set up.

So how do we actually use this?

Create a new Scala project

Lets start a brand new project to use these resources. Create a directory called ~/myproject and add the following folder structure,
.
├── project
├── src
│   ├── main
│   └── test

Inside of main, create a file called Main.scala with some sample code,

package com.myproject

object Hello {
  def main(args : Array[String]) = {
    println("Hello World")
  }
}

Now, run sbt in the directory, and on the prompt, type

ensime generate

Next, open the Main.scala file in emacs.

Typing M-x ensime and press enter – this should start the ensime client within emacs.

You’re all set – use the ensime manual to see some sample commands.

Grep patterns for URLs in logs

For mostly my reference, and anyone else who’s googling for it,


cat /tmp/my-log-file.txt | grep --only-matching --perl-regexp "http(s?):\/\/[^ \"\(\)\<\>]*" | awk '{print $1}'

The future of diagnostics

I was just thinking about this the other day!

anofi-Aventis just unveiled the iBGStar: a stand alone blood glucose monitor that can plug directly into your iPhone and iPod Touch. The device, which builds upon the existing diabetes-tracking technology WaveSense allow diabetics to test their blood sugar levels on the go, record notes, and send information to their healthcare providers via a free iPhone App.

via: http://blog.drchrono.com/?p=3640&preview=true

This is fantastic!

On the technical prowess of drug cartels in Mexico

I came across an excellent article in the New York Times today that goes in detail into the inner workings of drug cartels in Mexico – specifically that of the Sinaloa Cartel. This has been a rather hot topic of discussion in the US – the largest consumer of illegal drugs in the world, given its repercussions on the internal law and order situation in Mexico and its subsequent effects on the US. In fact, in recent years, successive Mexican presidents have made the abolishing of these cartels part of their election agendas, although it remains to be seen how effective they will be.

In any case, one particular passage caught my eye. This speaks of El Chapo’s (Joaquín Guzmán, the CEO of the Sinaloa Cartel) cartel and its level of sophistication when it comes to innovative means of transporting drugs between two points on the globe,

At first, Chapo’s organization controlled a single smuggling route, through western Mexico into Arizona. But by 1990, it was moving three tons of cocaine each month over the border, and from there, to Los Angeles. The Sinaloa has always distinguished itself by the eclectic means it uses to transport drugs. Working with Colombian suppliers, cartel operatives moved cocaine into Mexico in small private aircraft and in baggage smuggled on commercial flights and eventually on their own 747s, which they could load with as much as 13 tons of cocaine. They used container ships and fishing vessels and go-fast boats and submarines — crude semi-submersibles at first, then fully submersible subs, conceived by engineers and constructed under the canopy of the Amazon, then floated downriver in pieces and assembled at the coastline. These vessels can cost more than a million dollars, but to the smugglers, they are effectively disposable. In the event of an interception by the Coast Guard, someone onboard pulls a lever that floods the interior so that the evidence sinks; only the crew is left bobbing in the water, waiting to be picked up by the authorities.

My perspective of these cartels used to be one shaped by having seen hollywood movies set in South America, and from a book that chronicled Pablo Escobar’s life. Well, that got shaken up today.

With revenues rivaling Facebook or Netflix, a logistics network on the scale of Amazon or UPS, and technical sophistication in manufacturing submersible craft that rivals a small country’s – I wonder whether it will ever be possible for unorganized politicians under the duress of election agendas, lobbying and caucuses to ever effectively address this growing menace?

Judy trees

The Achilles heel of a simple digital tree is very poor memory utilization, especially when the N in N-ary (the degree or fanout of each branch) increases.

Enter the Judy Tree.

The Judy tree design was able to solve this problem. In fact a Judy tree is more memory-efficient than almost any other competitive structure (including a simple linked list). A highly populated linear array[] is the notable exception. Looking forward to implementing it!

Via : http://lambda-the-ultimate.org/node/741

Here’s to the crazy ones

I never had the privilege of meeting Steve Jobs. And yet, on hearing the news today, it felt like someone very close to me had died.

As someone I’ve followed from ever since I can remember – growing up listening to the stories of his showmanship and visionary designs, its hard to even remotely express the sense of loss I feel today.

Reading up on every book about him I could lay my hands on, watching liveblogs of new product announcements, and waiting with excitement at a WWDC or Macworld announcement – it almost feels like I actually knew him. And I think a large number of people from my generation share my feelings.

It is very rarely in a lifetime that you get to see someone like Steve Jobs accomplish the kinds of things he did – changing the very face of technology and entertainment as we know it. I’m so glad to have been in the valley to follow some of this first hand.

Here’s to the man who inspired an entire generation with his insane genius. And specially me.

Goodbye Steve. You’ll be missed.


NBDJS?

For all of you who land on this site using the google query “nbdjs” – it stands for “No Big Deal, Just Saying”.

Courtesy of an ex Stanford post doc who shall go unnamed – you know who you are! :)

Mark Twain on Whiskey and Civilization

I found this gem of a snippet today, and I rather agree with what it says!

“How solemn and beautiful is the thought that the earliest pioneer of civilization, the van-leader of civilization, is never the steamboat, never the railroad, never the newspaper, never the Sabbath-school, never the missionary — but always whiskey! Such is the case. Look history over; you will see.

The missionary comes after the whiskey — I mean he arrives after the whiskey has arrived; next comes the poor immigrant, with ax and hoe and rifle; next, the trader; next, the miscellaneous rush; next, the gambler, the desperado, the highwayman, and all their kindred in sin of both sexes; and next, the smart chap who has bought up an old grant that covers all the land; this brings the lawyer tribe; the vigilance committee brings the undertaker. All these interests bring the newspaper; the newspaper starts up politics and a railroad; all hands turn to and build a church and a jail — and behold! civilization is established forever in the land.

But whiskey, you see, was the van-leader in this beneficent work. It always is. It was like a foreigner — and excusable in a foreigner — to be ignorant of this great truth, and wander off into astronomy to borrow a symbol. But if he had been conversant with the facts, he would have said: Westward the Jug of Empire takes its way. ”

Reading Java properties file in Clojure

A simple and effective way to read properties files in Clojure, since they transform into Clojure maps!

(into {} (doto (java.util.Properties.)
         (.load (-> (Thread/currentThread)
         (.getContextClassLoader)
         (.getResourceAsStream "log4j.properties")))))

Next, to actually read this in, using atoms to swap the values like this seems to work,

(def *args* 
  (atom {:a 10, :b 20})) 

(defn -main [] 
  (swap! *args* assoc :a (read) :b (read)))

Decoding the US Military’s Cyber Command Logo code

From this Wired article here, it looks like there’s a number that is part of the cyber command’s logo – 9ec4c12949a4f31474f299058ce2b22a. Well, its 32 characters long, and looks like a hash. Sure enough, a quick python check later of the organization’s mission statement with md5 results in,

import hashlib
>>> hashlib.md5("USCYBERCOM plans, coordinates, integrates, synchronizes and conducts activities to: direct the operations and defense of specified Department of Defense information networks and; prepare to, and when directed, conduct full spectrum military cyberspace operations in order to enable actions in all domains, ensure US/Allied freedom of action in cyberspace and deny the same to our adversaries.").hexdigest()
'9ec4c12949a4f31474f299058ce2b22a'

Voila!