All posts by admin

Install Nginx on EC2 Ubuntu instance

Fire up an EC2 Ubuntu instance

 

Connect via SSH as user ‘ubuntu’

 

Add nginx repo

File contents:

Save & close – [Esc] [w] [q] [Enter]

 

Install dev tools

IF:

where xxxxxxxxxxxxxxxx is a 16 digit hex code like 00A6F0A3C300EE8C THEN:

 

Install build tools for compiling

 

Create sources dir

 

Download and extract zlib ( http://www.zlib.net/ )

 

Download and extract OpenSSL ( http://www.openssl.org/ )

 

Download and extract PCRE ( http://www.pcre.org/ )

 

Install dependencies

 

Download and install Nginx ( http://nginx.org/ )

Note that 2>&1 | tee ~/sources/{file}.log logs the output to a file in your user’s home directory (on EC2 likely /home/ubuntu/) while still outputting to the console.

Now we can compile the installer. Warning – this is one LOOOONG-ass make…

If make fails with:

Nginx needs patching:

This means the lines ending in libssl.a and libcrypto.a need .openssl/lib/ removed from them.
To do this:

Navigate to and edit the code. Save and close. Run make again.

And finally, we can install:

[quickie] Regex for tags missing attribute

So to find images missing alt attributes:

There are groups in there so you can do a find/replace and insert the missing tag:

Now it is trivial to find the missing alt=”” tags, add them, and then fill them in by then searching for the empty attribute…

Set Diffmerge as Diff/Merge tool for Git

From the command line run each of these. You don’t need to be in particular directory.

Thus will work for *nix flavours including OSX. May not work on Window boxes or flower beds.

Now, whenever you want it to launch diffs just use difftool where you’d normally use diff:

N.B. These commands need to be run from the relevant directory for the project

To resolve merge conflicts, just run git mergetool:

http://twobitlabs.com/2011/08/install-diffmerge-git-mac-os-x/

 

Literary Javascript

A most amusing post comparing the theoretical code authoring styles of famous authors.

http://byfat.xxx/if-hemingway-wrote-javascript

*nix: “Multi-terminal” Screen config

I’ve been using screen a lot lately for it’s ability to have multiple terminal ‘windows’ open in one ssh session.

I came across this .screenrc file – at http://pastebin.com/853JXscd – and I’ve found it quite useful – the handiest thing is having the screen status bar by default.

Just save it as .screenrc in your home directory

Prism – JS/CSS Syntax Highlighting

Looks great.

Well, the dark theme is a bit, shall we say, chocolate-y, and the funky theme is a horrific 80’s headfuck (if slightly amusing), but hey, CSS is CSS so you can change that. The default theme is perfectly tasteful. More importantly it’s lightweight, fast and extensible. I should add it to this blog sometime.

http://prismjs.com/

[edit 2016-07] I use Crayon for wordpress these days, but Prism is still a great highlighter for adding to your own build  [/edit]

Cleaning up PHP – Terminal conditions with continue;/return;

PHP (or any language where code blocks are indented) can get a bit messy sometimes

OK, that’s not a literal example, but it does happen. If your condition is terminal, that is: if it is not met, no further action is taken; then there is no need to wrap a massive chunk of code in curly braces and indent it yet further. Break out of the cycle! If you are in a loop, you can just continue; – for example instead of:

you can do this:

In this ridiculously abbreviated example, it does look longer, and yes it will always result in more code, but where you have several terminal conditions in a section of logic which are separated by a number of lines, this technique can save you one hell of a lot of indenting, making your code that much more readable. Our original example, while longer, would be a lot simpler to follow:

In a similar way to loops, if you are in a function, you can simply return; (or return true/false; as appropriate) earlier rather than doing it in an else statement; Shocking? No. A revelation? Hardly, these are not new constructs. But common? Not from the code I see. Give it a go. I will…