Saturday, August 6, 2011

More programming

Seeing as I haven't posted here in a while. Here is the latest update on my world of programmen:

C++: was the language required for my previous programming topic. Initial thoughts:
- this is better than Java
- templates are just macros
- STL is pretty neat
-

Java: required language for my current programming topic:
- still as overly verbose
- simple and easy to usehttp://www.blogger.com/img/blank.gif
- The amount of included resources is huge, you'd never get around to learning all of them

Python: just for fun, scripting, and bots:
- Easy to use
- Lots of libraries!
- I wrote a scraper to get the latest weather for my city from bom.gov.au
#!/usr/bin/python
import urllib2
import json

q = json.load(urllib2.urlopen("http://www.bom.gov.au/fwo/IDS60801/IDS60801.94675.json"))
for i in ['City','Temp','Wind','Rain','Humidity','Wind_Dir']:
print '%s' % (i.rjust(9)),
print
for i in ['name','air_temp',"wind_spd_kmh","rain_trace","rel_hum","wind_dir"]:
print "%s" % (str(q['observations']['data'][0][i]).rjust(9)),
print "${hr 1}\n"
p = filter(lambda x: x!="\r\n",urllib2.urlopen("ftp://ftp2.bom.gov.au/anon/gen/fwo/IDS10071.txt").readlines())

for i in p[5:8]:
j = i.split()
print j[0],"$alignr",' '.join(j[1:])[:-1]


PHP: Seeing I have a job or 2 to make some websites I've got the job of doing the backend. Both sites will use CodeIgniter and MySQL. The only difficult thing to design is a competition management system. Codeigniter is quite good and a huge step up from plain PHP. The myriad of included helpers and libraries simplifies a lot of things and the framework uses the MVC pattern which really separates out the presentation from the application.


I also got a github, so you can see the code I open sourced, the only thing I really update is TwatBot (a bot to post things from IRC to twitter).

https://github.com/JonnoFTW

Thursday, February 3, 2011

More php

So I got bored and whipped up 4 new things in PHP. After refreshing myself on a bit of SQL, I got to work and made a simple business site. It has editable pages via an admin panel which you can also use to upload images and add them into the pages. It is pretty much, a very simple and barebones blog system for small businesses. I'll probably make it generic enough to be rolled out whenever someone wants a similar system.


http://jonno.9ch.in/doors


The problem with this is that the client I did it for, had their own terrible hosting and domain (that's the www.example.com) name that won't update to point at it! Otherwise it was pretty simple after fixing problems with the layout of tables.

The second one was a Ticket Support system. It's basically a bug tracker, where if someone has a problem with some of our software, they can go there and submit a ticket, which will appear on a list for them and me. The idea being that I read the report and any comments and get around to fixing the problem. It also has a todo and FAQ system tacked on.

The third application I made is a text bulletin board system (there are a gazillion different sites like this). It's pretty simple, but getting the threads and comments to display just right took a while. Plus it has emergency raptors. You can see it here:


http://jonno.9ch.in/bbs/


The best feature I would say, is the uncrackable trip codes using Blowfish encryption. Normal trip codes (as seen on 4chan and similar sites) can easily be cracked on any modern computer within a few minutes. So you too can assume the identity of your favourite tripfagging poster.

The other thing I made was a Photo gallery, I originally set it up to store photos locally and use a database to manage them, but I then looked into the Picasa API which allows you to access the images from a picasa photo gallery. But getting this right has been a major problem, (mostly because the example code given only shows how to get the names of the images and not the images themselves). Rather frustrating really. Although I did find a nice slideshow to show them in which can easily integrate with flickr (you give it an album ID and it will use the images in that album in the slideshow). But picasa is a lot harder than that. You can view it here:

http://jonno.9ch.in/gallery/

All 4 of these make extensive use of a MySQL server. Which is a relational database management system that accepts 'queries' and will return a state from the server in the form a table similar to the kind of spreadsheet you might see in Excel. Or it will return an error if you made a syntactic mistake in your query, or a confirmation to say that the database has been updated. This made things a lot easier, because it avoids alternatives of constructing your own database or managing a convoluted system of files and folders. It's also quite fast (at the expense of consuming a lot of RAM) and the whole system is completely standardised and well documented. In fact, I should probably update the TPFC website to use MySQL...

Sunday, December 12, 2010

The horror, the HORROR

The past few days, I decided to teach myself PHP (PHP Hypertext Preprocessor). Essentially it's a parser that spits out html for a browser based on what it finds between in a .php file. Now the annoying part is what goes between those two tags.
It's horrible to write, there I said it, now deal with it. It's the kind of code that takes a while to write, it seems simple enough, but you just don't want to do it because coding it is so annoying.

That being said, it was pretty easy to learn (probably because I have good experience with html and programming) and code doesn't tend to result in sever runtime breaking because of its weakly typed nature (although it feels like it will lead to ambiguity but w/e).

Thus far, I've spent most of my time doing the admin panel, but I probably shouldn't let you see it.

If you would like to see what I wrote, it's all here:

http://users.adam.com.au/gmack1/tpfc/

Sunday, June 20, 2010

A post

To give the illusion that this is not dead. I guess you don't want to hear my life story in the absence of decent content. I also started to play the guitar. I just can't get past the association of a note with a pair of finger positions; I'll just say it's like typing and I have to get the muscle memory sorted out so I can just read sheet music and play from that.

Saturday, April 10, 2010

Merge and Sort

So, as an exercise in Haskell and recursive algorithms I implemented an exhaustive search called `search`, a faster and correct binary search called `bSearch` which requires a sorted list to start with to work correctly.


module Main where
import Data.List

search t [] = False --t is an item we want to check is an a list. if the list is empty, then obviously it can't contain t
search t (x:xs) | t == x = True -- if the first item in the list is the same as t, then the search returns the result of True
| otherwise = search t xs --if t is not the head of the list, search the rest of the list

bSearch t xs = bSearch' t (mergeSort xs) -- Binary search requires a sorted list, so we search through the sorted list, using t as the item we want to find
bSearch' t [] = False -- same as before
bSearch' t (x:xs) | t == x = True -- same as before
| t < x = pt fst -- since the list is ordered, we can check the first half of the list if t is less than x
| t > x = pt snd --otherwise we can check the second half of the list
where
pt f = bSearch' t $ f $ splitAt ((length xs)`div`2) (x:xs) -- to save time, here is another function that will perform a binary search on the half of the list you want (f)



On the sorting side I implemented the merge sort algorithm; wherein you keep break the list in half until you have pairs or a single and then sort the pairs and then rejoin everything together in the correct order (`merge`) after they've been sorted. This is implemented as `mergeSort`:


mergeSort :: (Ord a) => [a] -> [a] -- this says the sort function takes a list and returns a list. Each element in the list must be an ordered type, like numbers or letters which come in order
mergeSort [] = [] --obviously an empty list is already sorted
mergeSort [a] = [a] -- as well as list with one element
mergeSort [a,b] = order a b -- for a list with 2 elements, order them according to the definition below
mergeSort xs = merge (pt fst) (pt snd) --merge the 2 halves of the sorted lists, this will continue until the original list has been broken up into smaller lists of 1 or 2 elements
where
pt f = mergeSort $ f $ splitAt ((length xs)`div`2) xs

order :: (Ord a) => a -> a -> [a]
order a b | a < b = [a,b] --order a pair of things
| a > b = [b,a] --and return a list in the correct order, that is biggest at the right, and smallest at the left
| a == b = [a,b] --if the 2 items are the same, leave them that way

merge ::(Ord a) => [a] -> [a] -> [a]
merge [] ys = ys --merging the broken up lists back together, an empty list merging with a non-empty list, you just get the nonempty list
merge xs [] = xs -- they need to be in the correct order; same as above
merge xX@(x:xs) yY@(y:ys) | x <= y = x:(merge xs yY) --if x is less than or equal to y,(x and y being the first element in each list) the merged list will have the head of x merged with the rest of the first list and all of the second list
| otherwise = y:(merge xX ys) --same as above but reversed

Saturday, March 13, 2010

Photography on Nth Tce

Some new photographs

So there was a light show on North Terrace as part of the Adelaide Festival recently. I whipped out the camera and set it to long exposure on a tripod to see what would happen. Results below:

you moused over!






Thursday, January 21, 2010

And then I was all

NYAAUUUUUUU
And made this for project euler number 17 in a magical 15 lines. Screw you if you want numbers more than 1000 in word form.

module Main where
nones = ["","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"]
tens = ["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
num2word :: Int -> String
num2word n | x <= 2 && n < 20 = nones !! x
| x == 2 && n >= 20 = tens !! fst y ++ nones !! snd y
| x == 3 = nones !! fst z++"hundred" ++ a
| n == 1000 = "onethousand"
where
x = length $ show n
y = divMod n 10
z = divMod n 100
a | snd z == 0 = ""
| otherwise = "and"++num2word (snd z)
main = print $ length $ concatMap num2word [1..1000]