Author Archives: sam

Pretty print to console in Node.js

JSON.stringify is pretty cool, in fact you can use it to print javascript data structures in a more readable format.

Of course modern browser javascript consoles already format nested data for you, but this is really helpful when using console.log() in Node.js

console.log(JSON.stringify(window.location, null, 2));

// prints...
  "ancestorOrigins": {
    "length": 0
  "origin": "",
  "hash": "",
  "search": "",
  "pathname": "/category/web-dev/",
  "port": "",
  "hostname": "",
  "host": "",
  "protocol": "http:",
  "href": ""

JSON.stringify documentation

Analyzing mysql slow query log

I had yet to have a need for a tool to analyze a MySQL slow query log, after some searching I came across a tool I already had!

Most MySQL installs come with the utility mysqldumpslow which is great for parsing your slow query log. I needed to sort by lock time so I just ran the following:

mysqldumpslow -s l mysql-slow.log | less

I’m in love with git

A month ago I switched to git from subversion when I started at RealSelf. Now I’m in love.

Why I liked git before:

  • Distributed
  • Fast
  • Github
  • (hip)

Why I love git now:

  • Branching does not disrupt workflow

# ...working on myBranch...

git stash

git checkout someOtherBranch

# ...make your changes to someOtherBranch...

git commit

git checkout myBranch

git stash pop

# and I'm right back where I left off!

  • Rebase

# instead of:

git merge master

# and getting a messy commit log.. do this:

git rebase master

# and your commits starting after you branched
# are rewound and applied on top of the latest from master

  • The command line interface is so powerful and usable that I don’t rely on GUI tools (except for resolving conflicts)
  • Pull requests (Github again)

Disable Java plugins to avoid drive by installs

As a computer repair technician I clean up a lot of computers with Java based malware. Java is known for its zero-day vulnerabilities and as a popular vector for cross-platform attacks. Not to mention the fact that Java Runtime Environment (JRE) updates never remove old versions, and Java installs and enables plugins for all popular browsers (Chrome, Firefox, and IE). Continue reading