Posts for Tag: help

Nginx rewrite/redirect for blog URL

When i moved my blog to a [middleman](http://middlemanapp.com) system, i found that i needed to provide redirects from `/2012/01/25/some-post` to `/blog/2012/01/25/some-post`. It's a relatively simple task, though i lost some time because i missed a detail that no one usually explains.

There are articles on the web explaining how to do url rewriting in Nginx. Most of them will tell you something like this:

location /2009/ { rewrite ^(/2009/.*)$ /blog$1 break; }

In a gist, that's what you need. What they forget to mention is it will not work unless you provide the *root* in that *location* block.

Another thing you might want to do, to track eventual problems with your regular expression skills (hehe), is activate rewrite logging. It's also a good idea to inform clients that the resource moved permanently (301).

The full solution ended up being:

server { listen 80; server_name pedroassuncao.com *.pedroassuncao.com;

access_log /path/to/your/logs/nginx.access.log; error_log /path/to/your/logs/nginx.error.log;

rewrite_log on;

location /2009/ { root /path/to/your/html/; rewrite ^(/2009/.*)$ /blog$1 break; return 301; }

location / { root /path/to/your/html/; expires 24h; }

error_page 404 /404; }

A final note: When you activate `rewrite_log on;` nginx will dump all rewrite information to your *error* log as a notice. Since notice is the default it will show up. You can always make sure, by adding *notice* after the log file:

error_log /path/to/your/logs/nginx.error.log notice;

Happy nginxing :)

Automator service to resize image to several sizes

Here's an Automator service to [resize an image into several sizes](/files/workflow.zip). Unzip and copy the package "Multiple Sizes.workflow" to your **~/Library/Services** folder and you will get a new entry on the finder services context menu. Just right click any image and choose "Multiple Sizes" from the services menu.

For instance, if you select an image named "image.png" it will create the following files on the same folder:

- image_512.png - image_256.png - image_128.png - image_64.png - image_32.png

Feel free to open it up in Automator and modify to your needs :)

A collection of useful Ruby/Rails gems

Since lately i've been working a lot with Ruby (Android and Java as well, but that's a different story), i figured i posted a couple of interesting gems that will make your life easier, especially but not only for rails.

Slim

Slim is a templating engine (like ERB or HAML) which pursues simplicity. It helps you write an insane amount less HTML and Rails code. You will not believe your eyes. An example:

In HTML

<body> <h1>Markup examples</h1> <div id="content"> <p>This example shows you how a basic Slim file looks like.</p> <%= yield %> </div> </body>

The same in Slim

body   h1 Markup examples   #content     p This example shows you how a basic Slim file looks like.     == yield

Now tell me which one you prefer to write ;)

Stamp

A fantastic tool to format dates based on human readable formats. Why use Date.today.strftime("%Y/%m/%d") when you can use Date.today.stamp("2012/12/13")? Sweet, right?

Bugsnag

Bugsnag is web site exception grabbing on steroids. It basically monitors your website alerting you of any exceptions and providing the relevant information needed so you don't have to debug your production server.

Cool thing is, there are "bindings" for multiple languages and frameworks. You can find the one for Ruby/Rails here. 

Honey Badger

Honey badger has a really simple purpose: To make sure you know which server you are in (say, testing, dev, production) by displaying a small "badge" with the name of your choosing.

If you are like me you can easily think you are debugging something in testing when you are really looking at production. Ok, maybe that's just me, but the badge does look cool, right? :)

God

Now, i'm not one to call the name of the Lord in vain (i am!), but God is something i can no longer do without. It's a process monitoring framework written in ruby that keeps an eye on your server's, say nginx, apache or mysql and makes sure they are always up.

Further checks can be done, like for example restart the server when memory usage goes above X or CPU usage goes above Y. It is also capable of notifying you by email, jabber, twitter, you name it, when things happen. It's a true life saver :)

Hope you find these gems useful, as i did, and if you have some that i might find interesting, please do share via twitter :)