Reddit developers, please fix this

I previously mentioned how dumb it was for someone to have to wait 10 minutes to be able to post a comment on a different thread on Reddit, but this latest discovery is just delicious. Just tried to post a comment on a post where the submitter cle

Comments [0]

Android location provider mock

So, yeah, I resumed playing around with android, this time version 2.0. I'm really tempted to buy the new Motorola Milestone that should come out in Europe sometime between... now... and early next year, so I wanna be ready to create all the crazy

Comments [0]

Happiness hat

Holly crap, just when you think every weird thing has been invented here comes a new one to blow your mind. Introducing the happiness hat, the clothing accessory that makes sure you always have a smile on your face. Either that or you will experience intense pain until you do...

Comments [0]

Grabbing title tag from web page

At least a couple of options, the first using BeautifulSoup: import urllib import BeautifulSoup soup = BeautifulSoup.BeautifulSoup(urllib.urlopen("https://www.google.com")) print soup.title.string And the second one using lxml: import lxml.ht

Comments [0]

"Early riser" experiment conclusions

In case you didn't read my entry on becoming an "early riser" (i.e. someone that gets up every day at the same (early) hour), I started a 30 day experiment to see what would happen to me both physically and mentally if I did. These are the conclusion

Comments [0]

Fabric for remote deployment | Sugus

I recently came across a piece of software called “Fabric”. It has been made in python and its purpose is to help simplifying the process of deploying software to remote machines.

The really cool thing I like about it is that it’s much faster than, say, an ant script because it actually reuses the SSH connections it opens. This means that, if you copy a file to a remote host (using the ‘put’ operation), do some local copying, and after that perform a remote command (like starting a server, for instance), this latter operation will not need to open another SSH connection to run the command.

I managed to cut by a factor of 5 the deployment speed of some java services running on jboss just by replacing ant’s sshexec by fabric’s ‘put’ method and its siblings :)

But there’s a lot more to it: It allows you to configure multiple target environments and hosts (think about deployment to multiple nodes of equal functionality), perform remote commands with ’sudo’ and, since the configuration file is basically a python script, you can use all the pythonic sugar of your liking :D

More information about Fabric can be found here. You can get the latest (stable) version in their github page, and here is a reference of the available operations.

 

Comments [0]

Django template filter: Show list of objects as table with fixed number of columns | Sugus

I recently ran into the following problem: I needed to be able to display a list of users in a table that had a maximum of X columns. Since I could not find the solution on the Internet I decided to give it a try and here is my resulting template filter to do it:

def tablecols(data, cols):
rows = []
row = []
index = 0
for user in data:
row.append(user)
index = index + 1
if index % cols == 0:
rows.append(row)
row = []
# Still stuff missing?
if len(row) > 0:
rows.append(row)
return rows
register.filter_function(tablecols)

Then you can use it in your templates like so:

<table>
{% for row in members|tablecols:5 %}
<tr>
{% for member in row %}
<td>
{% show_simple_profile member user %}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>

It will break down the “members” list into a list of lists, each of the first being a group of (in this case) 5 users max.

Have fun :)

 

Comments [0]

OSX: Preventing iTunes from launching when pressing multimedia key | Sugus

If, like me, you have this annoying problem where iTunes insists on launching every time you press a multimedia key on your keyboard (for instance play/pause/next/previous song) the fastest and most effective way to work around it is to get rid of iTunes completely:

  • Move iTunes to the trash (from the applications folder);
  • Move FrontRow to the trash (from the applications folder);
  • Empty the trash;
  • If emptying the trash fails due to the iTunesHelper application being running do the following:
    • Open terminal/console:
    • Type “ps aux | grep iTunes”
    • You should see the process in the list. Get it’s process id (PID)
    • Type “kill -9 <pid>” to kill the process
    • Empty the trash
  • Extra step, remove iTunesHelper from the list of login items (system preferences -> accounts -> login items).

Use SongBird instead :)

 

Comments [0]

Python: Sort list of tuples by second item | Sugus

Straight from the PythonInfo Wiki:

>>> import operator
>>> L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)]
>>> map(operator.itemgetter(0), L)
['c', 'd', 'a', 'b']
>>> map(operator.itemgetter(1), L)
[2, 1, 4, 3]
>>> sorted(L, key=operator.itemgetter(1))
[('d', 1), ('c', 2), ('b', 3), ('a', 4)]

 

Comments [0]

Super useful article on PostgreSQL | Sugus

I’ve always been a fan of PostgreSQL, even though I’ve been forced to use MySQL at work for ages (you know, IT policies). Anyways, after reading this article I’m definitely switching all my pet projects to PostgreSQL. The documentation is amazing, the database itself is blazing fast and super scalable. And it’s open source. What more can you want? :)

 

Comments [0]

About

Genius. Incredible. Remarkable. Awesome. Cool. On top of that, I am extremely humble too.