He must really hate C

March 17, 2004
2 comments Misc. links

"This Kuro5hin user"n:http://www.kuro5hin.org/user/James%20A%20C%20Joyce must really hate the C programming language, but he must also know it very well. He's written a really long article about why C is such a bad choice of a programming language. If he's found so many things that are bad, how come he didn't stop using it and moved on to something better like C++, Java or Python?

I don't know C but I know the basics of C++ and compared to Java and Python it is pretty useless. However, it's bloody fast if that's what you're after. And a "more useful" programming language like Python is written in C.

So, if people realise that high-level programming languages like Python, Perl, Haskell are more useful for solving most tasks who's going to stay around with C and make sure we get these high-level programs?

The trend is to simplify programming languages and produce new ones that are easier to use. Surely we will always need low-level programming languages. For ever?

Virtual feminization

March 17, 2004
1 comment Misc. links

Virtual feminization of G. Bush "They all used to be Guys... They all have undergone the Virtual Feminization Process "

Really cool photoshopping. The sad truth is how well graphic artists can twist and turn pictures with the help of computers. One can take this is added proof that the girls on the Vogue cover aren't as beautiful as they look.

The Dead Zone

March 15, 2004
0 comments Misc. links

Map of Chernobyl I truely recommend that you read this slideshow gallery. The English isn't all that great but you understand it if you really try.

"I travel a lot and one of my favorite destination lead through poisoned with radiation, so called Chernobyl "dead zone" It is 130kms from my home. Why favourite? because one can ride there for hours and not meet any single car and not to see any single soul."

It's such a fascinating story.

"We had communists at power those days and they kept silence about this accident and then people start learning by themselves and real panic began in 7-10 days after disaster."

"in April 26-27, 1986 after reactor exploaded, people gathered on the roof of this building to watch a beautiful shining that rised above APP (the plant). [People] didn't know this was shining of radiation. they learned it on next day when evacuation began"

Truncated! Read the rest by clicking the link below.

Finished the bulk of my dissertation

March 15, 2004
1 comment Mathematics

This weekend I finished the bulk of my dissertation, which is a web application for academic staff to publish their academic papers online. The first target audience is for staff at City University Mathematics Department to whom I will deliver the project. The idea is that doctors and professors can submit their scientific papers on this web application. They enter some meta data about the paper such as title, abstract and co-authors and lastly upload the PDF or Word document that actually is the paper. The administrator will with time compile "Issues" which are basically bundles of papers published together with a little comment.

Registration is open to anyone but requires moderation. I.e. you can't log in straight after you have registered. Also all papers that registered members submit will need moderation too. This is done by a group of people (currently only me) who have administrator access.

My dissertation is about the computer science in building a web application. I.e. planning, data structures, algorithms, design, content management etc. It has "nothing" to do with mathematics even though I'm an undergraduate student of the mathematics department.

Please do go and visit the site and use it to help me get it as good as possible. There might still be bugs or spelling misstakes that needs to be taken out. When you register I will moderate you and please avoid rude words and try to make your example data as real as possible.

Now the last thing for me to do is to write the actual report about the project. That is what I will submit but my grade will based on the judgement of the web application. When I have finished my report I hope to show that on my web page too if I'm allowed.

The meaning of "hacking"

March 13, 2004
66 comments Misc. links

"Richard Stallman"n:http://www.stallman.org gives his explanation of what "hacking" is. I think I agree with him:

"Playfully doing something difficult, whether useful or not, that is hacking."

That's the definition people who hack like. To many people "hacking" is what you do when you "break security to gain access to a system". I often use the word "hack" as a ad hoc desperate technical solution. Much like filling a leaking hole in a dam with chewing gum. It stops the leak but just ain't right.

To readline() or readlines()

March 12, 2004
30 comments Python

UPDATE 2 (November 2017)

Sorry for not having updated this in so many years. 2004 was a different Peter and I'm sorry if people landed on this blog post and got the wrong idea.

To read lines from a file do this:


with open('somefile.txt') as f:
   for line in f:
       print(line)

This works universally in Python 2 and Python 3. It reads one line at a time by iterating till it finds line breaks.

When you create a file object in Python you can read from it in several different ways. Not until today did I understand the difference between readline() and readlines(). The answer is in the name. readline() reads one line character at a time, readlines() reads in the whole file at once and splits it by line.

These would then be equivalent:


f = open('somefile.txt','r')
for line in f.readlines():
    print line
f.close()

# ...and...

f = open('somefile.txt','r')
for line in f.read().split('\n'):
    print line
f.close()

The xreadlines() function should be used for big files:


f = open('HUGE.log','r'):
for line in f.xreadlines():
   print line
f.close()

Truncated! Read the rest by clicking the link below.

Python UnZipped

March 11, 2004
0 comments Python

Zipping and unzipping a file in Python is child-play. It can't get much easier than this. Well, in Windows you can highlight a couple of files and right-click and select from the WinZip menu. Here's how to do it in Python:


>>> import zipfile
>>> zip = zipfile.ZipFile('Python.zip', 'w')
>>> zip.write('file1.txt')
>>> zip.write('file2.gif')
>>> zip.close()

Still confused? Read this article for "Dev Shed"n:http://www.devshed.com/ then. The article includes some more advanced uses as well.

PSP - Python Server Pages

March 9, 2004
2 comments Python

"Python Server Pages (PSP), as you probably guessed already, is a way to inline Python in HTML or XML documents. The server interprets this inlined code to produce the final HTML sent to the client. This approach has become popular with tools such as JSP, PHP, and ColdFusion."

I really hope this catches on. It'll be the perfect alternative to PHP. PHP is very popular because it's easy to use but the syntax and execution is poor compared to Python. I guess PHP will stay strong for quite some time still but if PSP can get the tight Apache and MySQL integration that PHP has, we have a winner here.

Funniest Volvo advert ever

March 8, 2004
3 comments Sweden

Volvo advert On the same day 32 people bought the same car in the little Swedish town of Dalarö. The advert is about the new S40 Saloon but they've made a documentary only about the "fact" that 32 people bought the same car on the same day.

The film is embedded as Flash and takes a while to load, but you can download it as Quicktime or Windows Media if you like.

Worth watching if you as an unswede, want to get some insight into how normal Swedish people look and live and how they speak English. I think this also has large portion of Swedish irony in it, because even though it's all a joke, nobody smiles or laughs; you're on your own to understand it.