16 Mar 2015

Heredoc in Javascript

Most programming languages have a syntax for defining multiline string literals. Here’s an example for Ruby:

monty = <<END
It's only a model.
Who's that then?
On second thoughts, let's not go there.
It is a silly place.

puts monty.inspect
#=> "It's only a model.\nWho's that then?\nOn second thoughts, let's not go there.\nIt is a silly place.\n"

Javascript, however, does not have such a syntax. You can just insert newline characters yourself (\n), but then you have to escape the actual newline aswell… It’s quite messy!

var monty = "It's only a model.\n\
Who's that then?\n\
On second thoughts, let's not go there.\n\
It is a silly place.";

There is, however, a funny hack :)

var monty = (function() {/*Well, we did do the nose.
What do you mean?
She looks like one.
You don't vote for kings.

//=> Well, we did do the nose.
//=> What do you mean?
//=> She looks like one.
//=> You don't vote for kings.

And that’s how you do Heredocs in Javascript!

18 Mar 2014

GIT delete remote branch

Because I forget EVERY TIME!

  • delete local branch
  • git push origin :deleted_branch

(or vice versa)

It’s so easy!

16 Jan 2014

Domain Renewal Group - Scam!

So you got a letter from the “Domain Renewal Group” regarding one of your domains? You have no idea who they are?

Well, just ignore the letter. They’re a bunch of dicks.


Apparently, the Domain Renewal Group’s core business is to scam people into transferring their domains to them and then charging a shitload of money for their “service”. As long as you just ignore the letter, your domains are safe!

See also

12 Dec 2013

Continuous Deployment with Github Pages

Or how to let Travis-CI merge into master if the build is successful.

It is way easier than I thought.


  • The travis gem
  • Travis-CI integration up and running (ie .travis.yml is set up).

Step 1: Acquire Github Access Token

This is required because we don’t want to write our Github username and password anywhere. Go to your Github Application Settings and create a new Token.

Step 2: Encrypt the token

Even the Token is not something to post on your Twitter.

travis encrypt -a - GITHUB_TOKEN=your_generated_token

Your token will be encrypted and automatically added to your .travis.yml file.

Step 3: Add some magic to your Travis config

‘nuff said. Add these lines to .travis.yml (note this are only two lines):

- '[ "${TRAVIS_BRANCH}" = "stable" ] && git push https://${GITHUB_TOKEN}:x-oauth-basic@github.com/${TRAVIS_REPO_SLUG}.git HEAD:master'

Now for some explanation: The first part, [ "${TRAVIS_BRANCH}" = "stable" ] && only runs the following command if the current branch name is “stable”. You can omit this if you want to merge from ANY branch, or change it to use another branch.

The second part, git push https://${GITHUB_TOKEN}:x-oauth-basic@github.com/${TRAVIS_REPO_SLUG}.git HEAD:master' actually pushes the currently checked out state into master. * $GITHUB_TOKEN holds our Token from above * $TRAVIS_REPO_SLUG holds ‘github_username/github_repo_name’ (in my case this is mhutter/mhutte.github.io).

Back story

To ensure new pages don’t break Jekyll (as I managed earlier this month), I use Travis-CI.

I started working on a development branch and only merging into master after the Travis build succeeded. However, being the lazy guy I am I asked myself: “Wouldn’t it be nice to let Travis automatically merge into master if the build succeeds?”

30 Nov 2013

Rails has_many and Strong Params

For a recent Rails project I had the following setup:

class Pager < ActiveRecord::Base
  has_and_belongs_to_many :users
  # rest ommited for brevity

In my view, I want to select 0-n users. Actually the first challenge was to create the checkboxes in a way the selected options get submitted as an array. It’s been ages since I last used checkboxes!

<input type="checkbox" name="pager[user_ids][]" value="1">
<input type="checkbox" name="pager[user_ids][]" value="2">
<input type="checkbox" name="pager[user_ids][]" value="3">

This way, the selected user IDs will get submitted as an array.

The next problem was Strong Parameters. Even though I added permit(:user_ids), I got an Error message saying something aling “Parameter ‘user_ids’ not allowed.”.

Digging in the API from ActionController::Parameters I discovered that only some scalar types are allowed. To allow Arrays, they have to be declared as such:

def pager_params
  params.reqire(:pager).permit(user_ids: [])

If you’re new to Strong Parameters, I highly recommend reading Strong Parameters by Example by sensible.io.

07 Mar 2013

mhutter.net, my new Home on the Intertubes!

After months years of procrastinating, I finally built this thing.

While some content is still missing (like the About Page) and parts are falling off here and there, I’m proud to be at least somewhere.

Thanks to the help of Jekyll, Github Pages, Twitter Bootstrap and many helpful people out there I did most of the “work” in just 1 or 2 days.

(Why did I always want to build my own Website with Rails?)

While I work on the small things (like comments and so) feel free to contact me at manuel.hutter at gmail.com or a social network. (see header)

BTW, is it a bad habit to misuse a Issue tracking system as a ToDo-List?

21 Feb 2013

Syntax highlighting for Tumblr

  1. Customize HTML for your theme, add this at the end of <head>
<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" type="text/css" rel="stylesheet"/>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js" type="text/javascript"></script>
  1. Add this to your Body-Tag: onload="prettyPrint()"

  2. Done. To actually make use of it, you’ll have to use the HTML-Editor. I recommend the following (HTML5) convention:

<pre class="prettyprint"><code class="language-java">...</code></pre>

Recommended Add this to your custom CSS:

.prettyprint {
  overflow-x: auto;

If you want a transparent background, add this inside the curly braces: background: none;

Optional To use a Theme, download the desired CSS file (or create your own), upload it to Tumblr and replace the default CSS file in step 1 (blabla…prettify.css) with the URL of your uploaded file. DONE!

(distilled from /dev/null’s post on this topic)

19 Feb 2013

I am Dyslexic of Borg

I am Dyslexic of Borg. Fusistance is retile. Your ass will be laminated.

Dyslexic of Borg

29 May 2012

NPM install yields "Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN"


user@host:~ $ npm install coffee-script
npm http GET https://registry.npmjs.org/coffee-script

npm ERR!     at ClientRequest.<anonymous> (.../lib/node_modules/npm/node_modules/request/main.js:483:26)
npm ERR!     at ClientRequest.g (events.js:156:14)
npm ERR!     at ClientRequest.emit (events.js:67:17)
npm ERR!     at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1256:7)
npm ERR!     at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:91:29)
npm ERR!     at CleartextStream.socketOnData [as ondata] (http.js:1288:20)
npm ERR!     at CleartextStream._push (tls.js:375:27)
npm ERR!     at SecurePair.cycle (tls.js:734:20)
npm ERR!     at EncryptedStream.write (tls.js:130:13)
npm ERR!     at Socket.ondata (stream.js:38:26)
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR!
npm ERR! System Linux
npm ERR! command "node" ".../bin/npm" "install" "coffee-script"
npm ERR! cwd /home/user
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.21
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/user/npm-debug.log
npm not ok


user@host:~ $ npm config set strict-ssl false


user@host:~ $ npm config set registry="http://registry.npmjs.org/"