Skip to content

If you need your computer fixed or your electronics set up, I have another website where you can request technical help from me! Only $40 p/h.


http://zephyrpc.co.nz

Better URL Cloaking


When I signed up for url cloaking with my domain provider, I was a bit disappointed to find that all the service offered was a frame pointing to the url I had designated to cloak. Like this:

image

This was done in such a way that I couldn’t do anything else with the zephyrpc address. For example I wanted users to be able to go to zephyrpc.co.nz/fixmypc, which would take them straight to the form they needed to fill out. However it would just take them to the main page instead.

I emailed the support channel asking if anything could be done about this, but they said that they did not control that part of the service and therefore couldn’t fix it for me.

So i took the matter into my own hands and wrote a bit of code that would provide the functionality i wanted, and that i could place on my own server.

I changed the masked url to special location that only contained my script. When the frame was loaded into that location, the script looks at the url that was typed in and takes out the parts that come after the base address.

For example if I go to zephyrpc.co.nz/fixmypc, the script will extract the /fixmypc part. Then it appends this onto the masked url, thereby changing the location being loaded to the correct page.

Extra for experts

Not only does the script extract the path of the url, it gets any variables sent as well. For example zephyrpc.co.nz?referrer=theodoreiii. The referrer variable will be passed on to the webpage loaded in the frame as well.

Here is the code for the script if anyone is interested:

Index.php:

<?php

$refer = $_SERVER['HTTP_REFERER']; //Get the referrer URL

//Extract the path and query parts of the url
$parse = parse_url($refer);
$path = $parse['path'];
$query = $parse['query'];

//If there is a query, then it needs to begin with a ? in the url
if (strlen($query)>0)
	$query = "?" . $query;

$destination = $path . $query;

//This is so the script is called every time, and not cached. Otherwise if you changed the URL, it would point to the previous page
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

//A 301 redirect changes the fame's contents to the new address
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://theodoreiii.nightingale.feralhosting.com/website" . $destination );

?>

New domain name for my website


Recently I gave my technical help website a domain name!


http://zephyrpc.co.nz

So if you need any tech stuff done just go there Smile

I will fix your computer!


I’ve made a new website advertising my technical knowledge to people who might need help with stuff:
http://eddietechsupport.net63.net/

Edit: new server: http://theodoreiii.nightingale.feralhosting.com/website/
Edit: new domain name:
http://zephyrpc.co.nz 

It’s in its first steps at the moment but I think it has a lot of potential! :D

So yeah if your computer breaks or you need anything set up just give me a shout!

(Yes i will give it some sort of proper domain name eventually)

PC Control – Core Temp status on server


Just a small improvement to the server form today, I made it also show whether or not core temp is running:

coretemp form

Extra for Experts

This was actually a lot harder than I expected, I had a separate thread running to check the status of core temp every so often but it ended up crashing the app.

Turns out python’s threading module doesn’t work very well when you try to call a QWidget.repaint() on a pyqt form from within it. Long story short I ended up using a QTimer object to poll for core temp instead, and calling repaint from in there was no problem.

PC Controller–UI for computer list


I’ve finally  finished the UI for the PC controller app that allows you do add, remove and control different computers:

Here’s what it looks like on android:

SC20111224-141228SC20111224-141244SC20111224-141252

and iPhone:

Screenshot_3Screenshot_4Screenshot_5

[Edit: oops i forgot to actualy add the iphone screenshots]

Also I managed to convert the app to use socket communication instead of http, so it is running much faster now!

Extra for Experts

I ran into a lot of trouble trying to get sockets actually working correctly in android. I am using Appcelerator’s Titanium SDK to build the app, and in theory what worked on iPhone should have worked in Android too, except it took me hours and hours to figure out why it wasn’t.

The trick was that Android was a bit slower at sending the data than iPhone was, and the server was rejecting the connection because no data had been sent.

Once I figured it out, I changed a section in the server so that it would keep trying to read the data until there was some, or it timed out. After that android sockets ran perfectly!

Hopefully someone in the same boat will come across this and be saved a ton of work trying to figure out what the problem was, so in order to help that along, here’s what I typed in to google when I was trying to figure it out:

“appcelerator socket.write doesn’t work android”

 

def ProcessRequests():
    """Accepts and acts on any incoming requests to the server
    """
    global s
    try:
        conn, addr = s.accept()
    except socket.error: #No requests at this time
        return
        
    print 'Connected by', addr

    data = None
    success=False
    TIMEOUT = False
    timeStarted = time.time()
    while success==False and TIMEOUT==False:        
        timeNow = time.time()
        if timeNow-timeStarted > 1: #Wait one second for some data, then timeout
            TIMEOUT = True
            print "Timed out waiting for data"
        
        try:
            data = conn.recv(1024)
            success=True
        except: #If there is no data yet, this will fail and success will still be False
            pass
            
    if not data: 
        print "no data recieved"
        return #No data
    
    ###
    Rest of the data handling done here
    ###

PC Controller – Making the server run faster


Today I was playing around with my PC controller app, and I noticed that it was taking quite a while for the host computer to respond to my requests. I figure that this is because the server makes use of a fully functional web server. In reality that is overkill for the job the server needs to perform, there’s way too much going on in the webserver that is just unnecessary.

So with this in mind, today I changed the way the server works. I ditched the webserver module cherrypy and rolled my own implementation using sockets. A socket is just a basic connection between computers, used to send and receive data. This is much more suited to my project, where the phone app just has to send a very simple command to the computer (e.g. Lock) and get a reply back that it worked.

Because the implementation is much more basic in terms of operation than before, I am expecting that the performance of the server will dramatically increase. I haven’t got around to changing the phone app to the new sockets protocol yet but I will shortly

Extra For Experts

If you want to see how I implemented the new server using sockets, here is the python source code:

from coretemp import *
from commands import *
import select
import threading
import time
from urlparse import parse_qs
import json
import socket


HOST = ''                 # Symbolic name meaning all available interfaces
PORT = 50007              # Arbitrary non-privileged port

s = None
t = None
EXIT = False
def StartServer():
    """Set up the socket for listening and start the recieving thread
    """
    global s,t, EXIT
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.setblocking(0)
    s.listen(1) #Listen with a queue of 1
    
    EXIT = False
    #Socket recieves requests in another thread, so that the UI can continue to update
    t = threading.Thread(target = recv)
    t.start()

def recv():
    """Function run in another thread, it constantly processes any waiting requests
    """
    global s, EXIT
    while not EXIT:
        ProcessRequests()
        time.sleep(0.1) #Wait a bit so the thread doesn't thrash the CPU
        
def StopServer():
    """Stops the recieving thread and closes the socket
    """
    global s, EXIT, t
    EXIT = True; #Tells the thread to exit
    t.join()     #Waits for the thread to exit
    s.close()
    
    
def ExtractArguments(request, data):
    """Takes data in the form request?var1=x&var2=y (URL format) and returns a dictionary of the keyword arguments
    """
    dict = parse_qs(data.replace(request+"?", ""))
    return dict
    
    
def ProcessRequests():
    """Accepts and acts on any incoming requests to the server
    """
    global s
    try:
        conn, addr = s.accept()
    except socket.error: #No requests at this time
        return
        
    print 'Connected by', addr


    data = conn.recv(1024)
    if not data: return #No data
    
    #The default reply
    reply = json.dumps({
        "error": "Malformed request"
    })
    
    if data == "MyName":
        reply = socket.gethostname().upper()
    elif data == "CoreTempInfo":
        UpdateCoreTemp()
        reply = json.dumps(ReturnCoreTempInfo());
    elif data == "Lock":
        Lock()
        reply = "SUCCESS"
    elif data == "LogOff":
        LogOff()
        reply = "SUCCESS"
    elif data == "Restart":
        Restart()
        reply = "SUCCESS"
    elif data == "Shutdown":
        Shutdown()
        reply = "SUCCESS"
    elif data == "Sleep":
        Sleep()
        reply = "SUCCESS"
    elif data == "Hibernate":
        Hibernate()
        reply = "SUCCESS"
    elif data == "VolumeUp":
        VolumeUp()
        reply = "SUCCESS"
    elif data == "VolumeDown":
        VolumeDown()
        reply = "SUCCESS"
    elif data.startswith("SetVolume"):
        dict = ExtractArguments("SetVolume", data)
        if dict.has_key("vol"):
            SetVolume(float(dict['vol'][0]))
            reply = "SUCCESS"
        else:
            reply = json.dumps({
                'error':'vol keyword argument not included in request'
            })
            
            
    conn.send(reply) #Reply to the client
    conn.close() #Close the connection

Some cool pictures for the day!


Some pictures of Freddie Mercury doing the awesome meme pose

freddie1

freddie2

IN A CAPE

freddie4

 

And here’s an adorable penguin chick!

OMFG

Googolpede: Doors!


So I’ve done a bit more work on Googolpede, now it has doors that are unlocked by a corresponding key. Red key unlocks red door, blue key unlocks blue door etc:

image

Also you can die in the lava now. Although in this level you’ll have to be pretty quick to reach it in time.

Anyway here’s the link if you want to have a play around:

Download Googolpede v0.02

PC Controller – Host UI


Today I created the window that will be displayed on the host computer when it is running the cherrypy server:

image

There’s not much to it, and eventually all that you will see usually will be a small task bar icon.

I’m also going to add basic control for common media players (start, stop, pause) to the app so that lazy people like me don’t even have to get up off the couch to pause their video Open-mouthed smile

Soon I will probably put the app and server up here for beta testing. Currently it only works in windows but I may expand it to work on Mac OSX and Linux if it’s popular enough.

Time to get on with some paid work so I can make rent yay!

Any suggestions on either the host software or mobile app are most welcome.

New game – Googolpede


Recently I’ve been getting back into game development, and this is what I’m working on currently:

image

You play as the “googolpede”, a creature who has so many legs, that your body is effectively infinite. The idea behind this game is that you need to navigate each level while never crossing your own body. In this very early version, the player is represented by the white blocks (its feet are the red line).

I am liking the idea of having different types of terrain (brown = dirt, blue = water, red = lava etc.), and that these types of terrain can interact with other types. For instance if a water block falls onto a lava block, it will cool the lava down to create solid lava (the black blocks). However if a lava block touches a water block in any other way, the water is evaporated.

There will be collectables (maybe stars, or your lost eggs) which will be placed in such positions that make it harder to complete the level while still not crossing your body.

Currently the game consists of one level. The objective is to reach the golden exit point.

Oh and you can’t actually die yet, so swimming in the lava is ok!

download googolpede.exe v0.01alpha

Also lol i found googolpede for windows 3.1… old school ftw

Follow

Get every new post delivered to your Inbox.