Archive for February, 2009

28
Feb
09

boom de ya da!


It kinda makes you wanna … break into song ?

Yep ! The world is just awesome !

26
Feb
09

simplest way to use select with sockets?


I’ve been playing recently with python and network programming. IMHO, writing a server that makes use of select seems to be the simplest select code I’ve ever read/wrote. Here’s how it goes:



import socket,select,sys,pdb

if(len(sys.argv) != 2):
	print "a port must be supplied"
	exit(1)
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
read_list = [sock]
sock.bind(("localhost",int(sys.argv[1])))
sock.listen(5)

while 1:
	current_data = ""	
	infds,outfds,errfds = select.select(read_list,[],read_list,0.05)
	if len(infds):
		for socket in infds:
			if socket==sock:
				clientsock,client_addr = sock.accept()
				read_list.append(clientsock)
			else:
				current_data = socket.recv(4196)
				if(not len(current_data)):
					print "client disconnected"
					read_list.remove(socket)
		for socket in [socket for socket in read_list if socket != sock]:
			if current_data != "":
				socket.send("a client wrote:%s"%current_data)

The code illustrates a VERY basic messaging “application”, that will listen on a user-supplied port. Each time a client writes a message, the server sends the message to all connected sockets. The message doesn’t get sent to server again ( notice the socket != sock ). The deal with select is that you need to supply it with a list to check for available data, this is the read_list. I’m no socket guru, but this really looks simple, right?

24
Feb
09

how to detect spiders/web crawlers

In the previous posts, I’ve written about the techniques one could use to perform web scraping. I feel it’s important that developers know how to detect spiders and how to restrict them.

I think that the StackOverflowquestion “How do you stop scripters from slamming your website hundreds of times a second?” compiles the best information related to this topic. You can read the whole thing here.

24
Feb
09

nice site

I recently found Java Specialists. It covers pretty interesting topics.

23
Feb
09

training day no.3

So, oficially, I’m not able to perform the 50 day plan from Never Gymless. That’s why I decided to throw my own:

  • one day with various exercises for upper/lower body
  • one day shadow boxing

I started the shadow boxing about a month ago, and I’m really noticing progress. I went from being able to sustain the effort 2 minutes to about 7 minutes. On the other side, the upper body training is pretty much keeping my muscles guessing, which I consider to be a good thing, as I’m sure this will help me progress quicker. Unfortunately, a upper body training session leaves my muscles sore for about 2 days. I’m sure that pretty soon this phase will dissappear.

Even though it may be too soon to be really sure about this, I am seeing great improvements with my back pain. Coding each day for several hours is pretty demanding on the back, and lately, I’ve been feeling it. The funny thing is that this back pain manifests mostly when I’m going to sleep. I am glad that for the past 3 days it hasn’t come back. I hope it stays gone 🙂

23
Feb
09

i’m learning scala

I like to be able to code in many differite programming languages. Right now, I can write code in: Java, C, C++, Perl, Python, PHP, JavaScript, Ruby, AutoIT . 3.days.ago I wanted to see what was all the fuss about Scala. I like the fact that Scala can easily pass as a scripting language, without the issues related to speed. One downside would be that the learning materials are not as many as I would like.

I’m sure Scala will make a nice addition in every coder’s toolkit! I challenge you to try it!

22
Feb
09

omg time

For some unexplained reason, I was convinced that today is 1 March.




Blog Stats

  • 215,219 hits