July 01, 2009
Here is another post from the land of bash/shell scripting, this time instead of focusing on usability of tips the focus is thinkering
sudo echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
bash: /proc/sys/vm/dirty_writeback_centisecs: Permission denied
I bet you wanted to do something like that? A naive user would think this will write 1500 in that file, well, that’s not the case
. What really happens here is that bash first redirects the stdout that file (meaning that the redirection is performed as current user) and only than executes the command (which is executed as root). An ugly workaround or this kind of a problem is to create a script and than sudo execute that, a quicker workaround is to pass shell string argument:
sudo bash -c 'echo 1500 > /proc/sys/vm/dirty_writeback_centisecs'
Here are two links really worth reading (which i think belong in the category of “best practices”):
Everyone (hopefully) knows not to use `ls`, but what are the cases when the alternative is just too painful? So far i found only one, when you want to do something (to which the chronological order matters) with rotated logs, web servers usually give you a bunch of files like access.log.15.gz access.log.7.gz access.log.12.gz.
for i in access.log*.gz ; do gunzip "$i"; done
for i in `ls -v access.log* | tac`; do cat "$i"; done
First step in processing should be obvious, we simply decompress the gzipped files. As a side note, gunzip is retarded
, it can’t handle multiple files at once and it forces you to use .gz extension. The second line is very unportable, it will work just on the GNU coreutils (due to ls’s -v), what it does is print you the web servers logs as web server would write them, suitable for any kind of post processing. A real world use case would be you have logs stored this way but haven’t run webalizer (or whatever) on it.
Let’s have a look a close look at find(1)’s execution of non trivial commands over the matching files. You can ofcourse take easy way out and create a script, but real man use bash -c!
find . -exec bash -c 'for i; do echo "b00$i"; done' -- {} +
The interesting bits here are:
- We are using ‘+’ to terminate the expression, that tells find “accumulate as many files as possible (on linux: getconf ARG_MAX) and than pass them for one execution”
- ‘–’ is here for bash, it tells it “stop taking command line switches”
- -c argument should be quoted using single quotes (’), with double quotes (”) things like $i would be expanded by current shell before they even get to the invoked shell. In this example the output would be just a bunch of “b00″’s
- It appears that we are not looping through anything, bash implicitly loops through positional parameters if nothing is passed to for keyword
- {} should be quoted to work with files with spaces, right? wrong!
The steps that happen here are:
- bash sees the {}, it doesn’t mean anything to it so it passes it as is to find
- find sees the {} and expands it to file (list) and passes it to bash -c, it doesn’t know or care what are the special characters for shell. So event if the file name has any special characters find passes it as is to bash -c
- the invoked bash get’s the arguments and works with them
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=2d3fe065-2ef6-40b4-8b6a-a6306e456871)
July 01, 2009 10:31 PM
Let’s compare two hackerspaces, noisebridge and cyberpipe, i’ve been active in cyberpipe for several years and have been at several events and talked with noisebridge members about their hackerspace.
First some history, cyberpipe has existed for like 8 years now, noisebridge has existed in it’s current space for not even a year, before that members used to meet at peoples houses. They both have similar goals, provide a shelter for hackers, allowing them to learn and have good old geek fashioned fun.
Let’s start the comparison with something cyberpipe really excels at, events. They have up to date exensive video archive of all events (made with OSS stack! well, ignoring proprietary design/firmware on camera
), the lecturers are given mikes, projector and proper-ish lightning. The events in noisebridge on the other hand feel much more ad-hoc and way less professional from organizational point of view.

Now let’s compare a field where noisebridge excels at, the community. The community in cyberpipe feels dead-ish, the events do bring in the activity, but soon after they are gone the activity vanishes as well. Members are mostly not self-initiative and rarely i can meet some random people to whom i can talk about python lambda (or something like that). Noisebridge on the other hand has a very vibrant community around it, people are teaching German, French, Haskell, machine learning, Python and doing whole bunch of hardware hacking (i some kind of cooking classes were supposed to happen). Also their members as opposed to cyberpipe’s are producing a lot of fun toys, like the thing which you put around leg and it vibrates on north or reverse engineered led panel which was hacked to display game of life.
To continue the community comparison, let’s have a closer look at the community itself, cyberpipes members are mostly students, while among the noisebridge members you’ll find quite a lot of high profile folks (google/microsoft employees, OSS core developers, folks running own startups), which is probably the reason for my biggest surprise, noisebridge founds itself from membership dues! That is a level of commitment which i’ve very rarely seen at cyberpipe (tho, as gandalfar points out no one has really asked cyberpipe members to pay money).
Another major difference is the organization, cyberpipe has BDFL (well, without the FL part), which means you have a central point of authority who can decide on whatever, noisebridge on the other hand has democracy (and i mean it!), every paying member has veto so can block a decision. Let’s have a look at how new members get in, first they sign some form with basic info, than 4 weeks have to pass, and at the regular weekly meeting (if the person in question is present) they are sent to get beer or something, than both positive and negative feedback about soon-to-be member is solicited from people present at the meeting and if no member uses a blocking vote the new member is accepted.
This kind of organization gives you a great feeling of freedom, their only rule is “be excellent to each other”. My thoughts on this kind of organization initially were there is no way in hell this can survive the burden of abuses or members conflicting. A lot of people involved like it very much this way (and it certainly appeals to my inner anarchist), so i hope i’m wrong
July 01, 2009 06:30 AM
June 30, 2009
These days I usually buy my groceries at a Slovenian supermarket chain Mercator - they opened a new store recently just across Zemanta's offices. Since it's a new building it boasts a row of automatic check-out machines.
It must have been gut feeling, but I've never went near those things until a couple of weeks ago, when store employees started insisting that you try to use them.
Well, I'm not an expert in the field of usability, but I did my share of interface designs and I think that system can go down as a wonderful example of how not to make a human-machine interface. Especially not one that is intended for such a broad use.
It's downright confusing: you have no less than 6 ways of interaction, each one on a visually very distinct piece of the machine:
- The bar code scanner,
- touch-sensitive LCD,
- coin and banknote slot,
- returned change slot,
- card reader with its own keypad and
- scale for verifying the weight of the merchandise
You have to use all of these in correct order - even if you pay with cash, you have to use the smart card reader to insert their customer loyalty card.
I don't know about the average shopper, but my brain is only able to process one input channel at a time. When a machine is trying to tell me something in voice, plus displaying something different on the screen (plus there's an employee near-by, helpfully telling you his own instructions), I get annoyed in the best case.
Then there's paperwork. You get 6 different pieces of paper back (printed by two distinct printers). Some of which you are supposed to throw back into the machine! Don't ask me which ones - I just stuffed in pieces that didn't look like the master receipt. Or do they expect me to completely read those two meters of paper on the spot while a queue is building behind me?
And finally, the straw that broke the camel's back and the reason I'll never use the machine again: they force you to get a new plastic bag for each visit. No, you can't bring your own. I tried, successfully triggered an alarm and got told that that is a feature, not a bug (why, everyone likes a free plastic bag!).
Great. At the time where everyone is talking about sustainable economy and how to change the throw-away society, they introduce a service that gives out plastic bags in the thousands which will be thrown away the moment the happy shoppers get home.
I can understand a plan to take over the world by replacing people with cold, heartless machines, but this is ridiculous!
June 30, 2009 05:36 PM
June 29, 2009
First of all, why is this post in English? First reason would be, that Enlish language is widely understood (in comparison to Slovene)… the not-so-obvious reason is, that some people keep bugging me about my Slovene and a thing called “dvojina”. Dvojina is a really nasty part Slovene vocabulary (probably because there are only (iirc) 2 languages that use it). For example, I usually say “dve ure” [two hours], and those people immediately correct me, and say “dve uri” [two hours]… Tomato, tomato… They should probably create a Toporišič fan club
So, because the intro was relatively long, I am going to make the rest of the post shorter (i’m lazy, so what).
A couple of weeks ago Brodul and I decided to trash/wreck/destroy an old non-working laser printer, and harvested some interesting parts. Most of the motors, and the laster module are still in Kiberpipa, but I decided to keep 1 capacitor and 4 resistors.
Why the capacitor?

As you can see in the picture, it is a 330uF capacitor, built for 400 volts. Anyone who ever tried charging a high-voltage capacitor in a wall outlet (for example through a bridge rectifier) and throwing it towards someone else to catch, knows how funny that is
And why the resistors? Aren’t they dirt cheap?

These are 2.6ohm 20W resistors (4 of them), they were used in the printers power supply, and when fully loaded released 80 watts of heat. That’s more power then your whole laptop uses… and all of it went to (probably unwanted) heat.
I can’t wait for the next ‘breaking and smashing day’ in kiberpipa
June 29, 2009 11:47 PM
First a short intro to avahi, basically it is a ZeroConf implementation for linux, to make a long story short through use of multicast it is able to discover services as they appear (as well as scan network for those services).
This is a tale of a hacker deciding to take a pydra ticket. After verifying that avahi has python bindings i headed to their home page looking for docs. There is a “ProgrammingDocs” which looked like a good sign, imagine my horror when i read on that page
Though no real documentation about the DBUS API is available, you may browse the DBUS introspection data online
OK, so they pretty much don’t have docs, it can’t be that bad to work with it, right? Their API is to f**** complicated
, this is supposed to be the simplest of the “client” examples, this is the simplest of the “publisher” examples, fortunately the publisher wrapper is very nice to work with, but the fact that it exists hints that there is something wrong with the API.
As far as the protocol goes, first thing that struck me is that you can’t really distinguish between server and client, both take an active role. “publisher” advertisizes it’s service, while the “client” (or however you wanna call it) initiates the glib event loop and waits for asynchronous callback to happen. If we ignore the fact that you are forced to use certain event loop having continuous discovery is not a bad thing, it provies you a way to do discovery even if certain involved parties are temporary down, as well as the ability to see them as they join the network. What i’m saying is that forcing people to use event loop is a bad thing (as it is big overkill in simple cases).
If we get to my code, i choose to make the master the one discovering nodes, the reason for this is that this way i don’t have to make the node tell the master “hey i’m alive use me” (and of course implement the appropriate extension to the protocol). So basically a master is looking for nodes, when a node is put on network it advertisizes itself and master finds it and add’s it to it’s Node list.
June 29, 2009 10:40 PM
A slightly modified post i wrote long time ago (when i was trying to add a feature to the code bellow)
i will not abuse bash
i will not abuse bash
i will not abuse bash
i will not abuse bash
i will not abuse bash
i will not abuse bash
i will not abuse bash
i will not abuse bash
i will not abuse bash
Why not? Find out by yourself trying to add a feature to one of my scripts
shopt -s extglob
shopt -s nullglob
for i in */; do
[[ -f $i/photos.dat ]] && {
IFS=$'\a' read title desc < <( tr -d '\r' < $i/album.dat | sed ':b;$!N; $!bb; $s/\n/\\\\\\\\n/g' | ssed -nR 's/.*?s:5:"title".*?"(.*?)".*?s:11:"description".*?"(.*?)";.*/\1'$'\a'\\2/p)
title=${title//\'/\\\\\\\'}
albums=`sed -rn 's/s:11:"isAlbumName";s:8:"([^"]*)"/\n\t\1\n/gp' "$i"/photos.dat | sed '/\t/!d'`
printf "try:\n gallery = Gallery.objects.get(title='$title')\nexcept Gallery.DoesNotExist:\n gallery = Gallery.objects.create(title='$title', title_slug=slugify('$title'), description='$desc')\n"
for album in $albums; do
IFS=$'\a' read subtitle subdesc < <( tr -d '\r' < $album/album.dat | sed ':b;$!N; $!bb; $s/\n/\\\\n/g' | ssed -nR 's/.*?s:5:"title".*?"(.*?)".*?s:11:"description".*?"(.*?)";.*/\1'$'\a'\\2/p)
subdesc=`echo -n "$subdesc" | sed ':b; $!N; $!bb; $s/\\n/\\\\\\\\n/g'`
subtitle=${subtitle//\'/\\\\\\\'}
printf "try:\n child = Gallery.objects.get(title='$subtitle')\n child.parent = gallery\n child.save()\nexcept Gallery.DoesNotExist:\n child = Gallery.objects.create(title='$subtitle', title_slug=slugify('$subtitle'), parent=gallery, description='%s')\n" "$subdesc"
done
for j in $i/!(*.thumb|*.sized|*.highlight).@(jpg|jpeg|png|gif); do
filename=$j
dirless=${j##*/}
title=${dirless%.*}
c=`tr -d '\n' < "$i"/photos.dat | ssed -nR 's/.*?"'"$title"'".*?caption";s:[0-9]+:"(.*?)".*/\1\n/p'`
caption="${c//\'/\\\'}"
if [[ $caption != $title && $caption ]]; then cap=", caption='$caption'"; fi
printf "p=Photo.objects.create(image='$filename', title=title_wraper('$title', '${i%/}'), title_slug=photo_slug_wraper('$title', '$i')$cap)\np.save()\ngallery.photos.add(p)\n"
done
};
done
This was my attempt to write a migration script from gallery v1 to photologue. Attempt failed, and i learned not to abuse bash for any serious code generation. I hope.
The history of this script went something like:
- hrm, i’m supposed to parse serialized php, i bet i can do it with sed, how hard can it be?
- a “perfect” solution (probably certain line in that code now) was born
- hrm, i have new problem, another “perfect” solution was made
- possibly repeat the above step few more times
- hrm, this doesn’t work, let’s add some ugly solutions/gluing, just for test
- possibly repeat the above step few more times
- it WORKS!!, sleep time
Don’t get me wrong, shell is a great tool, just remember to keep it in your pants cowboy
. It allows you to do simple tasks with a speed (and character count
) python can’t possibly rival, but if you do too complex problems with bash you can easily slip in the land of unmaintainable.
As for the python, i agree pretty much with Tomaz, python is boring, you miss (almost) all the fun of look for a “perfect” one liner, the trade off for this is that the code is syntactically maintainable and not having to look up the syntax often.
Fast forward to recent times and you see that i use shell just to generate simple python array (well, probably soon to be two arrays), but that is harmless and can’t possibly turn into an un-maintainable monster, right?
June 29, 2009 04:46 AM
June 28, 2009
Here's another piece of electronics I saved from being dumped in a landfill: it's a wireless temperature and humidity sensor from one of those home weather stations. My sister gave it to me after I expressed my interest in it, but unfortunately I was too late to save the broken base station with the receiver. Now I'm playing with the idea of building a new receiver from scratch.
On the outside the sensor has a couple of buttons for setting up its connection with the receiver, self-test and choosing temperature display in Celsius or Fahrenheit (Kelvin fans are left out in the cold). There's a small LCD display on the unit that shows the current sensor readings.
Top side
Bottom side
There are no markings of any kind that would identify the manufacturer. That could be intentional, guessing from the sloppy way it's soldered together. Looks like the cost of assembling one of these things together was the primary concern of the designers: there's a single IC in the middle that uses direct chip attachment. Everything is SMD except for a couple of through-hole components that appear to be soldered by hand - in fact, whoever did it forgot to solder one of the pins of the trimmer capacitor (so I'm wondering if the base station was actually working just fine). Battery, buttons and LCD display all connect to the PCB by just being pressed against it - connectors really must cost a fortune these days.
Here's a schematic of the RF part. It appears to be a classical case of a cheap transmitter in the 433 MHz band. Basically it's a tuned oscillator: you have an amplifier and two tuned resonant circuits on both sides. One is a R433A SAW resonator and the other is a LC circuit that can be tuned with the trimmer. Because of the resonance the feedback can be minimal. In this case just the parasitic capacitance in the transistor's base-collector junction (Cbc) appears to do the trick. The antenna is just a fancy trace on the circuit board. I'm guessing there's only a simple amplitude modulation going on: either the transmitter is on, or it's off. But I have yet to hook up an oscilloscope to the circuit the verify that.
I'm planning to build a simple super-regenerative receiver, reverse engineer the data protocol and hook it up to an Arduino or some similar microcontroller. I know I could probably get a receiver module already built, but I want to get my hands dirty and finally try working with some RF circuit designs.
What I found so far on the internet seems encouraging. There's a really nice document about super-regenerative receivers by Eddie Insam and the protocol for weather stations has been broken before.
June 28, 2009 07:16 PM
I visited Exploratorium with the idea that this is yet another science museum with a bit more hands on approach. I was very positively surprised to discovered that it’s far from that. Instead of being classical museum it’s a giant ‘playground’ where each exhibit offers you an interactive experience around some concept, mostly from physics.
Exhibits are designed to be interacted by and you soon find yourself touching everything around you and just trying to learn by feeling and doing things. There were lots of super-excited kids running around which further hyped up the whole experience.
Two interesting things to note about the whole experience:
- Some exhibits were video taped in order to be able to optimize the exhibits. I find this very refereshing as it shows that the staff here really cares about the experience and that they’re willing to go that extra mile to make it really enjoyable for the visitors. They also nicely solved the problem of privacy as they’ve clearly marked the times when the exhibit will be under video survailance so you could come later.
- They build the exhibits themselves. Their workshop is part of the scenery and while they don’t actively work on the weekend, I imagine it has to be very interesting if you’re there during the week.
Example view:
There are also a few elements that are a nice touch, like this piano with an X underneath:

Image by Gandalfar via Flickr

Overall, a very fun thing to do in San Francisco and you should check it out next time you’re around.
June 28, 2009 07:40 AM
June 27, 2009
I’m not sure how big deal is death of Michael Jacson back in Slovenia, but here in the states it seems quite a big thing, with all the news talking about it all the time while internet keeps generating more content and links to YouTube videos that have something to do with Michael Jackson.
As I’ve written before, Friday Night Skate has a big music element and today most of the songs were from Michael Jackson, mostly older recordings. There is also traditional Thriller dance at the Union Square, San Francisco which attracted quite a crowd and made everyone really hyped up and dancing!
I tried recording a video of it, but you unfortunely can’t see much. I’ll try to figure out something better for next week:
In short, lots of hype around MJ’s death and an interesting way how a group of people reacted to it. A bit bigger crowd this time – 40+ skaters.
June 27, 2009 09:28 AM
Lets begin with a link, this is really REALLY REALLY good resource for learning bash (especially the BashFAQ).
Imagine this, you wrote a script for some thing, now that is ready for production you put it in the crontab and let it run from there, BUT in certain conditions that script fails. Assuming the error ain’t trivial the way i tackle the problem is to add something ala this to the top of the script.
exec 2> log.`date +%Y.%m.%d.%H:%M`
set -x
The first statement redirects stderr to a certain file, the second statement enables “xtrace” printing commands as they are executed. The undesired side effect of this is that ALL stderr is redirected to that particular file. The alternative to this would be to do proper logging, but if your script is long enaugh that you need proper logging there are pretty good chances that you shouldn’t be doing it in the bash in the first place
.
Ever found yourself wanting to do some simple processing of some command and wanting to use the result?
echo some string | while read; do foo='boo'; done; echo $foo
This echoes nothing as $foo is empty. What happens in the background is that pipes spawn the subshell, so the variable $foo is assigned in the subshell, and when the loop terminates subshell is closed and normal shell is execution is continued, which doesn’t know anything about $foo.
A solution for this is called “process substitution”, to the best of my knowledge it is exactly the same as pipe, only without the subshell part. As a side not, ksh doesn’t spawn subshells with pipes.
while read; do foo='boo'; done < <(echo some string); echo $foo
Let’s talk about dotfiles, specifically about those initializing the shell, in bash that would usually be .bash_profile and .bashrc, what they can be used for is to customize you bash on every startup. The difference is that .bash_profile is executed when a login shell is started (for exmple when you ssh to a box or do “su -”), while the .bashrc is executed when nonlogin shell starts (usually when you start mrxvt/xterm/konsole/…). Why the f**** do we have distinction between the two modes? No good reason really, it’s because we were doing it this way for 20+ years, why break the tradition? :/
[[ $PS1 ]] && exec bash -l
Having the above in .bashrc is the way around this annoyance, it allows you to have all your configuration in .bash_profile. The only thing it does is execute a login shell (thus triggering .bash_profile execution). The condition makes sure that the login shell is executed only when you are in interactive mode (bash by definition/man page set’s PS1 only for interactive shells). A non-interactive shell is spawned when you use scp.
June 27, 2009 03:28 AM
December 11, 2007
Finally something new! :)
This one was shot a week ago at the concert of Jan's (on the picture) band The Muffin Man.
.
Leave a comment
June 27, 2009 01:27 AM
August 31, 2007

I had some fun with my old Helios 58mm f/2 and my new model (no specifications on the casing :) the other day. And this is the 100% crop of the result... color-passthrough and desaturation were the only operations done on this one. I was blown away by how much sharpness and how vivid colors can this lens produce.
Leave a comment
June 27, 2009 01:27 AM
August 11, 2007

I haven't had any time to go shooting past few weeks so I've dug up some stuff from the archive. This one is from my trip to London. Street photography does have its charms.
Leave a comment
June 27, 2009 01:27 AM
August 9, 2007
Ricewind got down on one knee, the better to arrange the picture, and pressed the enchanted lever.
The box said, "It's no good. I've run out of pink."
A hitherto unnoticed door opened in front of his eyes. A small, green and hideously warty humanoid figure leaned out, pointed at a colour-encrusted palette in one clawed hand, and screamed at him.
"No pink! See?" screeched the homunculus. "No good you going on pressing the lever when there's no pink, is there? If you wanted pink you shouldn't of took all those pictures of young ladies, should you? It's monochrome from now on, friend. Alright?"
"Alright. Yeah, sure," said Ricewind. In one dim corner of the little box he thought he could see an easel, and a tiny unmade bed. He hoped he couldn't.
"So long as that's understood," said the imp, and shut the door. Ricewind thought he could hear the muffled sound of grumbling and the scrape of a stool being dragged across the floor.
-- an excerpt from Terry Pratchett's Colour of Magic, the first Discworld novel.
Leave a comment
June 27, 2009 01:27 AM
July 31, 2007

This shot was taken on my sister's birthday party two weeks ago. It's a part of 2-meters-long chocolate cake/roll. It was delicious! :) Once again, our aunt Mojca came through and overdid herself! Thanks again! :)
Leave a comment
June 27, 2009 01:27 AM
July 25, 2007
Actually, it is not fish, it's a squid but you catch my drift. :)
This shot was taken on my sister's birthday party this Sunday. These guys were just laying there, simmering, and the light was just right. I had to get real close for this shot, actually. I think the lens was just a few centimeters from the boiling hot plate.
Leave a comment
June 27, 2009 01:27 AM
July 24, 2007
Just my luck! :( I was about to clean my glasses yesterday when this happened. :/ The plastic-rope-thingy is all that's holding them together now. I can wear them but are far from being comfortable.
The irony of the whole event is that I was looking of buying new glasses for a while now and I have an eye exam scheduled on Wednesday. I've picked out a frame too but I don't know if it's "the one." I guess I'll see on Wednesday... or not. :)
PS: This shot was taken without me wearing the glasses (obviously) so I must thank Canon for the excellent autofocus in my 20D.
Leave a comment
June 27, 2009 01:27 AM
July 10, 2007
Another army shot, this time from Cyberpipe & Zavod k6/4 picknik last weekend.
This time we were shooting each other in a game of Airsoft, which is more "realistic" version of paintball - without paint. The guns are replicas of real weapons (yes, snipers too :), the bullets are smaller than paintball ones and the whole game is supposed to be as realistic as possible. Even with great chaos with communication in the woods the game was fun and I look forward to the next match. This is something every gamer should experience. Sure, you don't have HUD display and can't jump over a building with translocator, but feeling of being shot in the forehead and the confusion of players' names not being displayed over their heads is priceless. ;)
Leave a comment
June 27, 2009 01:27 AM
December 13, 2007
This one was shot a few weeks ago at EuroPrix Top Talent Award 2007 event in Graz, Austria.
It shows the host and "father" of the event and competition Prof. Peter A. Bruck right in the moment of projector's source changing and showing the well-known "blueness".
Leave a comment
June 27, 2009 01:27 AM
July 3, 2007

A little GIMPed shot from the paintball set (again).
Leave a comment
June 27, 2009 01:27 AM
June 26, 2009
 |
Metaclasses are deeper magic than 99% of users should ever worry about. If you
wonder whether you need them, you don’t.”
—Tim Peters |
This quote illustrates the perceived complexity of metaclasses in python, they really aren’t tho, this post attempts to explain them in simple terms understandable to anyone familiar with OOP (familiarity with django won’t hurt).
Basically they are just classes whose instances are classes and their main purpose (same as every other classes) is to customize their instances.
class MyMeta(type):
def __new__(cls, name, bases, attrs):
print 'in MyMeta.__new__'
return type.__new__(cls, name, bases, attrs)
class Boo(object):
__metaclass__ = MyMeta
print 'end'
This is the most basic and completely useless example of metaclasses, the interesting things here:
- metaclasses are supposed to inherit from the default (for new style classes) metaclass, “type”
- class attribute __metaclass__ tells python what metaclass current class should use (doh)
- metaclass is executed as soon as the class is defined, that means that it can permanently change your class (thus any object using it uses the changed one)
But since all so far was just theory let’s have a look at the real world examples, i explored metaclasses through django, so the examples are from there
class ModelFormMetaclass(type):
def __new__(cls, name, bases, attrs):
...
class ModelForm(BaseModelForm):
__metaclass__ = ModelFormMetaclass
First a short explanation of ModelForm, basically you pass it a django Model (object abstracting SQL table) and it generates the html form for it. You use it by subclassing ModelForm passing it your Model class as one of the inputs. (yes this is inaccurate explanation, let’s keep it simple for the sake of explanation)
Let’s start with a reminder, since __metaclass__ is just a class attribute, so when you use ModelForm (subclassing it) your class inherits this metaclass, what they do there is parse the Model you provided and generate the form fields in your class, this way (as opposed to manually writing fields) you:
- have cleaner/less code
- are more future proof (when/if the Model changes you don’t have to change your form)
def modelform_factory(....):
....
return ModelFormMetaclass(class_name, (form,), form_class_attrs)
This is from the same file as above code snippet, and ilustrates another way to use the metaclasses to generate classes, the use case for this is that based on the model you can get arbitrary numbers of forms for it, to be able to do so you have to generate the ModelForm on the fly (since you don’t know what Model you are gonna get)
Another possible use case for the ability to generate the classes on the fly is to create a template tag to which you pass model you want and it spits out the form for it, as a side note, this requieres light python abuse (globals() and
inner classes).
Ok, now we know what metaclasses are, how to use them and are familiar with it’s real world examples, but what are the alternatives? Well, two actually __new__ and class decorators.
You can use __new__ to kinda customize the class before it’s created, the options are limited, but first of two real world examples is still possible, that probably says: i refuse to acknowledge metalcasses can do anything and i’d rather abuse something i’m familiar with. A real downside of this is that the code in __new__ is executed once per object creation, let’s say you create 10 objects (implementing some feature in metaclass as opposed to your classes __new__, skipping the use of metaclass), code for that feature is executed 10 times in __new__ as opposed to 1 time when done in metaclass. Here is the code on what am i talking about:
class M(type):
def __new__(*args, **kw):
print 'M.__new__'
return type.__new__(*args, **kw)
class A(object):
__metaclass__ = M
class B(object):
def __new__(*args, **kw):
print 'B.__new__'
return object.__new__(*args, **kw)
for i in xrange(10):
A()
B()
The other alternative are class decorators, the major problem with this is that they are only available from 2.6 up, the other problem with them (same as __new__), they don’t allow you to blatantly abuse python like metaclasses do (say, mess up MRO), on the up side i can’t really think of a real world use case where you would need more power than class decorators offer
So, to conclude use metaclasses when you want to do one time transformation of classes and listen to Tim, if you don’t know why use metaclasses, than don’t.
June 26, 2009 06:52 PM
Ok, the other day i was playing with disqus API, i think the API is very uncustomizable, here is why, what may have lead to that decisions and suggestions for improvements.
A friend of mine suggested that i should do something fancy with it’s data (like visualize the most used words, or even better build a social graph using info about who’s talking to who), the problem here is that you can’t access the data (except yours). While i do understand that it takes some thinking on how to do data access, it IMHO should be done, as you are closing the door for a lot of 3rd party funky stuff. It is worth noting that this is documented unfeature:
Accessing your own data is our first priority in developing the API. We want to provide this kind of access in a way that does not infringe on the rights of the forum owner. This is still in progress
So my next idea was to build 0 delay syncer between local comments and disqus. Well, that didn’t go too well either. The problem here is that you are handled a black box (the comment text box is the iframe), so you can’t attach any javascript events/handlers to it, this is a security feature preventing you from impresonating the user.
One way around this would be something complicated such as OAuth (but that requieres users to allow posting as them from certain sites, and requieres qute a bit of work on developer side), the other way around it would be a simple callback, so disqus would POST to certain url (provided by developer) when a comment is made, providing the 0 delay functonality.
Another thing to be considered is what happens when/if the disqus servers are unavailable, with OAuth you have the option to sync the comments afterwards (having up to date local copy and ability to post comments during downtime), with callback way, well, if disqus is down you can’t have comment submited
.
My final idea was to create a fancy interface for comment moderation (with stuff ala bulk moderation), well, that can’t be done either. Not giving me full write access to comments on my forum is just bad (so you can’t delete comments or flag them as spam). (actually, it may make sense that i can’t delete the comment, but i should be able to “disassociate” it from my forum)
On a related note, i checked out the disqus wordpress plugin, the way they get around the syncing issues is that on every (post) page load they query their API, make a SQL query to comments comparing the two and locally INSERT-ing if necessary. Also another good idea would be to put the CSS locally on the blog using WP, as this way the comments will remain readable even with disqus down.
June 26, 2009 08:12 AM
Here are some of my notes from the Social Media Club panel discussion that happened tonight:
What is influence?
- Influence is a capacity to have some people do something. Actionable influence – influence as a strategy, as a process. You don’t master the outcome but you have a feeling what’s happening and where it’s going to end.
- Influence – facilitating conversations between and with customers. You have to be within the context of the conversation.
- Brands are today presented in many different worlds and the question is, how to manage all the influence there.
- Influence – the art of successfully levering what you can’t control.
- You are more influenced by the person that looks like you. What are the ethical and legal ratifications of using such technology?
How do you measure influence? Is the technology really the solution for this problem?
Technique 1: Mapping out all the people that are interesting to us, and then we converse with them (Twitter/Blog/etc.). Then we measure how often they talk about us, and what % of that is positive. After you identify a few thousand people like that, then we measure how many of them we can reach (phone, mail, etc.). Then we measure the reach of their blog and how many people connect through that.
Technique 2 (@Get Satisfaction): Asses the customer satisfaction level: where they are contextually in the conversation (are they angry?) and where they are going.
The role of crowd-sourcing and how does it impact the influence and how does that connect to “Web 2.0”?
- Twitter is not very influential, because it’s just another broadcast channel. Until we have threaded @replies, we don’t really have conversations.
Get Satisfaction is a “Social CRM”: There’s a lot of value in deanonymizing your personal data.
- If you enable your customers to talk to each other, they’ll get value in that and you’ll get value from eavesdropping. But to get real value out of that, you have to engage in conversation with them.
- Twitter is a lot of time used as a broadcast tool, but there are true customers on there and you can reach out to them (not spam them) and engage in deep conversations with them. Too much focus on the tool is dangerous path to go down so you get too focused on the technology.
- 140 characters – going back to basics, the value of headlines. They’re teaching us to write short and teach us how to be concise.
Does Brand matter anymore?
- The brand matters, but it’s changed. Brand has to work in so many more contexts. You have to understand how does the identity form itself, how does the brand act in a funny situation, how does it work in a serious one? You have to allow and understand how it works in these contexts in order for brand to be part of the conversation.
- We can count on the large portion in B2B that want to be part of conversation that are not ready for that.
- Conversation is still the same, it just moves faster from one medium to another.
- Creative marketing can’t cover bad brands and products anymore.
How can companies become more comfortable in the social media space?
- The conversations are happening whether you’re participating in them or not. You can be afraid of them and hide from the information that’s out there, or be part of it.
What are the things that can be controlled?
- What does the technology really change? Technology changes the circumstances in which the crisis happens. It changes who the influencers and important people are. But it also gives you more tools to refine and change your message.
- The tech that allows you to target your message to a right group of people. If you talk to people about their experiences about social media:
- Ads for women are very different. It’s increasingly the case that women get very different messages then men.
- Search engine bias – there’s a big fight right now about the algorithm for search. They’re really important things from the influence point of view.
- Personalization is a bad influence in Facebook.
What’s surprising about influencing patterns today?

- Image by Ekler via Flickr
- The media and analysts doesn’t matter that much anymore. The buying influence is coming from the peers. When it comes to lead conversation and getting involved with them – it’s not for sales team but for the whole team. If you’re not willing to expand your role and engage in the peer to peer conversation, you’re not giving your full potential to your company or a client.
- The user interface matters. Like the recent Facebook redesign that made the user status much more prominent. You can do a lot with cue’s and prompts.
How do you develop your own influence (as an individual?) – personal brand
- Let people see who you are and what are your interests and just go with it.
- There’s something in seeing vulnerabilities in people and companies that makes you trust them a bit more.
June 26, 2009 08:01 AM
It’s easy to see San Francisco and Bay Area as the Western hub of hi-tech technology. The theory goes that one should be able to fully navigate and organize their day with a smartphone and a bit of change for the transportation. Which works pretty well for the most part.
You tell the phone to use GPS to figure out where in the space it is, you tell it where you want to go and decide on transportation mechanism: Driving, Public Transport and Walking. Google Maps then sends all this personal data to the big machine in the sky and gives you back directions. Pretty nifty as it knows most of the public transportation options.
That is also a catch for unwary traveller new to the area. It turns out that while there are plenty of transportation options during the day, the bay area public transport is tricky at night. It seems that Google Maps only knows night transportation within the San Francisco and gives up if you’re somewhere else, in Oakland for example. While 4 hours of walking are always an option, it’s not something you want to do at 1 AM. With a bit of luck you catch a cab and a bit of cash later, you’re home.
There’s a bigger lesson here. Blindly trusting the technology in corner cases such as late night trains, buses etc. is not very smart. Always check everything online three times to ensure that if you leave the party late, you’ll know how to return home and have a Taxi phone number with you, just in case ?
June 26, 2009 01:04 AM
June 25, 2009
Due to my laptop being dead I am not behind my regular desktop and thus not seeing the statistics what I have listened to the most in the past weeks. So I will take this oportunity to reflect on what I dislike on Jamendo. There is not much, and its mostly just annoyances, but it is only fair to say it out loud and hope things improve.
For starters, I dislike the Flash player. There less volatile and more open technologies out there — e.g. The Yahoo! Media Player that is also being used by http://blocsonic.com">http://blocsonic.com">BlocSonic seems to be written in JavaScript/EcmaScript and feels nicer to me. I am even thinking of implementing it on my page.
The OGG/Vorbis torrents are sometimes seedless, which makes it sometimes a bit of a drag to wait days or even weeks for an album to finally download.
Already after my first TGJE report mareviq suggested to me Rob Costlow — a great pianist who offers his music under a CC license. Sadly though, his music can be heard on Jamendo, but not downloaded. After I contacted Jamendo with that problem, they responded that Rob Costlow is an exception. As someone who does have some idea of IP law, I find this really odd. Considering Rob Costlow has published his works under a CC BY-NC-SA license at least on Magnatune, it should not have been any problem with anyone who got the music legally to share it with others.
But even graver then the above case is HYPE — a french band whose music is not available on Jamendo anymore at all. From what I could gather from e-mailing Jamendo, is that HYPE got a record deal and the label gave the band an ultimatum to get all their free music offline. If anything, this looks like a school example of a copyright violation. Sure, an artist has a right to revoke his work under certain conditions, but a better commercial exploitation is hardly one of them. Again, since they (most probably) had their work on Jamendo under a CC license, it is a violation from their part to take back the rights that they already gave away to the public.
This brings me to free singles of non-free albums — lately I have found a lot of singles on Jamendo and when looking at the artists' sites I usually found out they have full albums released as CD's and nowhere any notice of any CC. Quite a lot of these I found were promoted by Open Music Wire. After looking at the Open Music Wire website it seems to me that in some cases both Open Music Wire's and in turn also Jamendo's services are being misused for promoting non-free labels and artists, by CC'ing just one track. This gives me very mixed feelings. On the one hand it does promote some lesser known artists. But on the other hand, it (ab)uses free services to tease people into buying non-free content. Moreover since CC is not mentioned anywhere on the artists' homepages, I wonder what would happen if, e.g. a user would get sued for copyright infringement of a track that is under a strict copyright on the CD, yet freely available under a CC license on Jamendo or Open Music Wire.
In other news: Since I started this experiment I have listened almost exclusively music from Jamendo. This will probably change a bit in the future, not because there is much wrong with Jamendo, but just because after proving that one can survive for a month of listening only to music served by Jamendo, I will go on with a normal life and expand TGJE over other free netlables non-discriminatory. This way I will try to make a user case of a normal, internet-savvy music lover.
hook out >> listening to Jamendo Radio on my dad's laptop and slowly going to bed
<!--break-->
June 25, 2009 10:09 PM
What a better way to kill time on a sunny Sunday then to go visit a local Zoo. San Francisco Zoo is just around the corner, and since their penguin feeding has its own upcoming.com event, I even knew how to time it
The Zoo is not too big and I really enjoyed the time there. Lots of penguins at their little Penguin island.



You can see all the photos in the San Francisco Zoo Flickr Set.
One of the positive things that happened during my visit, was that @sfzoo found my Tweet that I’m going see penguins there and Tweeted me their feeding times. Very positive experience and the fact that someone was listening on Sunday afternoon:

June 25, 2009 07:33 AM
June 23, 2009
Yesterday I attended the opening of the astrophotography exhibition in Tivoli, Ljubljana (part of the events celebrating the international year of astronomy).
I don't know about you, but I still get goosebumps whenever I see a picture like this.
Image by NASA
Having grown up watching Star Trek and building LEGO moon base sets, these photographs remind me that at least some small part of the promises we were given in elementary school did come true. There's a permanent international outpost in the Earth's orbit!
Now imagine seeing something like this with your own eyes. And if our unfashionable corner of the galaxy has wonders like that to offer, what kind of unimaginable sights are there to see around other stars?
And then comes the realization that all progress in space flight has been achieved with what, one tenth of a percent of resources put world-wide into senseless wars and destruction?
There are a number of technologies that could bring at least the rest of the solar system within our grasp, if only some more effort could be put into it.
June 23, 2009 10:40 PM
Muzej bo skupaj s prostori Kiberpipe zaprt od srede, 24. 6. 2009 do predvidoma konec septembra tega leta, ko se začne nova sezona. Letošnjo sezono smo otvorili z razstavo zbirke, ki nam jo je podaril Inštitut za biomedicinsko informatiko Medicinske fakultete v Ljubljani. Vodja muzeja Dunja Rosina sem z Martinom Hribarjem (ter ostalimi sodelavci) pripravila pet samostojnih začasnih razstav:
Ostali izpeljani projekti vključujejo sodelovanje na festivalu Generator, prevzem Monitorjevega muzeja, sodelovanje v okviru 18. dneva muzejev, organizacija predavanja MyCPU, sodelovanje na festivalu HAIP, predstavitev na študentski areni, …
V poletnih dneh pa lahko pričakujete prenovo spletnih strani!
June 23, 2009 07:57 AM
June 22, 2009
It’s been six months since I wrote my gloomy outlook and unlike most things I wrote, my thoughts keep coming back to it and issues I talked about. My view hasn’t changed. 2009 is indeed shaping to be a great year for me and an awful one for world in general.
If a problem like over-fishing, that is both well-understood and has known and relatively cheap solutions, seems to be beyond our willingness to solve, what chance do we have then to find and implement solutions for problems that require enormously more effort and resources?
Game over indeed.
I don’t see our civilization surviving this century even if no giant rock crosses our path. There are many reasons for this, but none original or interesting enough to dwell upon. At the same time I do think this is not the last century in which humans live.
If we are all indeed descendants of a tribe that at some point numbered only 2000 individuals, as I’ve heard in a lecture once, then it doesn’t take much to imagine that out of billions enough people will survive to continue our species existence. Not even me imagines a world completely void of water, plants or small furry animals.
Alas civilization needs more than mere presence of humans. Inspired by Irish post-Roman example a question occured to me recently: “Which 100 books would you try to preserve if you wanted to preserve our civilization?”
Point being that if things go the way of Dodo and people have to fight for survival, it wouldn’t be reasonable to expect enlightened person or small groups to preserve many more books than that. And books are still the best way to preserve knowledge in long term. Other forms are either too transient or can pack information far less densely.
I quickly realized two things. First, that I have no clue which books I would pick. And second, that there are more fundamental questions.
Can a civilization fluidly metamorphose from failing to a new, thriving and likely different civilization or does the new one need to start anew from ashes of previous ones?
Question matters, because I imagine that civilizations are in a way like companies. Establishing one is quite different than keeping one going and hence knowledge needed is probably different too. Most historical examples I know of persuaded me that scale of a problem and length of time before its full consequences are felt are inversely proportional to likelihood of our dealing with it before it is too late. However I am not a historian and could well be wrong. Still, you do with what you have and this seems reasonable enough assumption for further inspection.
Assuming this, what does it take to establish a civilization?
One thing that comes to mind is a high enough density of people who don’t spend all of their time procuring food. This means they can’t be hunter gatherers and some agricultural knowledge needs to survive to successfully plant and grow existing crops or tame new ones.
It would also be helpful if all technological knowledge isn’t lost either. Electrical gadgets will be hopelessly obsolete, but creating and fixing a good plow or knowing how to preserve perishable goods for longer periods of time will not be something to sneeze at. World might be full of decrepit remains that might be reused, but there is no good reason to leave it just to human ingenuity to discover how and to what purpose.
Another way to increase number of people living is to stop them dying needlessly. Hence preservation of most effective ways to stay healthy and low tech remedies for most common diseases and injuries would be helpful too. Most drugs will be gone for centuries, but it’s remarkable how much can be achieved with what will hopefully still be found in nature.
Mathematics is also an underpreciated, yet necessary underpinning of every developed civilization. Calculus will not be needed from the get-go, but just counting doesn’t get you far either. There’s hardly a plan that couldn’t be improved with a sensible application of mathematics. Related to this, basic economics should be preserved too.
“There is no such thing as society,” said Margaret Thatchet, which of course is rubish and why it is not enough to learn how to live in complex social structures, but also why and in what ways. Therefore sociological and philosophical texts should also make cut. I find it difficult to imagine titles, because I don’t think culture is something you can implant. It is nurtured and developed not only by circumstances and challenges society faces, but also with choices it makes. It is unlikely that next round would follow our footsteps but optimist in me would love to leave something that inspires and gives something to aspire to.
All these knowledge would be dead ink on paper if person holding a book doesn’t know how to read or what words actually mean. So alphabet learning book and a dictionary should also survive even though most of modern dictionary will probably be fairly useless by then and rest might be unhelpfully terse.
Last I would add a book about ecology trying to explain complexity of the world around us and why it would be wise to be careful how we try to change it. There is probably no better definition of stupidity then repeating same mistakes and expecting different results.
So what did I end up with?
An alphabet book, a dictionary and books about medicine, agriculture, mathematics, economy, sociology, philosophy, some basic technology and ecology. There are no titles since I don’t believe such books have been written yet. We have lived in a world full of books and knowledge for so long, that we simply never saw or had a reason to write a book premised on the idea, that it might be one of few books around.
In any case, even though I have spent more thoughts on this then is probably reasonable at this point, I am sure I haven’t thought of everything. What else have I missed?
June 22, 2009 07:32 PM
Here's a nice video shot from a camera aboard my father's model airplane:
(can't see embedded video?)
The airplane is EProjekt4, a fully aerobatic radio-controlled model airplane. It was designed and built from scratch by dad two years ago. The plane is propeller-driven and uses an 1.2 kW electronically commutated brushless DC electric motor. Power is provided by a 5-cell 4000 mAh lithium-ion polymer battery pack.
Video was recorded on a SD card using the tiny ACME FlyCamOne2 which was mounted under the airplane's fuselage (you can just see the propeller at the top of the frame).
The recording shows a panoramic view of a few villages around the model airfield on Planinsko polje, Slovenia, and a first-person view of a couple of aerobatic maneuvers.
June 22, 2009 11:36 AM
Dorkbot is a group that describes themselves as – People doing strange things with electricity. I was lucky enough to be able to go to their 7 year anniversary party that involved obscene amounts of electricity surrounded by geeks that actually knew what they were during so not to get anyone killed.
Event took place in blacksmith’s warehouse, that’s owned by the host – Jon Sarriugarte, who also ran the show. The first thing that you noticed when you arrived were mutated cars:

Image by k0re via Flickr


.. and of course lets not forget the ultimate geek mobile, engineering (debug?) version of Tesla Roadster electrical car:

The most interesting aspect of this car, at least to me, is that it’s totally quiet. They’ve moved it from one part of the yard to another and the only thing you could hear was the sound of the tires.
There was also the two 15-feet (4.5m) Tesla Coils, which I somehow managed to forget to take picture of in the day light. Here is one of them in action:

Image by k0re via Flickr
Inside the Kraftworks was even more fun, with food and drinks and the main scene:

Image by k0re via Flickr
Lectures of the night involved a talk about how to build your own electrical car and the pitfalls possible pitfalls, 1928 Hogan Tesla Coil, Mike Winter’s Interrogation by Robot and Omega Recoil – Wireless Transmission. Full announce.
I didn’t understand most of the first talk about electrical cars as they were talking a lot about torques, different voltages and power involved. It will probably make sense once I go out and try and build one of these.
1928 Hogan Tesla Coil is a machine seen on the picture above. The idea was to use electrical shocks to cure people with. Jon managed to find one and beautifully restore and made it work again. At the end of the night, they were also curing people with it on the stage. Jon’s blog post with more pictures and scary user manual.
And yes, it makes sparks:

Image by k0re via Flickr
Interrogation by Robot is an autonomous robot that can question the suspect and assess (with a bit of help of author) how big of a threat the person is. A fun project and another scary insight into how easy people will surrender their liberties to a robot that blinks and yells at them.

The last talk coupled with the giant sparks was about transferring energy across the space without using any wires. By using the Tesla Coil, the authors managed to light a small light bulb with wireless electricity over the 30 feet (~10 meters) distance:

The event was really fun with lots of other interesting tidbits and it’s clear that there is a passionate community here that invests a lot of effort into organizing these events.
Make sure to check out great Flickr photo set from k0re with more photos and even a few videos.
June 22, 2009 06:29 AM
June 21, 2009
I just noticed that Larry Lessig looks just like Linus van Pelt wearing glasses... Wow! O_o
hook out >> studying finance and drinking Kneipp coffee
<!--break-->
June 21, 2009 10:19 PM
Every now and then I like to tinker a bit more with KDE than just using it. So I set on a course of creating a simple plasma widget (also called plasmoid). I must admit, I’m not really a seasoned Qt (or KDE) developer.
So I figured — take a look at some of the examples and tutorials on KDE techbase and I’ll be running my very own proud plasmoid in no time, right? Err.. was I wrong or what.
I tried to create a simple plasmoid for my shiny KDE 4 desktop. Ok, copy paste the example from the KDE site and voila, a widget with “Hello world” text pops up. Next I looked up to microblog plasmoid, that provides a twitter/identi.ca microblogging widget. It’s a simple applet, but still has a fair amount of useful knowledge in it, eg. how to use dataengines, how to render plasmoid and how the code fits together in general. Data engines are API endpoints, that provide your plasmoid with data such as time in different timezones, twitter timelines for users, etc. They are designed to decouple presentation layer (your applet) from data layer (the data engines), which makes sense. They also provide a way to make use of technically superior methods than those used in SuperKaramba (you can also read that as “polling as little as possible”).
Well, it turns out that doing that from Python is currently not possible from KDE 4.2, at least not without reimplementing a great deal of already implemented code. But that was not my main issue. I was a bit irritated at the lack of documentation. Python bindings are sadly not regarded as important as other and are usually feature-wise behind the C++ and JavaScript. Also, there were quite a few missing spots in my knowledge about plasmoids. I was missing a bit more noobish introduction to plasmoids, that would explain what types of plasmoids there are, what one can do and what Plasma API expects from a plasmoid (eg. the API requirements). Many plasmoids are PopupApplets, but Python examples don’t mention those — clearly because they can’t even work yet in KDE 4.2, as I’ve just figured. Also, it took me way too much time to realize that, a newbie overview over the Plasma API would of solved that in no time.
All in all, KDE 4.2 is “already” quite usable, and KDE 4.3 will probably be a lot more, given the fact that Twitter microblog plasmoid shouldn’t leak memory anymore. Other than that — it’s a shame that KDE overhyped the KDE 4.0 release so that everyone was dissapointed afterwards. Also, I’m very sad to see the commit-digest.org having fairly little bug fixes compared to features. That’s also the pest that’s hurting KDE the most as far as I am concerned — releasing undertested code on their users.
June 21, 2009 08:59 PM