Programming Update

September 14th, 2011 by Alan MacGregor No comments »

A lots been happening with regards to my programming recently, one of the first major things is writing OpenGL. OpenGL is a language I’ve always wanted to learn but it often went way over my head, around May time I decided that I would try and learn it and in turn create an iPhone game. What happened was that I got very confused but eventually got down to how the code works, I’m still quite new to it so I’m gradually getting better at it with learning to techniques to make the code work better. One of the surprising things about OpenGL (not surprising actually) is the amount of optimisation you need to make to ensure that the user gets to see a high a frame rate as possible. Anyway a game was released and is now on the App Store, it isnt selling very well but I still like the fact that it is my first proper game

Since I’m struggling trying to get a job as a programmer I have also decided to start learning additional languages, the two that I have chosen are C++ and Javascript. I have programmed in C++ in the past but I felt it would be best to begin from the start again and really master this language. I also decided to use javascript so I can get some really nice AJAX scripts running, I already have one which admittedly isn’t that great but it does a task that saves me time so its all good.

Well thats my update, hope you all are ok, byes

Dos and Do-nots of iPhone development

June 10th, 2011 by Alan MacGregor 2 comments »

A couple of months ago I revisited my very first app on the appstore, iWin, which when I first created was the best I could come up with, then after creating iUnlocked I came up with lots of improvements for my initial app. I appreciate that programming is a learning process but here’s some things that I did to my app to really improve the quality

  1. UITABLEVIEWs are your friend. Originally any of the setting views I had created were held together on a normal UIVIEW and a couple of UITEXTFIELDS. The problem with this is that they often tend to look a bit basic and can give the impression of bad design, this is why grouped UITABLEVIEWs are so helpful. Anyone whose used an iPhone for any period of time will be very apparent of these views, mainly with the fact that they are commonly used with settings, because of this people will understand what is going on with your app when you reach one of these views. These are also really useful in about views as they break the information up clearly
  2. ReloadData means reload ALL data, if you have a UITableView with numerous rows and only one row needs to be changed, reload that one row rather than all of them, its often a little more technical than just issuing the ReloadData command but the performance you gain back from doing so is often worth it
  3. You don’t always have to use the singleton to transfer data from one class to another, if you are opening a new view from another view simply parse the data into the controller directly into the other class, as long as the property is nonatomic, retain and the variable is allocated you should be ok.

Torrent Linker: Update

October 29th, 2010 by Alan MacGregor No comments »

A while ago I came up with a python script to link torrent newly downloaded torrent files to a folder allowing you to manage data more effectively whilst seeding. However I have only just realised that the initial script does not work as the importer appears to have removed the spaces at the start of each line making the code unusable. As I cannot find my original code here is an update that also features a twitter integration to send you a twitter message when a file has completed.

All you have to do is modify the items inside of “Modify These Variables”, also ensure to set your torrent program to move your completed torrents to the ‘torrentfilesdirectory’ folder

import os
import sys
from commands import getoutput

#Declare Variables
ary_errors    = []
ary_directory = []
ary_tracker   = []
ary_torrent   = []

#Modify These Variables
torrentfilesdirectory = "/torrent/torrentfilescompleted/"
torrent_completed_dir = "/torrent/completed/"
link_directory        = "/torrent/links/"
torrent_move_to_dir   = "/torrent/torrentfilescompletedandlinked/"
twitter_username      = "##########"
twitter_password      = "##########"

#Add list of torrents into variable
torrent_list = getoutput("ls " + torrentfilesdirectory)

#=====================================================
def WorkOnTorrents(line):
 #Read data from torrent
 directory = getoutput("btshowmetainfo \"" + torrentfilesdirectory + line + "\" | grep \"directory name:\"")
 directory = directory + getoutput("btshowmetainfo \"" + torrentfilesdirectory + line + "\" | grep \"file name.....:\"")
 tracker = getoutput("btshowmetainfo \"" + torrentfilesdirectory + line + "\" | grep \"announce url..:\"")

 #Modify the directory variable
 directory = directory.split(": ")[1]

 #Modify the tracker variable
 try:
  tracker = tracker.split("\n")[0].split("/")[2].split(":")[0]
  torrent_valid = "Works"
 except:
  torrent_valid = "Fails"

 print tracker;

 #Add torrent variables to arrays
 if torrent_valid == "Works":
  # Check Against Identified Errors
  if tracker == "":
   ary_errors.append(line);
  else:
   ary_tracker.append(tracker);
   ary_directory.append(directory);
   ary_torrent.append(line);

torrent_list = torrent_list.split("\n")
for line in torrent_list:
 WorkOnTorrents(line)

#=====================================================
## Create Links
print "Executing Links"
for i in range(len(ary_tracker)):
 os.system("curl -u " + twitter_username + ":" + twitter_password + " -d status=\"" + ary_torrent[i] + "\" http://twitter.com/statuses/update.xml")
 print "Creating Link for: " + ary_torrent[i];
 if os.path.exists(link_directory + ary_tracker[i]) == 1:
  os.system("ln -s \"" + torrent_completed_dir + ary_directory[i] + "\" \"" + link_directory + ary_tracker[i] + "/" + ary_directory[i] + "\"")
 else:
  os.system("mkdir " + link_directory + ary_tracker[i])
  os.system("ln -s \"" + torrent_completed_dir + ary_directory[i] + "\" \"" + link_directory + ary_tracker[i] + "/" + ary_directory[i] + "\"")
 os.system("mv \"" + torrentfilesdirectory + ary_torrent[i] + "\" " + torrent_move_to_dir);

#=====================================================
## Display Error Torrents
if len(ary_errors) > 0:
 print "Errors Found:";
 for i in range(len(ary_errors)):
  print ary_errors[i];

Downloading daily TV torrents on ThePirateBay

October 14th, 2010 by Alan MacGregor No comments »

There are many torrent download scripts online, I even uploaded one a while back, but this one allows you to selectively download episodes that have a date identifier rather than an episode identifier. Once again this is written in python, all you have to do is modify the source variable to contain the search string for your show, create a file in the same folder called downloaded and modify the watch_folder to the folder where you want the torrents to be downloaded to.  Have Fun

import os
import sys
from commands import getoutput
downloaded = getoutput('cat downloaded')
watch_folder = "/torrent/watch/"
source = getoutput('curl -s "http://thepiratebay.org/search/TV%20Show%20XviD/0/0/0" | grep "http://torrents.thepiratebay.org"').split("\n")
for item in source:
    item = item.split('"')[1]
    torrent_link = item
    item = item.split(".")
    date = item[5] + "." + item[6] + "." + item[7]
    if date not in downloaded:
        os.system('cd ' + watch_folder + ' && wget "' + torrent_link + '"')
        os.system('echo "' + date + '" >> downloaded')
        downloaded = getoutput('cat downloaded')

Show the Top ‘N’ in a group inside an SQL query

June 25th, 2010 by Alan MacGregor 1 comment »

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)

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

June 21st, 2010 by Alan MacGregor No comments »

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.

Creating An Overly Simple RSS downloader in Python

February 16th, 2010 by Alan MacGregor No comments »

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 Alan MacGregor
#######################################
import os
import sys
from commands import getoutput

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

###User Required Variables
cookie_file   = "/home/alan/rss_downloaders/.lynx_cookies"
search_filter = "TV.Show.*720p|" + \
                "Other.TV.Show"
watch_folder  = "/torrent/watch/"
prev_down_loc = "/home/alan/rss_downloaders/torrentbytes_downloaded"
tb_passkey    = "##########################"
tb_username   = "##########################"

def downloadtorrent(torrent_name, link):
 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 + '"')

if option == "download":

 downloadtorrent("Manually_Downloaded_Torrent_File.torrent", sys.argv[2])
 sys.exit()



###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("&amp;","&").split("<link>")



for torrent in rss_feed[1:]:
 torrent = torrent.split("</link>")[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.split("=")[2]

 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:
    downloadtorrent(torrent_name)
    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 :)

PS3? Why?

February 5th, 2010 by Alan MacGregor No comments »

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

Xbox Achievement HTML Creator Update

November 25th, 2009 by Alan MacGregor No comments »

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

My Twitter Page

September 23rd, 2009 by Alan MacGregor No comments »

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