Skip to content

Snippets

Password protecting folders with nginx

Ever wondered how you can password protect a folder and the underlying content with nginx the same way Apache does? Pretty simple.

First create a htpass-file like so:

htpasswd -bc htpass NewUser NewPassword

Edit your site’s configuration file by adding the following lines of code inside the server-block:

location ^~ /secret {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/htpass;
}

And your folder should be password protected. :)

Converting an avi to the Nokia E71 size

This is a oneliner to convert an avi-file to the correct dimensions of a Nokia E71. The screen is small, but sure beats to buy an iTouch if your cell already can play movies for you. :)

ffmpeg -y -i input.avi -acodec libfaac -ab 72k -s 320x176 -aspect 16:9 -vcodec libx264 -b 300k -qcomp 0.6 -r 25 -qmin 16 -qmax 51 -qdiff 4 -flags +loop -cmp +chroma -subq 7 -refs 6 -g 250 -keyint_min 25 -rc_eq 'blurCplx^(1-qComp)' -sc_threshold 40 -me_range 12 -i_qfactor 0.71 -directpred 3 output.mp4

.cue/.bin to .iso

First install the program called bchunk:

yum -y install bchunk

Now we convert .bin/.cue to .iso:

bchunk foo.bin foo.cue foo.iso

And there you go.

flac to mp3

for file in *.flac; do $(flac -cd "$file" | lame -h - "${file%.flac}.mp3"); done 

ssh-agent-script

To be placed in your .bashrc-file:

SSHAGENT="/usr/bin/ssh-agent"
SSHAGENTARGS="-s"

if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
  eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

ssh-clean-keys

Simple lines of code to clean invalid hosts from your .known_hosts-file.

ssh-clean-keys () 
{ 
    for host in $1 $(dig +short $1);
    do
        echo "Cleaning $host";
        ssh-keygen -R $host 2>&1 | sed -e 's,^,I,g';
    done
}

How to join multiple .avi or .mpg files

Imagine that you for some reason end up having several files, such as a.movie.avi.001, a.movie.avi.002, and so on. How do you then join them up into one big avi file? The answer is actually pretty simple – cat and mencoder.

Do the following if you don’t have mencoder installed:

# yum install mencoder mplayer

Then:

$ cat a.movie.avi.001 a.movie.avi.002 a.movie.avi.003 > a.movie.avi

That’s pretty much it, but there’s one final step before it’s done.

$ mencoder -forceidx -oac copy -ovc copy a.movie.avi -o a.movie.final.avi

And you’re done. :)