Erik's blog

Code, notes, recipes, general musings

Archive for the ‘Uncategorized’ Category

Notes from “Web Application Development with Closure Compiler” talk by Alan Leung on 6/22/11

leave a comment »

Alan visited Twitter on 6/22 and presented an introductory talk on Google’s Closure compiler for JavaScript. Alan is tech lead on Closure team.

Here are the slides:


* JavaScript was originally designed for small DOM operations. Now that we’re building large-scale apps in JS, we can use some help.
* Google uses Closure for all but a couple products
* The Closure compiler can perform ~55 optimization passes, including linting code, validating function definitions, performing gzip-optimized compression, trimming dead branches
* Closure can also provide compile-time constants, e.g., “if(INTERNAL){…”, and trim unused branches that result
* Closure uses a graph coloring heuristic for variable renaming



Written by Erik

June 25, 2011 at 11:43 am

Learnings from an attempted robbery

with 2 comments

My wife and I were waiting for the BART when a woman started yelling for help. She said, “they stole my iphone!”

Her voice was coming from the stairs leading into the station. I couldn’t see her, but there were two young men, boys, really, jumping down the stairs three at a time. They were yelling back at her, “shut the f**k up. I never took anything from you.” It was difficult to determine if we were really seeing a robbery or just an argument.

But if a woman is yelling for help, and there are a couple people running away, something’s probably amiss. I started walking towards the two guys as they rounded a corner away from the stairs. They were moving out of view, towards the platform of an inbound train. They were trying to blend into the crowd.

I shouted at them, but they didn’t stop or look back. A person they passed said to me, “they’re going around the other side.” It took me moment to understand what he was saying. I was confused why he was speaking so matter-of-factly, and otherwise doing nothing to help.

Finally, I understood and reversed my path to head them off. When I came around the other side, they had broken into a run, and were heading directly towards me. A few people now, men and women, young and old, were trying to stop them. As we moved to push one of them against a wall, he started swinging, hitting a woman in the face. I grabbed for his leg to get him on the ground. We all fell. I grabbed the guy’s arms and held them behind his back. We restrained him until the police came.

Both men were arrested, and the phone was recovered.

My takeaways:

1) Yelling “HELP!” as loud as possible is good

I was surprised by how slowly the crowd reacted. Luckily, the victim kept shouting, and “help” is a pretty disruptive word. At one point I needed assistance keeping the thief on the ground. Shouting “help!” worked (see below).

I’d like to get more practice shouting for help and reacting to requests for help. These seem like a couple good skill sets to have.

2) Awareness of surroundings while using an iphone, ipad, etc in public is good

The officer we talked with at the BART station said this type of crime is very common. A person will be looking at his/her phone and a thief will grab it and run.

3) Yelling a description of the attackers is good

For example, “HELP! Stop those two guys! They stole my phone!” (repeat)

This helps people like me, who didn’t witness the crime, quickly get a sense of things.

4) Holding the attacker’s arms behind his back worked well

Here’s a more detailed description:
We were both sitting. I was behind him. His arms were behind his back, and I had my arms between his and his back. As my arms became tired, I grabbed my elbows.

At one point, the guy tried to get his feet under him and stand up. My hold would have been weakened by this, so I shouted for help. A man standing next to us then put his foot on the assailant’s hip and held him down. From this I learned …

5) Standing on an attacker is good

If two or three people just put their foot on someone on the ground, it would be super-helpful in keeping the person pinned. I hadn’t thought of it before, but it really works, and it seems like a low-risk way to assist.

6) Hitting someone is illegal

The woman who was hit had the wherewithal to recognize it as assault. I might have overlooked this fact. I very nearly didn’t get involved in the whole incident, thinking I was misunderstanding what I was seeing, but I was witnessing theft and assault.

7) Being a part of a community feels good

The thieves were just walking away from the victim, as though they expected no one to do anything. Had the train come a minute earlier, they could have jumped on and disappeared.

I’m so happy things worked out differently. Thankfully, the assailants weren’t armed.

My thanks to all the people who helped. The BART employees and police were great, esp. Officer Rodriguez. I feel like we’re a community. It became easier to help as more people became involved, and I became comfortable shouting and grappling and trusting other people with my safety.

Written by Erik

April 21, 2011 at 8:51 pm

Posted in Uncategorized

Tagged with ,

Trying out posterous

leave a comment »

Written by Erik

March 15, 2011 at 12:42 am

Posted in Uncategorized

hello world with Scala and sbt

leave a comment »


I’d like to learn more about Scala.  To get started, I’m going to run through a hello world example on sbt’s Google Code site.  Here are my system details:

  • Mac 10.6.6
  • Scala 2.7.7
  • sbt 0.7.4
  • Java 1.6


  1. Create a new sbt project by simply running the command sbt.  I set the name to “hw”, the organization to “”, and the project version to “1.0”, and accepted the defaults for the Scala and sbt versions but just hitting enter.  After building the project, sbt will leave a command prompt open.  Close this by typing ctrl-D.  Note: The quick start creates the code first, but then doesn’t talk about where to put it, which I found a bit confusing, so I’m presenting it here in reverse order.

    Screen shot of sbt creating a project

    Screen shot of sbt creating a project

  2. Create the file hw.scala in the src/main/scala/ directory generated by sbt:
    echo ‘object Hi { def main(args: Array[String]) { println(“Hi!”) } }’ > src/main/scala/hw.scala
  3. Compile the project: sbt compile

    Screen shot of compiling a project

    Screen shot of compiling a project

  4. Run the project: sbt run

    Screen shot of running a project

    Screen shot of running a project


So that’s that. It’s just hello world, but I found it helpful as an introduction to sbt’s relationship to Scala.  Time to call it a day, like these birds are doing:

birds on a wire

"birds on a wire" by touterse

Written by Erik

February 23, 2011 at 1:09 am

Posted in Uncategorized

Tagged with

YUI 2in3 Modal Panel Example

leave a comment »

Suppose you’re using YUI 3.2 and you’d like a modal dialog.  YUI 3 Overlay provides an easy way to position an element above the others, but it doesn’t provide modality.  The Overlay Extras gallery module sounds perfect, but it seems to work best with YUI 3.1.0.

YUI 2 has exactly what we’re looking for in its Panel widget.  Fortunately, the YUI 2in3 project makes the Panel available in YUI 3.2.  

The sample code below demonstrates usage, and you can see a demo on

    <body class="yui-skin-sam">
        <p><button id="show">show modal</button></p>
        <!-- modal dialog content markup -->
        <div id="content" style="visibility:hidden">
            <div class="hd">Header</div>
            <div class="bd">
                <p><button id="hide">hide modal</button></p>
            <div class="ft">Footer</div>
        <script src=""></script>
        YUI().use('yui2-container', 'yui2-dragdrop', 'event', function(Y) {

            var YAHOO = Y.YUI2;
            var modal = new YAHOO.widget.Panel("content", {
                width: "240px",
                fixedcenter: true,
                close: true,
                draggable: true,
                zindex: 4,
                modal: true,
                visible: false

  '#show').on('click', function() {
  '#hide').on('click', function() {



Written by Erik

January 10, 2011 at 6:04 pm

Posted in Uncategorized

Super-audacious scam email

leave a comment »

Wow. I just received a scam/spam email that takes the prize for most audacious. I guess the idea is McChrystal is hard up for cash(?). To be fair, the details are a bit dated, which, I suppose, could be interpreted as a wink to the better informed.

For your enjoyment, I reprint it below in full. I hope the author doesn’t mind 🙂


This is General Stanley Mc Chrystal from the states but on duties now in
Afghanistan the commander of the multi international forces here in
Afghanistan, first I apologies to you on contacting you through this media.

Actually I have gotten a business proposal for you dear sir, it may sound
strange or surprising to contact you through this media but really I am in
need of someone to help me from your country. 

I acquire $ 20, million dollars on the attack when we try to apprehend the
Taliban in a hidden cave here in Afghanistan.

I am looking for an honest and trustful person that is capable of handling
this transaction as we can understand that I am talking about hug amount of
funds and I will like to transfer the funds out of Afghanistan to any
country where the funds can be secure for some while until my arrival to
your country.

I could not transfer this huge amount of money to my country to prevent me
for been probe by the house of pentagon on how I made that hug amount and
to avoid been questioned by the United States government. 

This is a top secret transaction I do not want you to discuss this
transaction in the public places for security reasons and also to secure my
status and a serving American 4star General 

Please contact me via email address for more information detail regarding
this transaction:

Your email address and telephone contact is needed for easy

Best regards
General Stanley Mc Chrystal

Credit:,, and/or some unfortunate collection of writers & zombie machines

Written by Erik

October 21, 2010 at 9:13 am

Posted in Uncategorized

Tagged with , ,

getting started with ufw on Ubuntu server

with 2 comments

Rather than read the entrails of iptables syntax, I’d prefer to continue respecting myself, and use something more user-friendly, something like the Uncomplicated Firewall (ufw). I just learned about this, but it’s the Ubuntu default. I’d like to have faith, but for now I just hope it doesn’t suck.

The UFW wiki page linked above states “Setting the default mode of ufw is recommended before turning it on …”: sudo ufw default deny

That was easy. Next, I’ll enable it: sudo ufw enable

Now, I’ll allow port 2222 for ssh: sudo ufw allow 2222

And allow port 80 for tcp: sudo ufw allow 80/tcp

Check the current settings: sudo ufw status

Turn on logging: sudo ufw logging on

Ubuntu’s saying I need to restart in order for the changes to take effect. Fingers-crossed. Holding breath: sudo shutdown -r now …

As an aside, why does it have to be this way? Why can’t we just know that it will work? To be fair, UFW does seem pretty simple, and UFW’s –dry-run might be exactly what I’m looking for. Hopefully, UFW keeps me safe. Once I figure out how to automate deployment, things might be ok.

Ok, let’s check on the our ability to log in locally …

Good. I can still log in locally, so I didn’t lock myself out utterly. Checking local ssh as a sanity check: ssh -v localhost -p 2222

That works. Checking remote log in: ssh erik@ -p 2222

Hmm. That still doesn’t work, and nothing is showing up in either /var/logs/auth.log or /var/logs/messages. Lemme try viewing the iptables directly:
sudo iptables -L

Wow. UFW knows how to generate iptables. The list goes on forever. Let’s try again w/ less: sudo iptables -L | less

I can see 2222, www, and ssh allowed, so it’s not obvious why I can’t ssh in. Following a couple suggestions on the vmware forums, I set /etc/hosts.allow to “SSHD:ALL”, and set networking to “bridged”, but still no luck.

Ok. I’ll hang it up for now. Here’s a nice, soothing picture of a kelp forrest to chill out to:

Kelp Forrest at Monterey Bay Aquarium

Photo credit: Moral Threat

Written by Erik

October 18, 2010 at 11:03 pm

Posted in Uncategorized