Welcome

Hi there my name is Alan MacGregor and this is my blog, hope you enjoy it :)

25 Jun 2010

Show the Top 'N' in a group inside an SQL query

I've been trying to work out how to produce this for a while as I didnt want PHP to do the calculations and increase the server strain, thankfully after much searching I have come across this very helpful tutorial

http://www.artfulsoftware.com/infotree/queries.php?&bw=1245#104

This allows me to show the top 5 results for each group in my code it looks quite similar to this

SELECT seriesid, comicid, number
FROM (
SELECT
seriesid, comicid, number,
IF( @prev <> seriesid, @rownum := 1, @rownum := @rownum+1 ) AS rank,
@prev := seriesid
FROM comic t
JOIN (SELECT @rownum := NULL, @prev := 0) AS r
ORDER BY t.seriesid
) AS tmp
WHERE tmp.rank <= 5
ORDER BY seriesid, number, comicid;
This is an example that I was working on, it shows three columns (seriesid, comicid & number) from the table (comic)

21 Jun 2010

403 Errors in Dreamweaver when trying to connect to a mysql database

Afternoon all,
I've just spent the last 3 or so hours trying to solve a particulary annoying issue in Dreamweaver CS4, I wanted to connect to the mysql server using dreamweaver so I can create some code with a little more pollish than my current "nano" work. However each time i tried to fix this I got 403 error from the server. I did some minor work on the permissions (ie 755 chmod access) but nothing worked and then tried this and hey-presto it worked.

chown www-data\: _mmServerScripts/ _mmServerScripts/*
chgrp www-data _mmServerScripts/ _mmServerScripts/*


Obviously the above is valid for my setup and may require some modification for yours but it's a nice easy fix.

16 Feb 2010

Creating An Overly Simple RSS downloader in Python

I Wrote this script the other day as I was getting more and more annoyed that my version of uTorrent wouldn't download torrents from torrentbytes for reasons that I still am not sure of. Because of this I created a new script that fits my purpose.

The script is written for the TorrentBytes tracker but you should be able to modify the code to work on other sites too. Anyway here it is

#!/usr/bin/python

#######################################
# RSS Downloader for torrenbytes
# Programmed by Severed Spirit
#######################################
import os
import sys
from commands import getoutput

###Get Arguments
option = ""
if len(sys.argv) > 1:
if sys.argv[1] == "-c":
option = "check"
else:
option = "default"

###User Required Variables
cookie_file = "/home/alan/rss_downloaders/.lynx_cookies"
search_filter = "Saturday.Night.Live.*720p|" + \
"Aqua.Teen.Hunger.Force.|" + \
"30.Rock.*720p|" + \
"The.Office.*720p|" + \
"South.Park.*720p|" + \
"The.Big.Bang.Theory.*720p|" + \
"Rab_C_Nesbitt.*720p|" + \
"Family.Guy"
watch_folder = "/torrent/watch/"
prev_down_loc = "/home/alan/rss_downloaders/torrentbytes_downloaded"
tb_passkey = "###################"
tb_username = "###################"

###Initialise Variables
listoftorrents = ""
previously_downloaded = getoutput('cat ' + prev_down_loc)
rss_feed = getoutput('curl "http://www.torrentbytes.net/rss.php?passkey=' + tb_passkey + \
'&username=' + tb_username + '&direct" | grep guid').replace("&","&").split("")

for torrent in rss_feed[1:]:
torrent = torrent.split("")[0].split("\r")

#fix issue with curl data
if len(torrent) > 1:
torrent = torrent[0] + torrent[1].split("\n")[len(torrent) -1]
else:
torrent = torrent[0]

if option == "check":
print torrent

episodes = search_filter.split("|")
for episode in episodes:
items = episode.split("*")
found = "true"

for filter in items:
if filter not in torrent:
found = "false"

# Display torrent if all items are matched
if found == "true":
listoftorrents = listoftorrents + "|" + torrent

for link in listoftorrents[1:].split("|"):
if len(link) > 0:
torrent_name = link.split("&name=")[1]
if option == "default":
if torrent_name not in previously_downloaded:
os.system('wget -q --referer=http://www.torrentbytes.net/login.php --cookies=on --load-cookies="' + cookie_file + '" ' + \
'--keep-session-cookies --save-cookies="' + cookie_file + '" "' + link + '" -O ' + watch_folder + torrent_name)
os.system('echo "' + torrent_name + '" >> "' + prev_down_loc + '"')
print "Downloaded: " + torrent_name
else:
print "Already Downloaded: " + torrent_name
else:
print "No Torrents Found in Query"


All you have to do is modify the "###User Required Variables" section along with the cookie file and you should be set. I'd love to here what sites you've gotten this to work on plus if you can see where my code might have tried to join the failbus then please leave comments :)

5 Feb 2010

PS3? Why?

Recently I took the plunge into getting a nice shiny new PS3 Slim. It wasn't a quick buy though, the price was still quite expensive even though the price has gone down since launch.

The main reason I moved over to the PS3 was that I have had enough of the Xbox 360, recently practices involving microsoft policies and their hardware monoplisation had begun to annoy me more than ever. One main issue was due to XBLA, my machine had been locked out from going online (guess why) however there was a game that I wanted to play so I took my hard drive and swapped it with my brothers so I can buy it on my brothers and then swap it back and play it on mine. After I LEGALLY paid for the game I was surprised (more pissed off) that I couldn't play it because the game was not activated to play on this machine. How petty, I felt so enraged due to this that I havent played on the 360 since.

The PS3 is amazing, It's so much quieter than the 360 which lets face it was like having car revving up inside at times, I can also watch blu-ray which looks great. The thing I like about it more is that it just works and has a much more liberal feel to it unlike the 360s capitalist feel, it allows the use of things such as BBC iPlayer to be involved (The Xbox 360 will not be getting the 360 due to issues with the BBC being unable to charge viewers for content), it just works.

I'm just about to preorder the box set of FFXIII which is something that I've been waiting for a while now, I can't wait to play that soon.

BTW: My PSN username is severedspirit if anyone wants to add/check

25 Nov 2009

Xbox Achievement HTML Creator Update

Hello all,
I'm currently rewriting the code from scratch, the new code is written in python as its much cleaner than using .net code. The new code has many new features including:
- Multi OS support
- Faster creation of pages (due largely because the program downloads source only rather than leaving an ole to download the full page with flash, images, etc to ensure full data)
- Modular based.. ish (The code will feature a modular system to it meaning that new parts can be added into the code at any time, one feature in the pipelines is a twitter mod that sends out a twitter status update everytime you get a new achievement although there is a rather annoying bug I'm still yet to patch up)
- New graphs (Currently working on the last big graph but its a good one)

The only thing left to do at the moment is to check for consistancy and ensure that all user modifications has a globalised setting

I'll upload the code at some point in the very near future. To check up on the status get to http://twitter.com/severedspirit, I'm always updating it and I often update on the code progress

23 Sept 2009

My Twitter Page

As you can see this blog is pretty empty, mainly because I keep forgetting to update it (I will be updating it soon with some more code), however I do have a twitter page now which I update a lot, you can view the page at this address: http://twitter.com/severedspirit

13 Apr 2009

XBOX Achievement HTML Creator v0.2

Xbox Achievement HTML Creator v0.2 is out --> http://www.megaupload.com/?d=DS97VOX2
I decided to knock the version down to 0.2 while we get everything sorted

This includes a faster grabber which only gets data from games that you have achievements for. The other main feature is to create a graph that shows where you stand between you and another player, great for bragging rights, anyway, if you have any feature srequests or notice any bugs then please leave a comment
Template by - Abdul Munir | Daya Earth Blogger Template