Last.Fm Spirit

Download Code on GitHub LastFmSpirit is a free Plugin for WordPress. It allows users to use WordPress Shortcodes to create tables and charts of data from the Last.Fm Api: It is written by Ashton McAllan: It is based on the LastFm library by tijsverkoyen: == Usage == To use the plugin you will need to enter your Last.Fm Api Key and Secret on the LastFmSpirit options page. You can get these by registering your application here: Shortcodes take the form: [LastFmChart attributeName="value"]apifunction[/LastFmChart] EG: [LastFmChart user="acegiak"]user.getWeeklyTrackChart[/LastFmChart] == Installation == This section describes how to install the plugin and get it working. e.g. 1. Unzip and upload the files to the `/wp-content/plugins/LastFmSpirit/` directory 2. Activate the plugin through the ‘Plugins’ menu in WordPress 3. Enter your API Key and Secret on the LastFmSpirit Options Page. You can get these from : == Frequently Asked Questions == = Why does it complain about the Api Key Or Secret? = In the options page enter your API Key and Secret on the LastFmSpirit Options Page. You can get these from :
Read More
So it seems pfefferle has schooled me again with his php wizardry. His refactoring of the semantic linkbacks plugin for wordpress is a much neater implementation than the higgledy piggledy mess that I worked together out of bits of spare code from around the place, with heaps more functionality.

I guess I should maybe stop spreading myself out over so many projects and focus on a few and maybe I could actually get some nice work done like this.

So I’ve managed to get dobby responding to text posts and reblog comments on his tumblr with a new module, which kind of makes up for the fact that you can’t gtalk with him since google disabled their xmpp compatibility.

I’ve also managed to make it so that it correctly embeds images in his replies and when he posts youtube videos when he’s bored, they are posted as video posts, which is neat.

Sheriff’s Secret Police Userscript

sheriffsSecretPolice.user.js Residents of Night Vale are encouraged to install this greasemonkey script to assist the Sheriff’s Secret Police  in monitoring all Night Vale citizens. It assists in the avoidance of Thoughtcrime by shielding the user from the results of Dog Park related queries. This is a greasemonkey script and requires: tampermonkey for chrome or greasemonkey for firefox or your own compatible alternative of choice
Read More
Using jQuery this is the smallest I can get an implementation of the Konami Code in javascript. This example uses it to make the page CAPSLOCK MODE.

function konami(){$("body").css("text-transform","uppercase")}
$(document).ready(function(){window.kc=0;$(document).keydown(function(e){window.kc=e.which==(new Array(38,38,40,40,37,39,37,39,66,65,13))[window.kc]?window.kc+1:0;if(window.kc>10){konami()}})})

QAD Normalized Google Distance

I was introduced to the idea of Normalized Google Distance as a measure of semantic relatedness between keywords today and it struck me as a really neat idea but I couldn’t find an implementation anywhere with which to play around. After playing around with a convoluted and far too manual Google Spreadsheet system I mashed up this code: #!/usr/bin/env python import math,sys import json import urllib def gsearch(searchfor): query = urllib.urlencode({‘q’: searchfor}) url = ‘’ % query search_response = urllib.urlopen(url) search_results = results = json.loads(search_results) data = results[‘responseData’] return data args = sys.argv[1:] m = 45000000000 if len(args) != 2: print “need two words as arguments” exit n0 = int(gsearch(args[0])[‘cursor’][‘estimatedResultCount’]) n1 = int(gsearch(args[1])[‘cursor’][‘estimatedResultCount’]) n2 = int(gsearch(args[0]+” “+args[1])[‘cursor’][‘estimatedResultCount’]) l1 = max(math.log10(n0),math.log10(n1))-math.log10(n2) l2 = math.log10(m)-min(math.log10(n0),math.log10(n1)) distance = l1/l2 print distance So if you want to play, there it is. Just beware that Google blocks you for a while if you start doing too many requests too quickly and each run is three requests.
Read More

QAD Minecraft IRC bridge

While waiting for bukkit to be released for minecraft 1.3 we moved out server to the pre-release version. We were happy to roll without plugins especially as we move towards a more hardcore server. What we did miss, however, was irc integration and the interaction with Dobby. This is a quick and very dirty python irc bridge I wrote up that connects to IRC with a socket which it parses and sends the say command to the screen minecraft is running in. It reads lines from the server.log file and passes those back to the IRC channel. It is known to work with the foonetic network. It will need a little bit of tweaking to work on other networks. #!/usr/bin/env python import re import time import sys import socket import string import threading import os #not necassary but later on I am going to use a few features from this  HOST=’’ #The server we want to connect to PORT=6667 #The connection port which is usually 6667 NICK=’MinecraftBot’ #The bot’s nickname IDENT=’pybot’ REALNAME=’MinecraftBot’ OWNER=’owner’ #The bot owner’s nick CHANNELINIT=’#channel’ #The default channel for the bot readbuffer=” #Here we store all the messages from server minecraftdir=’/pile/mc/mserv/current’ screenname=’minecraft’ s=socket.socket( ) #Create the socket lastline = [] reg = False def send(m): global s print m s.send(m) def parsemsg(msg): global screen complete=msg[1:].split(‘:’,1) #Parse the message into useful data info=complete[0].split(‘ ‘) msgpart=complete[1] sender=info[0].split(‘!’) com = ‘screen -X -S ‘+screenname+’ -p 0 stuff \”say IRC(‘+sender[0]+’): ‘+msgpart+’\r\n\”‘ print com os.popen(com) if msgpart[0]==’-‘ and sender[0]==OWNER : #Treat msgs with – as explicit command to send to server cmd=msgpart[1:] send(cmd+’\r\n’) print ‘cmd=’+cmd class ircloop(threading.Thread): def __init__(self): threading.Thread.__init__(self) def get_result(self): return self.result def run(self): global s,HOST,PORT,NICK,IDENT,REALNAME,OWNER,CHANNELINIT,readbuffer,reg try: s.connect((HOST, PORT)) #Connect to server s.send(‘NICK ‘+NICK+’\r\n’) #Send the nick to server s.send(‘USER ‘+IDENT+’ ‘+HOST+’ ‘+NICK+’ :’+REALNAME+’\r\n’) #Identify to server readbuffer=”” reg = False while True: time.sleep(0.1) print “——————————–” try: readbuffer=readbuffer+s.recv(64) temp=readbuffer.split(“\n”) readbuffer=temp.pop( ) except: temp = [] for line in temp: line = str(line) print line if line.find(‘ound your hostname’)!=-1 or line.find(‘have not registered’)!= -1: #This is Crap(I wasn’t sure about it but it works) s.send(‘NICK ‘+NICK+’\r\n’) #Send the nick to server s.send(‘USER ‘+IDENT+’ ‘+NICK+’ ‘+NICK+’ :’+REALNAME+’\r\n’) #Identify to server if line.find(‘Welcome to Foonetic’) != -1: reg = True s.send(‘MODE ‘+NICK+’ +B\r\n’) s.send(‘JOIN ‘+CHANNELINIT+’\r\n’) #Join a channel if line.find(‘PRIVMSG’)!=-1: #Call a parsing function parsemsg(line) if line.find(‘PING’) != -1: #If server pings then pong s.send(‘PONG ‘+line.split()[1]+’\r\n’) except IOError: print “fail” class logloop(threading.Thread): def __init__(self): threading.Thread.__init__(self) def get_result(self): return self.result def run(self): global s,l,lastline,reg,minecraftdir try: while True: time.sleep(0.1) c = os.popen(“tail –lines=1 “+minecraftdir+”/server.log”) l = c.readlines() for e in l: e = re.sub(“^.*?\[INFO\] “,””,e) if re.match(“^(<|.*?lost connection|.*? logged in).*”,e): e = re.sub(“<(\w*?)>”,”(\g)”,e) if e not in lastline and reg: send(‘PRIVMSG #machinespirit :’+e+’\r\n’) if len(lastline) > 10: lastline = lastline[:-10] lastline.append(e) c.close() except IOError: print “fail” thread = logloop() thread.start() thread = ircloop() thread.start()
Read More