Ramblings Of a Madman

Yeah, like i would know a good description…

Posts for Tag: tips

Avoiding SSL redirect loop

If you are configuring an nginx website to use SSL and - by any chance - you need to setup more than one “server” entry (for instance to make www redirect to the plain URL), keep in mind that you need to declare the ssl certificate mumbo-jumbo in both entries, otherwise browsers will enter a redirect loop.

Something like the following will do:

server {
        listen 443 ssl;
        server_name www.zenblast.com;

        include zenblast-ssl.conf;

        return 301 $scheme://zenblast.com$request_uri;
}

server {
        server_name zenblast.com;
        listen              443 ssl;

        include zenblast-ssl.conf;

        ...
}

zenblast-ssl.conf is where we define stuff like ssl_certificate, ssl_certificate_key, ssl on, ssl_ciphers, ssl_prefer_server_ciphers on, and ssl_protocols. Notice that the file is included in both entries.

Hope this helps save someone 30 minutes of Googling :)

'Google Drive new document bookmark'

Here's a neat trick: Bookmarks to create all sorts of Google Drive documents. This way you don't have to first access Google Drive and click on new, you can just have the appropriate bookmarks in your browser's toolbar. Just add these links:

- New Google Document: [https://drive.google.com/document/?action=new](https://drive.google.com/document/?action=new) - New Google Spreadsheet: [https://drive.google.com/spreadsheet/?action=new](https://drive.google.com/spreadsheet/?action=new) - New Google Presentation: [https://drive.google.com/presentation/?action=new](https://drive.google.com/presentation/?action=new)

Have fun documenting :)

Found - a Quicksilver alternative for Mac OSX

If you are looking for an alternative for [Quicksilver](http://www.blacktree.com/), the popular OSX launcher, you might find [Found](https://itunes.apple.com/us/app/found/id527134927?mt=12) (no pun intended) a suitable replacement.

To be honest it does not seem to be quite as powerful but, if - like me - you only use Quicksilver to launch apps, then Found is a great lightweight (and beautiful) alternative.

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 :)

On using MySQL and working remotely

A couple of interesting articles this morning, one about [why you should not use MySQL](http://grimoire.ca/mysql/choose-something-else) (i particularly love the expression "Mysql development and administration causes brain damage, folks...") and a [rant about remote work](http://ericfarkas.com/posts/a-short-rant-about-working-remotely/) and why companies still can't see the value in it.

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 :)

Sets - Link collections made simple

Meet [Sets](http://makesets.com), a website that allows you to create and maintain lists (or sets) of links. Much like with sex, you can do it solo or with other people. I think it has the potential to replace [Delicious](http://delicious.com) and other bookmarking sites even if, for now, it does not support tags or groups... although that's not necessarily a bad thing :)

The design is super simple and pleasing to the eye and they include a bookmarklet to help you link any webpage you visit, much like [Pinterest](http://pinterest.com) did. One of the features i love is the fact that it automatically retrieves the title for the link, based on the url you enter. I wish they would expand this to also retrieve pieces of text in the web page and let you choose if you wanted any of them as a start for the link's description.

Here's my first take on a set: [A collection of modern TV shows](http://www.makesets.com/best-tv-modern-shows). Check it out, you might have missed some ;)

JAVA vertical gradient background panel

Recently i had to create a gradient background for one of the panels in our [POS application](http://inforviegas.pt/wp-content/uploads/2010/09/VOS.jpg), so i though i'd share the code.

You need to pass the top and bottom colors of the gradient and also make sure that any panels inside this one are transparent (i.e. setOpaque(false)), otherwise they will paint above it.

import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints;

import javax.swing.JPanel;

public class VerticalGradientBackgroundPanel extends JPanel {

private Color topColor; private Color bottomColor;

public VerticalGradientBackgroundPanel(Color topColor, Color bottomColor) {

this.topColor = topColor; this.bottomColor = bottomColor; }

@Override protected void paintComponent(Graphics grphcs) {

super.paintComponent(grphcs);

Graphics2D g2d = (Graphics2D) grphcs;

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new GradientPaint(0, 0, topColor, 0, getHeight(), bottomColor); g2d.setPaint(gp); g2d.fillRect(0, 0, getWidth(), getHeight()); } }