The problem: You’re going to a festival with more bands than you could ever hope to see. You need a playlist with songs of all the bands playing so you can decide what to go and see and what to give a miss.

The solution: From a list of the artists, query the Spotify Search API with the artist name and save the URIs of the five most popular tracks returned by Spotify. Simples!

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

30

import requests# for querying the API

import json# for interpreting the data returned by the API

def top5(artist):

# an empty list of tracks

tracks=[]

# set up for requests module

query_params={'q':'artist:'+artist}# nospace after colon

endpoint='http://ws.spotify.com/search/1/track.json'

response=requests.get(endpoint,params=query_params)

print response.status_code

print artist

ifresponse.status_code==200:# server responds nicely

data=json.loads(response.content)# load the json data

i=0

whilelen(tracks)&lt;5:# check we have some results, or haven't reached the end of them if int(data['info']['num_results']) == i or 100 == i: break # construct our 'track' library track = {'name':data['tracks'][i]['name'], 'artist':data['tracks'][i]['artists'][0]['name'], 'uri':data['tracks'][i]['href']} # check the returned artist matches the queried artist if artist == track['artist']: add = True # Check the track is available in my territory -&gt; GB

ifnot'GB'indata['tracks'][i]['album']['availability']['territories']:

add=False

# Check the track isn't included already, eliminates including single and album versions

The code above is the function which you can pass each artist name to. It’s only a few more lines of code to feed a list of artists into the function and save a playlist list of tracks. I’ve deliberately saved more data than is needed for this task, as you never know when it will come in handy e.g. creating a script to query the playlist for all the artists that were successfully found.

Once you have all the URIs in a text file, with appropriate line breaks, you can drag this into the Spotify client and into a new playlist and they’ll magically become the tracks you want!

The chaps over at MAMA and Company announced the first batch of artists for The Great Escape festival this May, and with more than 100 announced and more to come, its time to get listening to my TGE14 Spotify playlist!

As with last year, I’ll be adding to it as more acts are announced and more tracks become available. As a rule, I’ve taken the top five most popular tracks from each artist (where present). Its work in progress, so do let me know if there’s something in there that shouldn’t be (I’ve tried to eliminate false positives this year).

And if you’d like to see the code that generated it, check out this post.

The problem: Take 1500 images captured from my Raspberry Pi and turn them into a 1080 HD video suitable for upload to YouTube, Facebook, and Vimeo.

The solution: Install ffmpeg and/or mencoder and use either tool to from the Terminal on my mac to compile the images into a suitable video format.

To install the command line tools ffmpeg and mencoder I followed this tutorial from aktagon.com which points you to the binaries available from Mac OSX port website ffmpegx.com, which in turn points you to a few other sourceforge websites to download what you need. Once your set and you can run ffmpeg and mencoder from the command line, you’re ready to go.

The first method I tried was using ffmpeg. I tried this originally with a smaller resolution timelapse (720 HD) and it compiled quickly and easily with a relatively small filesize. Thanks to Greg Heartsfield for the instruction on this approach.

This roughly translates as: use ffmpeg, with a frame rate of 25fps, with settings preset ‘hd720’, with the H.264 codec, to encode a video with a bit rate of 1 Mbit/s called ‘timelapse.mp4’ using jpg files that follow a image0001, image0002, image0003 etc schema.

However, my timelapses weren’t consistent with this approach, and on some I got tearing and grey blocks across the screen. It may be my ageing MacBook was to blame, but instead I sought an alternative approach. So after failing to compile the video using mencoder with the H.264 codec from this post on a Ubuntu forum, I settled on this PasteBin code from a RaspberryPi For Beginners YouTube:

The first line of the code is a handy trick to list all the jpg files of the current directory and save them to a text file. The second line I’m less certain of as I’m unfamiliar with mencoder, and with the success of this encode my desire to trawl Google was somewhat diminished. However, it should be said that this method took a lot longer to encode than ffmpeg and playback was still jerky in places – but I’m definitely putting that down to the MacBook. I would have also have liked to have used the H.264 codec but I couldn’t get the code I’d found elsewhere to work…

Do let me know of any improvements to the code above, or alternative/more reliable methods for encoding jpgs into a timelapse video.

The problem: Invert the colours of a Sublime Text 2 colour theme, so that when I invert the screen on my MacBook the colours are as if they weren’t inverted.

The solution: Write a python script that matches the hex colour codes (e.g. #ffffff) in the colour theme configuration file against a regular expression, and replace the hex colour codes with their inverse.

The code:

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

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

import re

def invertHex(hexNumber):

#invert a hex number

inverse=hex(abs(int(hexNumber,16)-255))[2:]

# if the number is a single digit add a preceding zero

iflen(inverse)==1:

inverse='0'+inverse

returninverse

def colorInvert(hexCode):

#define an empty string for our new colour code

inverse=""

# if the code is RGB

iflen(hexCode)==6:

R=hexCode[:2]

G=hexCode[2:4]

B=hexCode[4:]

# if the code is ARGB

elif len(hexCode)==8:

A=hexCode[:2]

R=hexCode[2:4]

G=hexCode[4:6]

B=hexCode[6:]

# don't invert the alpha channel

inverse=inverse+A

else:

# do nothing if it is neither length

returnhexCode

inverse=inverse+invertHex(R)

inverse=inverse+invertHex(G)

inverse=inverse+invertHex(B)

returninverse

def replaceHex(matchobj):

#exclude the preceding hash symbol of the matched object

hexCode=matchobj.group(0)[1:]

#invert the colour code and return with the hash

return'#'+colorInvert(hexCode)

#open and read the original file

f=open('Monokai.xml','r').read()

f.close()

#invert every match of the regular expression from f

invertedcode=re.sub('#([0-9a-fA-F]{6,8})',replaceHex,f)

g=open('Inverted Monokai.tmTheme','w')

g.write(invertedcode)

g.close()

Things to note: The python interpreter returns hex numbers with a preceding ‘0x’, so hex(255) yields 0xff. That’s why we use [2:] to grab just the last two characters of the value. The regular expression here is used to match six character RGB codes as well as eight character ARGB codes. RGB codes can also be expressed as three characters but in the tmTheme file I was working with none were present.

Background: Last year I was diagnosed with cataracts in both eyes. A white back-lit program or webpage is particularly difficult to read because of the glare caused by the white light. Fortunately on Macs ctrl + alt + cmd + 8 inverts the screen to help alleviate this. Unfortunately this meant by code editor (Sublime Text 2) got inverted too. So rather than having to flick back and forth between modes, when working between Sublime and the browser I thought it’d be best to invert Sublime to have my Mac screen consistently inverted.