Category Archives: Programming

Hide Facebook ‘Like’ News

If you use Facebook, you’ve probably seen entries like this in your news feed. facebook_like_newsThey seem to just be popular posts from pages that your friends ‘like’. I find them to generally be irrelevant, so I made a user script to hide them.

It was an interesting opportunity to poke around the Facebook frontend JavaScript code. I also tried out MutationObservers and built my knowledge of XPath, which is very powerful.

Code is in the Hide_Facebook_Like_News.user.js Gist, which also explains how to use it:

Passletters

passletters is a tiny command line utility to read a password from stdin and echo it with letters enumerated (for entry into web prompts that demand random, individual letters). The terminal scrollback is cleared afterwards.

sudo pip install passletters

NB: sudo may be needed to install the passletters script somewhere in your PATH.

https://github.com/inversion/passletters

https://pypi.python.org/pypi/passletters

Fezzle – Try all those bands you’ve only ‘heard of’

Fezzle logo

Fezzle is a new site I’ve created which is based around playlists of the most popular songs for artists playing at festivals. It’s a way to discover who the other bands are at a festival you’re (potentially) going to. It is borne of frustration from looking at line-ups and searching by hand on YouTube or Spotify, and is essentially a quicker way to do that without a lot of copy and pasting or alt-tabbing.

Current development status:

  • Tested on major desktop browsers as well as iOS simulators for iPhone and iPad
  • Festival list is rather UK-centric.

Planned features – Lots! But firstly:

  • Get more festivals included, especially those not in the UK.
  • More information displayed about festivals and artists (country, bio, etc.)
  • Some way to export or note what you liked – especially integration of favourites into the excellent Clashfinder.

 

Generate Favicons and Apple Touch Icons

Here is a script to generate different sizes and formats of favicon as well as apple touch icons for different tablets and phones. It uses the convert program which is part of ImageMagick.

As a starting point, create a square PNG with dimensions > 144px. I went with 512px. The script generates the different favicons for IOS, Android and desktop browsers as well as outputting the HTML to put in your header.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
 
convert favicon.png  -bordercolor white -border 0 \
          \( -clone 0 -resize 16x16 \) \
          \( -clone 0 -resize 24x24 \) \
          \( -clone 0 -resize 32x32 \) \
          \( -clone 0 -resize 48x48 \) \
          \( -clone 0 -resize 64x64 \) \
          -delete 0 -alpha off -colors 256 favicon.ico
 
HTML=""
for SIZE in 57 72 114 144
do
    for SUFFIX in "" "-precomposed"
    do
    FILENAME=apple-touch-icon-${SIZE}x${SIZE}${SUFFIX}.png
    convert -resize x$SIZE favicon.png $FILENAME
    if [ "$SIZE" -ne "57" ]
    then
        HTML=$HTML"<link href=\"${FILENAME}\" rel=\"apple-touch-icon${SUFFIX}\" sizes=\"${SIZE}x${SIZE}\" />\n"
    fi
    done
done
 
# Don't need the dimensions explicit for the 57x57 icon
mv apple-touch-icon-57x57.png apple-touch-icon.png
mv apple-touch-icon-57x57-precomposed.png apple-touch-icon-precomposed.png
HTML='<link href="apple-touch-icon.png" rel="apple-touch-icon" />\n<link href="apple-touch-icon-precomposed.png" rel="apple-touch-icon-precomposed" />\n'$HTML
echo $HTML

 

References:

How to Add a Favicon to your Site
Adding an Icon for iPhone, iPad & Android to Your Website
Don’t Forget About Favicons on Retina Screens
Apple: Custom Icon and Image Creation Guidelines
Microsoft: Customizing the Site Icon
ImageMagick Favicon Recipe

Apache 2.2 Websocket Proxying on Ubuntu with mod_proxy_wstunnel

Until recently, I was running a Node.js web application using Websockets with socket.io alongside an Apache web server. I wanted Apache to run on port 80 and serve both sites using name-based virtual hosting. However, Apache httpd mod_proxy couldn’t proxy Websockets correctly.

I discovered that there is a new mod_proxy_wstunnel module in the Apache httpd source trunk in an article describing how to backport mod_proxy_wstunnel to Apache 2.4 or 2.2. I figured out the specific steps for doing this on Ubuntu (tested on 11.10 with Apache httpd 2.2.20). I wanted to add them as a comment, but they were disabled on that blog.

Here are the steps, see the original blog post of the patch author for more information:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Check apache version (should be 2.2.20 as of writing, if not adjust the next step)
dpkg -s apache2
 
# Checkout apache source
svn checkout http://svn.apache.org/repos/asf/httpd/httpd/tags/2.2.20/ httpd-2.2.20
 
# Get patch and apply it
wget http://cafarelli.fr/gentoo/apache-2.2.24-wstunnel.patch
cd httpd-2.2.20
patch -p1 < ../apache-2.2.24-wstunnel.patch
 
# Build Apache 
svn co http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x srclib/apr
svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x srclib/apr-util
./buildconf # EDIT: Some commenters noted that buildconf should be run before the configure
./configure --enable-proxy=shared --enable-proxy_wstunnel=shared
make
 
# Copy the module and recompiled mod_proxy (for new symbols) to the ubuntu apache installation and update the permissions to match the other modules
sudo cp modules/proxy/.libs/mod_proxy{_wstunnel,}.so /usr/lib/apache2/modules/
sudo chmod 644 /usr/lib/apache2/modules/mod_proxy{_wstunnel,}.so
echo -e "# Depends: proxy\nLoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so" | sudo tee -a /etc/apache2/mods-available/proxy_wstunnel.load
 
# Enable the module (also make any configuration changes you need)
sudo a2enmod proxy_wstunnel
sudo service apache2 restart

Organise digital voice recordings

Recording lectures with a USB digital voice recorder left me with a lot of obscurely named files. Naming them according to what the lecture subject was by hand would have been very time consuming. I wrote a script to take an ical calendar file and match up recordings from the device with events on the calendar.

Given an input and output directory and a path to an ical calendar file (may be at a remote URL to use with Google Calendar or similar) the script will copy files and rename them according to corresponding events. Where there are multiple (or no) events occuring around the time of the recording, the script will name the recording as ‘uncategorised’.

It needs the icalendar module to run. The script can be downloaded here. See also the GitHub page.

It’s not limited to organising voice recordings and could be used to label any files with calendar events based on their modification timestamp.