Skip to Content

Cek's blog

Hi, I'm Francesco.

I like to write software and reading.
You may find me lost in Azeroth or Sanctuary.

Show how awesome you are with Better GitHub Widget for WP

Some of you may have noticed the new GitHub widget on the right, what you may don’t know is that I made it.
Before using WordPress to manage my blog I was using Octopress, one of my favorite features were the javascript plugins — in particular I liked the GitHub one — so I decided to make my own version for WP.

You can find it on WordPress.org or on GitHub.

Why should you use it?

Before writing my own widget I tried some other plugins I found on WordPress.org, they were all using curl to fetch the data from GH before responding to the page request.
From my empirical experiment this was causing a major slowdown on the loading time, but I don’t have any data to prove it so you should take this with a bit of salt.

The future

I have some ideas to expand the widget, shortly I will add the ability to:

  • Show forks
  • Hide the OctoCat

If you have any idea on how to improve this widget feel free to leave a comment or open an issue of GitHub.

Painless blogging with MarsEdit and Markdown

Recently I’ve been revisiting my blogging habits, one of the reasons I don’t post often is because, with my old workflow, the friction between thinking a blog entry and posting it was too high.
After spending an evening searching I found a workflow that suits my needs, the setup is very easy and if you follow along you will be up and running in no time.

My old workflow

My old workflow consisted in:

  1. Write the post in iA Writer
  2. Convert from markdown to html with Marked
  3. Post from WordPress web interface

The annoying steps where step 2 and 3, every time I had to make a minor edit to a post I had to convert it again.

My new workflow

My new workflow is:

  1. Write the post in MarsEdit
  2. There’s no step 2 :)

The setup

To make this working some steps are needed:

  1. In MarsEdit preferences, choose ‘HTML text’ as default editing mode
    Choose 'HTML text'
  2. To have a nice preview in MarsEdit, select ‘Markdown’ as the preview text filter under the blog’s settings
    Select 'Markdown'
  3. Install the Markdown on Save Improved plugin on your WordPress install and activate it. Leave the options unchanged.

Now every time you will click ‘Send to Blog’ the plugin will convert your Markdown to HTML and then publish the post.

Easily generate Amazon affiliate link with a Chrome extension

Update: I’ve published the extension on the Chrome Web Store, you can find it here.

Over the course of the weekend I had to generate some Amazon affiliate link to post on this blog, the problem is the links generated by Amazon own tool are too long.
For example the link to this item is 397 characters long.

So how did I solve this problem?
As you can guess from this post’s title I wrote my own Chrome extension, you can find it on GitHub.

Installing and using the extension

The extension is not available on the Chrome Web Store(at the moment, things may change), to install it you have to:

  1. Download the zip from GitHub and unzip it
  2. Go to the Windows > Extensions page in Chrome
  3. Check Developer Mode
  4. Click load unpacked extension and select the extension’s folder
  5. Click options and enter your tracking ID and hit save

Now visit any item page on Amazon.com, you should see an orange icon in the address bar, click it and copy the text in the field.

The extension in action

The generated link is way shorter than the Amazon’s generated affiliate link, only 50 characters!

How it works

As you can see if you inspect the DOM, the form on the right has a hidden field with value equal to the item’s code. Also an affiliate url on amazon.com has this structure

http://amazon.com/dp/ + ASIN-CODE + /?tag=YOUR-CODE

When you have all the data getting the solution is easy :)

If you want to give this extension a try go get it on GitHub, if you have any feedback feel free to contact me or open an issue on GitHub.

My Happy Hacking Keyboard Pro 2 review

A keyboard is something nearly everyone using a computer use, yet most of the people use the keyboard bundled with their computer. I was one of them, for the last years I used the keyboards Apple included with their macs.

Last month, after a period where I wrote at my mac for more than 5 hours a day I decided it was time to buy a “better” keyboard than my Apple Bluetooth keyboard.

After some searching on the web I found the Happy Hacking Keyboard Professional 2, it was the right size (I don’t like extended keyboards) and with a nice keyboard layout.

I bought mine on EliteKeyboards, you can also find it on Amazon (affiliate link).

The keyboard

Packaging and bundle

The keyboard arrives in a black box, the quality is not Apple-level but it’s still better than other companies’ boxes.

The box contains:

  • A manual written in japanese
  • The keyboard
  • The USB cable

After unboxing the keyboard you should customize the keys layout using the switches in the back, I choose to use the mac layout and to use the delete key as backspace.

How it feels

The HHKB is not very heavy but it feels very solid, I tried to apply force on the edges and it didn’t flex. The only thing that looks fragile are the switches on the back but it’s something you don’t touch very often, so you shouldn’t worry about them.

The keys are a pleasure to use, they are easy to activate and make a nice noise.

The keyboard does not feels like a mechanical keyboard, nor like a scissor-switch keyboard. It’s really hard to describe it and it’s something you should try for yourself.

The layout

The HHKB has a layout different from most other keyboards, it doesn’t have a caps-lock key and it has the Control key in its place.

Near the 1 key there is the Esc key, the numbers row is also the last row — to use the function keys you have to use the Fn key with a number key.

The Delete key is over the Enter key, it’s an unusual place but I like it, I use delete a lot more than \.

The HHKB doesn’t have the arrow keys, to use them you have to press Fn + the keys near enter, it takes only a couple of hours to get used to it.

I bought the blank version because I don’t use the QWERTY layout — I use Dvorak — and I found it’s very hard to press the correct number key, probably I only need some more experience. If you use QWERTY I think you should buy the labeled version.

Conclusion

The HHKB Pro 2 is the best keyboard I’ve ever used, but every review has to answer the question: “Is it really worth the €300 price tag?”.

I think that it’s a really tricky question and depends mainly from how much you can spend on it and how much you will use it.

A keyboard won’t make you a better programmer/gamer/writer, it can only make you time spent programming/gaming/writing more pleasant.

Why I decided to read less

When I discovered Hacker News for the first time I thought it was awesome, all that great articles to read everyday! And they are about startups/business/programming, so I’m not wasting my time!

I was wrong.

The articles are (mostly) great and worth reading if my time was an unlimited resource, but it’s not. Months ago I decided to go cold turkey and quit HN, Google Reader and Twitter to finally spend less time reading online and spend more time doing something real. Again, it was not the right move. I started wasting time, this time on Reddit and 9gag, a lot worst than reading HN isn’t it?

Finally I found this article on HN, what struck me was one of the comments. Farnsworth has a simple solution to this problem, after you have read an article write a short summary of it, a couple of sentences should be enough. I started adopting this method right away and it’s working, this morning I read only three articles(2 of them from my reading list) and spent the rest of my time doing my job: studying. Because every article requires some more effort — writing requires me to use a lot of mental energy — I tend to trash low quality articles and read only high quality/interesting pieces, the signal to noise ratio is a lot better.

One tool I recommend if you follow my advice is Pinboard and the relative iOS application Delibar, I use the description field to write my commentary on the article — another benefit is that I keep an history of interesting articles I find on the web. Writing a critique of an article also helps me fixing the content in my head, I need to read again the parts I didn’t understand well and lookup words I didn’t know.

Still this is not enough if your RSS Reader interrupts you every hour with dozens of new articles, this is a problem I solved months ago after reading Marco Arment’s article: Sane RSS usage. I’m subscribed only to low activity feeds or feeds with short articles(like daring fireball), I don’t follow general news websites or news aggregators.

Another trick I’ve learned is to manage my time with the Pomodoro technique, I force myself to read only in the 5 minutes break between each pomodoro. If an article requires more than 5 minutes I add it to my reading list — you can use services like Pinboard, Instapaper or Readability — and read it during the 25 minutes break.

Reading an entire issue of The Economist or The New Yorker requires a lot of time — english is not my native language and I need to lookup a lot of words — I usually choose the interesting articles when I receive a new issue and read them during the week.

This works great, I achieved a nice productivity boost without sacrificing my need of information and also I force myself to write each day — I hope this helps my (poor) english skill.

Creating World of Warcraft Textures Using Acorn and ImageMagick

In this period I’m working on a World of Warcraft addon, one of the first things I’ve learned is that to make a beautiful addon you need some custom graphic.
World of Warcraft accepts 2 image formats, BLP and TGA files; the former is a proprietary format while the latter is free.

On my reference book there’s an entire chapter dedicated to learn how to create TGA files for the game with different application(The Gimp, Photoshop, Paintshop Pro), the problem is I use Acorn to make my graphic and it doesn’t export TGA images.

Installing ImageMagick

Go to the official download page and choose your preferred method, I recommend to install it with homebrew.

$ brew install imagemagick

Converting the images using the terminal…

If you know how to move in the file system with the terminal you can convert a file simply using the convert or the mogrify commands.
The difference is that convert writes to a new image file, while mogrify overwrites the original file.

$ convert my-texture.png my-texture.tga
$ mogrify -format tga my-texture.png

…and without it

If you don’t know how to use the terminal, or you don’t like it, you can use a simple Automator Application I made.
Simply drop the image you want to convert on the icon and it will do the rest, note that you still need to install ImageMagick.

Setting a Custom Prompt in Ksh

Customizing the prompt, a.k.a. $PS1, is usually the first thing I do when I’m trying a new shell; if you are using bash or zsh there are many resources on the internet that teaches you how to do it.
But what if you are using a less-known shell like the Korn Shell? Usually the informations are outdated or incomplete. This tutorial is intended for the original ksh93, if you don’t know which version you are running run

ksh --version
# version         sh (AT&T Research) 93u 2011-02-08

or

echo ${.sh.version}
# Version JM 93u 2011-02-08

or

echo $KSH_VERSION
# Version JM 93u 2011-02-08

Basic prompt

Let’s start with a very simple example, I set the prompt to the classic user@host $

export PS1='$(logname)@$(hostname -s) $ '

$(logname) returns the output of the command enclosed in parentheses.

To show the current path use the $PWD variable.

export PS1='$(logname)@$(hostname -s):$PWD $ '

The result is
Basic Prompt

Add the colors

A black-and-white (in my case, grey-and-sand) prompt is so ’80s!
Let’s add some colors.

Color escape sequences have to be enclosed in \E[ m, for example $'\E[32mhello will display the string ‘hello’ in green.
To have a red prompt set $PS1 to

export PS1=$'\E[31m$(logname)@$(hostname -s):$PWD $ \E[0m'

Note the \E[0m before the closing ', this resets the text color.

You can add more attributes to \E[ m, the complete form is:

\E[bgcolor;textattribute;fgcolor m

The possible values for bgcolor are integers between 40 and 47, for fgcolor are integers between 30 and 37 and for tetxattribute are 0, 1, 4, 5, 7 and 8.

Refer to the following table for the colors

Color table

The values for textattribute have the following meaning:

  • 0: normal text
  • 1: bold text or light color, depending on the term preferences
  • 4: underscore text
  • 5: blinking text(yep!)
  • 7: inverse
  • 8: concealed text

Putting all together

My prompt is the following, you can modify it to fulfill your needs.

export PS1=$'\E[35;7m$(logname)@$(hostname -s)\E[0m:\E[32;1m$PWD \E[0m $ '

My prompt

Open an URL in Safari From Emacs

When I edit my tools’ configuration files I usually put in them the website from where I stole that nifty trick, months later I can remember why I did something that way.

Opening an URL from a text editor usually involves this steps:

  1. Select the URL
  2. Copy the URL
  3. Switch to the browser
  4. Paste the URL and hit enter

Emacs has the Browse-URL package, it allows us to open URLs we encounter in a browser. To do this put the following snippet of code in your .emacs file.

You can read more about open on the man page.

Now you can open an URL with C-c C-o, if the cursor is hover something that resemble an URL that URL is used as default.

Open an URL like a boss

Uploading a File to Amazon S3 Using Clojure and Noir

Before we start

To upload files to Amazon S3 we need, surprise!, an Amazon S3 account.

Go to the S3 homepage and signup, note that you need a credit card to do this.

From the S3 console make a new
bucket.

What we will use

For this tutorial we will use:

  • Clojure 1.2.1
  • Noir 1.1.0

Project setup

Create a new noir project, if you don’t have noir installed install it

lein noir new file-uploadr

Remove src/file_uploadr/views/welcome.clj, put this code in src/file_uploadr/views/upload.clj

Then start the web server with

lein run

and open it at http://localhost:8080/.

The form

Now we can write our page with the form. Change the definition of your "/" page to look like this

Notice that we had to add {:enctype "multipart/form-data"} to the form.

Play with the REPL

The form is ready but first we need to learn how to interact to Amazon S3 using Clojure, so start your REPL! M-x clojure-jack-in

Start by requiring the S3 util in noir

(require '[noir.util.s3 :as s3])
;=> nil

Create a map containing your S3 credentials

(def *server-spec* {:secret-key "SECRET KEY"
                    :access-key "ACCESS KEY" })
;=> #'user/*server-spec*

and a sample file

(def project-file (java.io.File. "project.clj"))
;=> #'user/project-file

Now we can upload our first file to S3!

(binding [s3/*s3* (s3/service *server-spec*)]
 (s3/put! "s3-tut" project-file))
;=> #<S3Object S3Object [key=project.clj, ...]>

You can find your file at https://s3.amazonaws.com/<bucket-name>/project.clj, the general URL is (http|https)://s3.amazonaws.com/<bucket-name>/<file-name>.

Now that we know how to upload a file we can finish our application.

Finishing the application

Add the following code to upload.clj be able to upload a file to S3

I use the (binding [s3/*s3* (s3/service *server-spec*)] …) because it seems there’s a bug in the with-s3 macro.

Refresh the page, upload a file, then go to your S3 console, you should see it here!

What needs improvements

The file you have uploaded has an ugly/random name and it’s doesn’t have the correct MIME type.

This can be annoying depending on what you plan to do with the files you upload.