Book - Nginx Module Extension

I’ve read another Nginx book (see my last review here) and this one is all about Nginx’s modular way and what modules are available. It’s called Nginx Module Extension

cover

It starts off with a basic walkthrough on how Nginx is built philosophically with its modularity and takes you through the config of the main module. Pretty basic stuff if you’ve used Nginx before.

Deniable One Time Pad with Vigenére's Tabula Recta. One piece of text, many solutions.

Encrypt


Here you can generate a cipher that carries many messages depending on the key used.
A so called Deniable Encryption.


Shorter plaintexts will be padded with -‘s so they match the length of the longest one.


Enter up to three different plaintexts blow and I’ll give you the keys and ciphertext for them.


Only dash and english letters are valid, upper- and lowercase. No spaces or other chars.




- 1:st plaintext


- 2:nd plaintext


- 3:rd plaintext





Decrypt


Enter a cipher and a key to decrypt it.


- Ciphertext


- Key



HAProxy as a static reverse proxy for Docker containers

I like Docker. A lot.

Everything I build and deploy now ends up in their own container on some server/VPS of mine. One reason for this is because of how easy it is to move the site or service to another server if needed. Just export and import the Docker container and you’re done. No config on web and database servers needed, it’s all done.

But there’s one thing you need to do. You can’t have lots of containers listening on the same public port 80, so you have to have your containers listening on some random port like 4553, 4566, 4333 etc. But your site’s visitors are coming to port 80 so you need to somehow listen to port 80 and forward requests to the right Docker container on the right port.

There are several ways to do this and I started out with Nginx as a reverse proxy. This works fine but I don’t want a web server doing that. I’ve used HAProxy in the past for load balancing. And it is actually just what I need, a load balancer is made for forwarding requests.

Avoid CORS with Nginx proxy_pass

I recently had to make cross origin AJAX requests (CORS), which was fine since I had control over the API server and simply adding these headers will make modern browsers ask the API server for permission and then make the request.

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET,PUT,DELETE
Access-Control-Allow-Headers: Authorization, Lang

But, of course, Internet Explorer want to be a pita and IE 8 & 9 does not support this (a part of it is supported, check out this table). And I have to support IE 9 at least.

So, nginx to the rescue like many times in the past.

Neo4j / Cypher: If not exists, get that instead

I’m starting to learn Cypher recetly since I’m doing a project backed with a Neo4j database.

One thing I bumped in to recently was a situation like this:



>
> A user can post a link. Users can comment on that link, and on other comments as well. (think reddit).
If someone comments on your link or on one of your comments, you should get an email saying so.
>
>

So, we have: (n:user)<-[:POSTED_BY]-(m:link) for the link.

And for the comments we have (n:user)-[:POSTED]->(o:comment)-[:COMMENT]-(m:link)

When you post a link or add a comment, a SUBSCRIBES_TO relation is added. Like this:

(n:user)-[:SUBSCRIBES_TO]->(m:link)
or
(n:user)-[:SUBSCRIBES_TO]->(o:comment)

Create a nested array recursively in Javascript

Let’s say you have an array like this:

[
    {id: 1, title: 'hello', parent: 0},
    {id: 2, title: 'hello', parent: 0},
    {id: 3, title: 'hello', parent: 1},
    {id: 4, title: 'hello', parent: 3},
    {id: 5, title: 'hello', parent: 4},
    {id: 6, title: 'hello', parent: 4},
    {id: 7, title: 'hello', parent: 3},
    {id: 8, title: 'hello', parent: 2}
]

And you want to have the objects nested like this:

Toggle WiFi Alfred Workflow

I switch a lot between wifi and wired network on my Macbook Air and to save battery I always turn my wifi off when using ethernet.

So I made this Alfred Workflow to toggle wifi status with ease.

The keywords are wifi on and wifi off.

You can download it here if you want to try it.

Extend disk in a VMWare client

If you have been allocated more space to your VMWare disk but it doesn’t show up when you run df -h, this post will tell you how to extend your last partition over your new blocks. The important thing here is that you can only extend your last partition without the risk of losing data.

Alfred Workflow - Upload most recent screenshot to Imgur

I needed an easy way to upload my last screenshot to Imgur. I have automatically uploading of screenshots to CloudApp but they preserve file names etc. I needed something that just takes my image and forgets that I sent it.

So, I created an Alfred Workflow to do this for me. The actual uploading is done by Bash Script Uploader. All I do is to find out where you keep your screenshots and take the newest one.

#!/bin/bash

DIR=$(defaults read com.apple.screencapture location)
FILE=$(ls -t "$DIR" | head -n 1)

CUR_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

#Upload
"$CUR_DIR/imgurbash.sh" "$DIR/$FILE"

The keywords to upload it are “ss to imgur“.

You can download it here >>

Cryptocat - Chat with privacy

Privacy and encryption should not be hard to use in a chat service. There’s a OTR option in Adium where users can start an encrypted chat.

But seriously, have you ever used it? This should be the default option and users who want to chat in the open can request that.

This is where Cryptocat comes in. It’s a chat service (based on XMPP I believe) that has OTR for all conversations, all the time. You don’t even have to option to skip it.

img1
Picka a name and a room to start.