Search Results: "js"

17 June 2012

Christian Perrier: Debian: Thou Shalt Be Packaged

Debian is such a universal system:
# apt-get install wine and cheese
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  brasero brasero-common cheese-common desktop-file-utils evolution-data-server-common gcr gir1.2-atk-1.0 gir1.2-clutter-1.0 gir1.2-clutter-gst-1.0 gir1.2-cogl-1.0
  gir1.2-coglpango-1.0 gir1.2-evince-3.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-gst-plugins-base-0.10 gir1.2-gstreamer-0.10 gir1.2-gtk-3.0 gir1.2-gtkclutter-1.0
  gir1.2-gtksource-3.0 gir1.2-json-1.0 gir1.2-pango-1.0 gnome-desktop3-data gnome-icon-theme gnome-keyring gnome-sushi gnome-video-effects gstreamer0.10-plugins-ugly gvfs
  gvfs-backends gvfs-common gvfs-daemons gvfs-libs hwdata libbrasero-media3-1 libburn4 libcamel-1.2-29 libcap2-bin libcdio-cdda1 libcdio-paranoia1 libcdio13 libcheese-gtk21
  libcheese3 libclutter-1.0-0 libclutter-1.0-common libclutter-gst-1.0-0 libclutter-gtk-1.0-0 libclutter-imcontext-0.1-0 libcluttergesture-0.0.2-0 libcogl-common libcogl-pango0
  libcogl9 libebook-1.2-12 libecal-1.2-10 libedataserver-1.2-15 libedataserverui-3.0-1 libevdocument3-4 libevview3-3 libexempi3 libgck-1-0 libgcr-3-1 libgcr-3-common libgee2
  libgjs0b libglib2.0-data libgnome-desktop-3-2 libgssdp-1.0-3 libgupnp-1.0-4 libgxps2 libisofs6 libjson-glib-1.0-0 libjte1 libmozjs185-1.0 libmpg123-0 libmx-1.0-2 libmx-bin
  libmx-common libnautilus-extension1a libpam-cap libpam-gnome-keyring libpoppler-glib8 libpoppler19 libquvi-scripts libquvi7 libsidplay1 libt1-5 libtotem-plparser17
  libtracker-sparql-0.14-0 libwine libwine-alsa libwine-bin libwine-gecko-1.4 libwine-gl nautilus nautilus-data nautilus-sendto wine-bin
Suggested packages:
  libdvdcss2 gnome-video-effects-frei0r libcap-dev sidplay-base xsidplay wine-doc libwine-cms libwine-sane libwine-ldap libwine-print libwine-openal libwine-gphoto2 eog
  xdg-user-dirs tracker pidgin gajim ttf-mscorefonts-installer winbind avscan klamav clamav 
The following NEW packages will be installed:
  and brasero brasero-common cheese cheese-common desktop-file-utils evolution-data-server-common gcr gir1.2-atk-1.0 gir1.2-clutter-1.0 gir1.2-clutter-gst-1.0 gir1.2-cogl-1.0
  gir1.2-coglpango-1.0 gir1.2-evince-3.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-gst-plugins-base-0.10 gir1.2-gstreamer-0.10 gir1.2-gtk-3.0 gir1.2-gtkclutter-1.0
  gir1.2-gtksource-3.0 gir1.2-json-1.0 gir1.2-pango-1.0 gnome-desktop3-data gnome-icon-theme gnome-keyring gnome-sushi gnome-video-effects gstreamer0.10-plugins-ugly
  gvfs-backends hwdata libbrasero-media3-1 libburn4 libcamel-1.2-29 libcap2-bin libcdio-cdda1 libcdio-paranoia1 libcdio13 libcheese-gtk21 libcheese3 libclutter-1.0-0
  libclutter-1.0-common libclutter-gst-1.0-0 libclutter-gtk-1.0-0 libclutter-imcontext-0.1-0 libcluttergesture-0.0.2-0 libcogl-common libcogl-pango0 libcogl9 libebook-1.2-12
  libecal-1.2-10 libedataserver-1.2-15 libedataserverui-3.0-1 libevdocument3-4 libevview3-3 libexempi3 libgck-1-0 libgcr-3-1 libgcr-3-common libgee2 libgjs0b libglib2.0-data
  libgnome-desktop-3-2 libgssdp-1.0-3 libgupnp-1.0-4 libgxps2 libisofs6 libjson-glib-1.0-0 libjte1 libmozjs185-1.0 libmpg123-0 libmx-1.0-2 libmx-bin libmx-common
  libnautilus-extension1a libpam-cap libpam-gnome-keyring libpoppler-glib8 libpoppler19 libquvi-scripts libquvi7 libsidplay1 libt1-5 libtotem-plparser17 libtracker-sparql-0.14-0
  libwine libwine-alsa libwine-bin libwine-gecko-1.4 libwine-gl nautilus nautilus-data nautilus-sendto wine wine-bin The following packages will be upgraded:
  gvfs gvfs-common gvfs-daemons gvfs-libs   
4 upgraded, 95 newly installed, 0 to remove and 974 not upgraded.   
Need to get 100 MB/104 MB of archives.
After this operation, 250 MB of additional disk space will be used.
Thanks to Zobel, who pointed me to this one....

15 June 2012

Paul Tagliamonte: debtree.pault.ag - my latest toy

I ve pushed up some code (named familytree) to my GitHub, which lets folks browse the social connections that make up Debian. Many thanks to the number of people who gave me feedback (arno, luca, algernon (at least!)) Y all rock! I ve taken the dump of information from nm.debian.org, and rendered it out into four datasets. Mashing this up with an example d3 page, I ve come up with what I m calling debgraph . Here are some notable examples that I think are rad :) By the way - green lines indicate sponsorship, black lines indicate sponsors, and dashed lines indicate AM-ing. Tan nodes are DD-emeritus, and blue is active. I don t think this handles MIA correctly. Anyway, here it is: Me! (paultag) Algernon tbm (OK, this one is massive, I ve scaled it down a skitch old computer warning, it ll peg your CPU!) zack

8 June 2012

Dmitrijs Ledkovs: Hello Debian, Planet and Debconf12

I am going to Debconf12
I'm going to Debconf12
Hello Debian Planet!

I have recently became a Debian Developer. One of the first things I did, was fix some RC bugs in my packages due to an ABI break from upstream in a point release. Then I fixed some bugs in offlineimap... Little did I know, that I broke it for many Debian developers including my ex boss and the Debian Project Leader all at the same time.

Speaking of which, any help will be appreciated in hunting down a memory leak in offlineimap.

I am going to Debconf12, thanks to my employer. I am interested in Python/dh_python[2-3], dh, 3.0 (quilt) with a DVCS, lvm2, mdadm, btrfs-tools, autofs, e2fsprogs, dm-crypt, debian-installer, init-systems & friends, OpenERP, offlineimap... if you are as well, find me and talk to me =)))

Regards,
xnox

6 June 2012

Petter Reinholdtsen: Web service to look up HP and Dell computer hardware support status

A few days ago I reported how to get the support status out of Dell using an unofficial and undocumented SOAP API, which I since have found out was discovered by Daniel De Marco in february. Combined with my web scraping code for HP, Dell and IBM from 2009, I got inspired and wrote a web service based on Scraperwiki to make it easy to look up the support status and get a machine readable result back. This is what it look like at the moment when asking for the JSON output:
% GET https://views.scraperwiki.com/run/computer-hardware-support-status/?format=json&vendor=Dell&servicetag=2v1xwn1
supportstatus( "servicetag": "2v1xwn1", "warrantyend": "2013-11-24", "shipped": "2010-11-24", "scrapestamputc": "2012-06-06T20:26:56.965847", "scrapedurl": "http://143.166.84.118/services/assetservice.asmx?WSDL", "vendor": "Dell", "productid": "" )
%
It currently support Dell and HP, and I am hoping for help to add support for other vendors. The python source is available on Scraperwiki and I welcome help with adding more features.

5 June 2012

Ondřej Čertík: How to convert scanned images to pdf

From time to time I need to convert scanned documents to a pdf format.


Usage scenario 1: I scan part of a book (i.e. some article) on a school's scanner that sends me 10 big separate color pdf files (one pdf per page). I want to get one nice, small (black and white) pdf file with all the pages.


Usage scenario 2: I download a web form, print it, fill it in, sign it, scan it on my own scanner using Gimp and now I want to convert the image into a nice pdf file (either color or black & white) to send back over email.

Solution: I save the original files (be it pdf or png) into a folder and use git to track it. Then create a simple reduce script to convert it to the final format (view it as a pipeline). Often I need to tweak one or two parameters in the pipeline.

Here is a script for scenario 1:
<script src="https://gist.github.com/2871625.js?file=reduce2.sh"></script>
And here for scenario 2:
<script src="https://gist.github.com/2871625.js?file=reduce1.sh"></script>
There can be several unexpected surprises along the way. From my experience:

In general, I am happy with my solution. So far I was always able to get what I needed using this "pipeline" method.

4 June 2012

John Sullivan: To nook

My curiosity was definitely nookd by this story. While this doesn't seem to have been an act of censorship or anything nefarious by Barnes and Noble itself, this does point to just how terrifying ebooks can be if we aren't careful. In the future, when we are dealing with the entirety of human knowledge, we better be careful with the find and replace function. And we better make sure we control our computer systems so that other people can't nook us without our permission. See also: As someone who read War and Peace in paper form, much of it in bed, I definitely empathized with this:
Some weeks ago I decided that I wanted to read Tolstoy's War and Peace. Lou Ann loaned me her copy. At more than 1100 pages, reading it in bed required as much strength as balancing a box of bricks in my hands. In my senior years I have developed arthritis in my thumbs, which made the effort not only difficult, but painful.

3 June 2012

Jose Luis Rivas Contreras: Little CoffeeScript to resize images

I needed to resize about 300 images and couldn t find an easier way to do this than with help of node + CoffeeScript. So here s my script, it requires you to install (via npm) imagemagick and underscore: <script src="https://gist.github.com/2862235.js?file=resize.coffee"></script> Grab it if you want, is under Do Whatever You Want license. As you can see from the shebang (that s the first line of the script, with the #!) I ran it from my command-line, this was not used in a website, although it could without too much modifications (the magic of JavaScript).

1 June 2012

Steve Kemp: I've posted my javascript stuff

I previously mentioned some work I'd done with mixing Javascript & C. The code is now visible here: This consists of a binary which allows you to run javascript files, those javascript files have some extra methods available to them, allowing this sample file to execute and do things: Not great work, but still a useful exercise. ObQuote: "Please! I don't wanna go back there, you don't know what it's like to be treated as a freak!" - Shrek

Francois Marier: Proper indentation of Javascript files using js2-mode in emacs

If you use emacs for Javascript or Node.js development, you should have a look at js2-mode (apt-get install js2-mode in Debian / Ubuntu). In addition to providing syntax highlight, it will parse your Javascript and issue errors and warnings. (It's not as pedantic as jslint or jshint so you'll probably want to fix all of them before committing your files.) Unfortunately the default indentation style looks a bit crazy and adds excessive indentation to your code. Here's an example:

navigator.id.secret.generate(identity, function (plainKey, wrappedKey)
var data = wrappedKey: wrappedKey ;
$.post('/loggedin', data, function (res)
$("#message").text('All done');
, 'json');
, function (error)
$("#message").text('ERROR: ' + error);
);
It turns out that indenting Javascript properly is really hard, but you can turn on a special flag which will cause the indentation to "bounce" between different strategies, starting with the most likely one. This is what I now have in my ~/.emacs:
(custom-set-variables
'(js2-basic-offset 2)
'(js2-bounce-indent-p t)
)
You can find and configure all other options by issuing the following command:
M-x customize-group [RET] js2-mode [RET]
So yes, you can have both the reasonable indentation of the standard js-mode and the helpful warnings and errors of js2-mode!

29 May 2012

Michal &#268;iha&#345;: Android support in Gammu

Android support in Gammu is one of frequently requested features. I don't have neither time to motivation to do that, so unless somebody else will step up, it won't be done. Recently, I got offer from MyPhoneExplorer author to share it's applet for communicating with Android phones. It basically provides protocol similar to Sony-Ericsson phones Gammu already supports, just over TCP/IP. So all what would have to be done is glue layer for using TCP/IP and possibly some minor adjustments to Sony-Ericsson code. Both of these should be quite easy tasks and I'm willing to guide you through this process. In case anybody would be interested in this challenge, just let me know :-).

Filed under: English Gammu 1 comments Flattr this!

23 May 2012

Gintautas Miliauskas: HP LaserJet 1018 on Ubuntu

An offtopic post for an issue that I just ran into for the n-th time: after upgrading to Ubuntu Precise, my HP LaserJet 1018 stopped working again, the issue being that the printer firmware was not being uploaded to the printer properly. For posterity, (one) way to fix this is to uninstall the printer-driver-foo2zjs package, remove the printer itself from the list of printers, and then use HP utilities to set up the printer:

sudo apt-get remove printer-driver-foo2zjs
sudo apt-get install hplip-gui
sudo hp-setup


You may need to turn the printer off and on after the procedure to trigger the firmware uploader.

21 May 2012

Johannes Schauer: sisyphus wins ICRA 2012 VMAC

Sisyphus is a piece of software that I wrote as a member of a team from Jacobs University led by Prof. Dr. Andreas N chter. It managed to place our team first in this year's IEEE ICRA 2012 Virtual Manufacturing Automation Competition in all three rounds. The goal was, to stack a given set of boxes of different length, height and width on a pallet in a way that achieved optimal volume utilization, center of mass and interlock of the boxes. Besides the cartesian placement of a box on the pallet, the only other degree of freedom was a 90 rotation of the box around a vertical axis. Since the arrangement of boxes into a three dimensional container is NP hard (three dimensional orthogonal knapsack), I decided for a heuristic for an approximate solution. The premise is, that there are many boxes of equal height which was the case in the test cases that were available from the 2011 VMAC. Given this premise, my heuristic was, to arrange the boxes into layers of equal height and then stack these layers on top of each other. A set of boxes that would be left over or too little from the start to form its own full layer, would then be stacked on the top of the completed layers. There is a video of how this looked like. My code is now online on github and it even documented for everybody who is not me (or a potential future me of course). This blog post is about the "interesting" parts of sisyphus. You can read about the overall workings of it in the project's README. Python dict to XML and XML to Python dict The evaluation program for the challenge is reading XML files and the pallet size and the list of articles with their sizes are also given in XML format. So I had to have a way to easily read article information from XML and to easily dump my data into XML format. Luckily, all the XML involved was not making use of XML attributes at all, so the only children a node had, where other nodes. Thus, the whole XML file could be represented as an XML dictionary with keys being tagnames and the values being other dictionaries or lists or strings or integers. The code doing that uses xml.etree.ElementTree and turns out to be very simple:
from xml.etree import ElementTree

def xmltodict(element):
def xmltodict_handler(parent_element):
result = dict()
for element in parent_element:
if len(element):
obj = xmltodict_handler(element)
else:
obj = element.text
if result.get(element.tag):
if hasattr(result[element.tag], "append"):
result[element.tag].append(obj)
else:
result[element.tag] = [result[element.tag], obj]
else:
result[element.tag] = obj
return result
return element.tag: xmltodict_handler(element)

def dicttoxml(element):
def dicttoxml_handler(result, key, value):
if isinstance(value, list):
for e in value:
dicttoxml_handler(result, key, e)
elif isinstance(value, basestring):
elem = ElementTree.Element(key)
elem.text = value
result.append(elem)
elif isinstance(value, int) or isinstance(value, float):
elem = ElementTree.Element(key)
elem.text = str(value)
result.append(elem)
elif value is None:
result.append(ElementTree.Element(key))
else:
res = ElementTree.Element(key)
for k, v in value.items():
dicttoxml_handler(res, k, v)
result.append(res)
result = ElementTree.Element(element.keys()[0])
for key, value in element[element.keys()[0]].items():
dicttoxml_handler(result, key, value)
return result

def xmlfiletodict(filename):
return xmltodict(ElementTree.parse(filename).getroot())

def dicttoxmlfile(element, filename):
ElementTree.ElementTree(dicttoxml(element)).write(filename)

def xmlstringtodict(xmlstring):
return xmltodict(ElementTree.fromstring(xmlstring))

def dicttoxmlstring(element):
return ElementTree.tostring(dicttoxml(element))
Lets try this out:
>>> from util import xmlstringtodict, dicttoxmlstring
>>> xmlstring = "<foo><bar>foobar</bar><baz><a>1</a><a>2</a></baz></foo>"
>>> xmldict = xmlstringtodict(xmlstring)
>>> print xmldict
 'foo':  'baz':  'a': ['1', '2'] , 'bar': 'foobar' 
>>> dicttoxmlstring(xmldict)
'<foo><baz><a>1</a><a>2</a></baz><bar>foobar</bar></foo>'
The dict container doesnt preserve order, but as XML doesnt require that, this is also not an issue. Arranging items in layers When it was decided, that I wanted to take the layered approach, it boiled down the 3D knapsack problem to a 2D knapsack problem. The problem statement now was: how to best fit small rectangles into a big rectangle? I decided for a simple and fast approach as it is explained in Jake Gordon's blog article. There is a demo of his code and should the site vanish from the net, the code is on github. This solution seemed to generate results that were "good enough" while simple to implement and fast to execute. If you look very hard, you can still see some design similarities between my arrange_spread.py and his packer.js code. Jake Gordon got his idea from Jim Scott who wrote an article of arranging randomly sized lightmaps into a bigger texture. There is also an ActiveState Code recipe from 2005 which looks very similar to the code by Jake Gordon. The posts of Jake Gordon and Jim Scott explain the solution well, so that I dont have to repeat it. Should the above resources go offline, I made backups of them here and here. There is also a backup of the ActiveState piece here. Spreading items out The algorithm above would cram all rectangles into a top-left position. As a result, there would mostly be space at the bottom and left edge of the available pallet surface. This is bad for two reasons:
  1. the mass is distributed unequally
  2. articles on the layer above at the bottom or left edge, are prone to overhang too much so that they tumble down
Instead all articles should be spread over the available pallet area, creating small gaps between them instead big spaces at the pallet borders. Since articles were of different size, it was not clear to me from the start what "equal distribution" would even mean because it was obvious that it was not as simple as making the space between all rectangles equal. The spacing had to be different between them to accommodate for differently sized boxes. The solution I came up with, made use of the tree structure, that was built by the algorithm that arranged the rectangles in the first place. The idea is, to spread articles vertically first, recursively starting with the deepest nodes and spreading them out in their parent rectangle. And then spreading them horizontally, spreading the upper nodes first, recursively resizing and spreading child nodes. The whole recursion idea created problems of its own. One of the nicest recursive beauty is the following function:
def get_max_horiz_nodes(node):
if node is None or not node['article']:
return [], []
elif node['down'] and node['down']['article']:
rightbranch, sr = get_max_horiz_nodes(node['right'])
rightbranch = [node] + rightbranch
downbranch, sd = get_max_horiz_nodes(node['down'])
ar = rightbranch[len(rightbranch)-1]['article']
ad = downbranch[len(downbranch)-1]['article']
if ar['x']+ar['width'] > ad['x']+ad['width']:
return rightbranch, sr+[downbranch[0]]
else:
return downbranch, sd+[rightbranch[0]]
else:
rightbranch, short = get_max_horiz_nodes(node['right'])
return [node] + rightbranch, short
get_max_horiz_nodes() traverses all branches of the tree that node has below itself and returns a tuple containing the list of nodes that form the branch that stretches out widest plus the list of nodes that are in the other branches (which are shorter than the widest). Another interesting problem was, how to decide on the gap between articles. This was interesting because the number resulting of the subtraction of the available length (or width) and the sum of the articles lengths (or widths), was mostly not divisible by the amount of gaps without leaving a rest. So there had to be an algorithm that gives me a list of integers, neither of them differing by more than one to any other, that when summed up, would give me the total amount of empty space. Or in other words: how to divide a number m into n integer pieces such that each of those integers doesnt differ more than 1 from any other. Surprisingly, generating this list doesnt contain any complex loop constructs:
>>> m = 108 # total amount
>>> n = 7 # number of pieces
>>> d,e = divmod(m, n)
>>> pieces = (e)*[(d+1)]+(n-e)*[d]
>>> print pieces
[16, 16, 16, 15, 15, 15, 15]
>>> sum(pieces) == m
True
>>> len(pieces) == n
True
You can test out the algorithms that arrange rectangles and spread them out by cloning the git and then running:
PYTHONPATH=. python legacy/arrange_spread.py
The results will be svg files test1.svg and test2.svg, the latter showing the spread-out result. Here is an example how the output looks like (without the red border which is drawn to mark the pallet border): arrange_spread2.py contains an adaption of arrange_spread.py for the actual problem. Permutations without known length When creating a layer out of articles of same height, then there are four strategies that I can choose from. It is four because there are two methods that I can either use or not. I can rotate the article by 90 per default or not and I can rotate the pallet or not. So every time that I build a new layer, there are those four options. Depending on which strategy I choose, there is a different amount of possible leftover articles that did not fit into any layer. The amount is different because each strategy is more or less efficient. To try out all combinations of possible layer arrangements, I have to walk through a tree where at each node I branch four times for each individual strategy. Individual neighboring nodes might be the same but this outcome is unlikely due to the path leading to those neighboring nodes being different. To simplify, lets name the four possible strategies for each layers 0, 1, 2 and 3. I now want an algorithm that enumerates through all possible permutations of those four numbers for "some" length. This is similar to counting. And the itertools module comes with the product() method that nearly does what I want. For example, should I know that my tree does not become deeper than 8 (read: no more than eight layers will be built), then I can just run:
>>> for i in itertools.product([0,1,2,3], repeat=8):
...     print i
...
(0,0,0,0,0,0,0,0)
(0,0,0,0,0,0,0,1)
(0,0,0,0,0,0,0,2)
(0,0,0,0,0,0,0,3)
(0,0,0,0,0,0,1,0)
(0,0,0,0,0,0,1,1)
(0,0,0,0,0,0,1,2)
(0,0,0,0,0,0,1,3)
This would work if the number of layers created with each strategy was the same. But as each strategy behaves differently depending on the input, it cannot be known before actually trying out a sequence of strategies, how many layers it will yield. The strategy (0,0,0,0,0,0,0,0) might create 7 layers, resulting in (0,0,0,0,0,0,0,1), (0,0,0,0,0,0,0,2) and (0,0,0,0,0,0,0,3) yielding the same output as only the first 7 strategies count. This would create duplicates which I should not waste cpu cycles on later. It might also be that (0,0,0,0,0,0,1,0) turns out to be a combination of strategies that creates more than 8 layers in which case the whole thing fails. So what I need is a generator, that gives me a new strategy depending on how often it is asked for one. It should dynamically extend the tree of possible permutations to accommodate for any size. Since the tree will become humongous (4^11 = 4194304), already traversed nodes should automatically be cleaned so that only the nodes that make the current list of strategies stays in memory at any point in time. This sounded all complicated which made me even more surprised by how simple the solution was in the end. Here a version of the algorithm that could easily be ported to C:
class Tree:
def __init__(self, branch_factor):
self.branch_factor = branch_factor
self.root = "value": None, "parent": None, "children": []
self.current = self.root

def next(self):
if not self.current["children"]:
self.current["children"] = [ "value":val, "parent":self.current, "children":[] for val in range(self.branch_factor)]
self.current = self.current["children"][0]
return self.current["value"]

def reset(self):
if self.current["parent"]:
self.current["parent"]["children"].pop(0)
else:
return False
if self.current["parent"]["children"]:
self.current = self.root
return True
else:
self.current = self.current["parent"]
return self.reset()

def __str__(self):
return str(self.root)
It would be used like this:
>>> tree = Tree(4)
>>> print tree.next(), tree.next(), tree.next()
>>> while tree.reset():
...     print tree.next(), tree.next(), tree.next()
Which would be equivalent to calling itertools.product([1,2,3,4], 3). The special part is, that in each iteration of the loop I can call tree.next() an arbitrary amount of times, just how much it is needed. Whenever I cannot generate an additional layer anymore, I can call tree.reset() to start a new permutation. For my code I used a python specific version which is a generator:
def product_varlength(branch_factor):
root = "value": None, "parent": None, "children": []
current = root
while True:
if not current["children"]:
current["children"] = [ "value":val, "parent":current, "children":[] for val in range(branch_factor)]
current = current["children"][0]
if (yield current["value"]):
while True:
if current["parent"]:
current["parent"]["children"].pop(0)
else:
return
if current["parent"]["children"]:
current = root
break
else:
current = current["parent"]
It is used like this:
it = product_varlength(4)
print it.next(), it.send(False), it.send(False)
while True:
    print it.send(True), it.send(False), it.send(False)
Again, the expression in the loop can have any number of it.send(False). The first it.send(True) tells the generator to do a reset.

14 May 2012

Vipin Nair: A quick and beautiful hack!

You can get inspired from the most unlikely of places, and this time it was a twitter background image. I came across the twitter profile of @Nitish today, a fellow GSoC student from India. One thing that held my attention, apart from the fact that he tweets crazy, was the background picture in his profile. Yes I had not seen something like that before and I absolutely loved the concept. The image was large grid and each tile carried the profile picture of one of his twitter followers. It was beautiful. The background image was generated by twilk, a very popular application that I had never heard of. I wanted to try it, but I figured my follower count might be a little too low for the application to work. Twilk works only with twitter and I wanted it for Facebook. Instead of looking for something similar, I decided to write it myself. I had worked with the Python Imaging Library some time back and knew it would not be very difficult task. The first thing I needed was the profile pic thumbnails of my friends. Facebook API supports a call which returns a small 50x50 pixel profile pic of a user, if we send a valid user ID. I wrote a quick script that returned the user ID s of my friends on Facebook as JSON data. I grepped the user ID s from the JSON and wrote a small wget script to download the profile pics of all my friends to a directory. Once the download was in progress, I started my work with the imaging library. I knew the image count beforehand and after some quick math, I fixed the dimensions of the output image that I wanted. Once the dimensions were fixed, the work was fairly easy. I knew before hand how many images will be there in each row and how many rows will be there in total. All I had to do was to randomly pick one of the images from the directory, and arrange it on the output image canvas. Few lines of code later I get the result that I wanted and it is on my twitter profile. Yay! :) I have uploaded the python code in here. If you are running it, make sure you change the values according to your requirements. The image below is a cropped out from the output image to fit this div. Click on it to see the actual output. When I showed this to @Jaseeemabid, he asked me to put this up on Google App Engine and start a service so that even non geeks could use this. I liked the idea but I am slightly busy(lazy) now. I ll do it when I am free or when I see that there is some demand for this! :) Update As few Redditors pointed out, this may not be the best way to do it. This was just a quick hack to get something done. The JSON could be processed in Python itself and files can be downloaded as well. I modified an old PHP script to get the JSON data and since the structure was relatively simple, I grepped the relevant information and fed it to wget as I prefer wget over any other tool for mass downloads. Update 2 Redditor Bio Lazarus improved upon this and made an end to end version that does all of the above in one single python script and the code is available here. And if you like this post, you should follow me on twitter :)

26 April 2012

Olly Betts: Xapian GSoC 2012 Projects

At the end of the previous episode, you may remember our gallant heroes had a pile of 30 proposals to review. We soon spotted one more to mark as invalid (just a paste with our ideas list plus a some biographical details), and another got withdrawn by the student without explanation (but was low quality anyway), so that left us with 28. We had six volunteers for mentoring, and in the initial allocation we received five student slots from Google, but we asked nicely if we could have an extra one, and were lucky enough to get it. Last year we had four students, so that's a 50% increase. Here's those 28, broken down by the project idea:
  • 8 - Weighting Schemes
  • 6 - Learning to Rank
  • 3 - Dynamic Snippets
  • 2 - Lucene Backend
  • 2 - QueryParser improvements
  • 1 - Erlang Bindings
  • 1 - Improve C# and Java bindings
  • 1 - Improve PHP Bindings
  • 1 - Improve Python Bindings
  • 1 - Improving Japanese Support
  • 1 - Node.js Bindings
  • 1 - Postlist encodings
I find it interesting that the most popular three ideas have closer connections to Information Retrieval theory than most - probably these appeal to students who have taken IR courses and already have an interest and some knowledge of the project area. I think we should aim to get more ideas like these on the list in future years. It's worth noting that in several cases students had taken an idea in sufficiently different directions that there wasn't much overlap, so we didn't just pick the best proposal for each project idea to narrow things down. Also, the proposal isn't the only factor - we like to see applicants work on patch, and to interact with us on IRC and/or email. But in the end it happens we ended up with proposals which were all from different ideas - here are those we selected:
My congratulations to the lucky six, and my commiserations to those we weren't able to select. It wasn't an easy selection to make, and we truly appreciate the time you spent writing your proposal, working on patches, and on the rest of the application process. We'd encourage you to remain involved with Xapian, and to apply to us again next year if you're still eligible for GSoC.

24 April 2012

M nica Ram rez Arceda: Debian talk at Institut usias March

Last Friday (2012-04-20) I gave a talk about Debian at Institut usias March. This talk was inside Jornades t cniques d'FP 2012, a conference organized by different schools around Catalonia. I tried to explain to about 60 students the essence of Debian Project I hope they enjoyed the talk! To prepare the slides, I played a little bit with impress.js. I don't think I'm a great artist but I enjoyed using this nice tool. Here you have the slides I used for the talk: Talk: Debian. El sistema operatiu lliure creat per la comunitat. They are in Catalan but, although you don't understand this language, I encourage you to go until the last slide stars always have something to tell you ;)

22 April 2012

Gregor Herrmann: RC bugs 2012/16

this week I've started to look at the (not yet release critical) gcc 4.7 bugs. luckily there are still enough patches for them in the BTS but at the time of writing, at least 138 are not fixed & don't have a patch yet. so still some work ahead.

& for those who prefer to fix debian/rules files, lucas' last archive rebuild (where build-arch was used) still leaves enough work, & many bugs are not difficult to fix with a basic understanding of makefiles & debian build sytems.

21 April 2012

Paul Tagliamonte: gcc 4.7 patchathon part III

S more days, s more patches: Hacked out a few over the last few days, this time, to some good eats. I m making a habit of this tv-hack-time thing. Consider helping out with the gcc-4.7 ftbfss, there s a bunch!

14 April 2012

Sandro Tosi: Mercurial: what's the tag containing this changeset?

In software development, you often need to know: when was this feature released? in which releases was this changeset included?

Typical example is: you're debugging a problem, you find out what's the changeset introducing it, now you want to know when that changeset was firstly released (i.e. included in a tag) - how to do that?

hg log -r "cset:: and tag()"

where cset is the changeset you're looking for.

So know I know that Sphinx new way to load searchindex.js was introduced in the this changeset, and released for the first time in 1.0b2:

$ hg log -r "423faa03c908:: and tag()"
changeset: 2261:b494009dccf1
tag: 1.0b2
user: Georg Brandl <georg@python.org>
date: Sun May 30 19:52:08 2010 +0200
summary: Release preparation for 1.0b2.
...

awesome!

PS: why did I need to know that? because Matplotlib is still using the old way, but Debian needs the new one.

9 April 2012

John Sullivan: Photos from Belgium

I put up (with almost no filtration) the photos I took while visiting Brussels for FOSDEM in February. Most are from the Atomium.

8 April 2012

John Goerzen: 26 Hours At The Creek

I m back from one of the best experiences a father can have a whole day with two happy boys. I took Jacob (5) and Oliver (2) camping with me out by our creek. This was the first time we d camped there, and also the first time I d taken the boys camping without Terah along. So there were some unknowns, but it worked out great. When we got out there, I started to get the tents set up. The boys were interested, but pretty soon invented some games. A large nearby tree with plenty of low branches on its trunk became their locomotive, and certain sticks made the train go forward or backward, whistle, or ding its bell. This was good for quite some entertainment. Another nearby tree, near the bank of the creek, had some erosion near it. Combined with its roots, this made some natural steps. Jacob named some the enter steps and others the exit steps , and I sure heard about it if I walked the wrong way on the exit steps. We then gathered up sticks and the things we needed to build a campfire. We cooked up brats and zucchini. Although it was later than usual for supper, they loved it just the same. After that, we made smores for dessert another thing they loved. Then, one of the big highlights: sleeping in tents and sleeping bags. I had showed them the sleeping bags earlier, and they were excited to try them out. Morning was beautiful when the sun came out, it was shining right on the heavy dew on the ground, making the grass shine brightly. It s not every day that they get to start their morning slowly waking up by a warm fire. They were content to sit for quite awhile while I got things going for breakfast. It was chilly outside, so I helped them change clothes by the fire where. I then cooked them some scrambled eggs which, despite the lack of salt and pepper, seemed so much better than normal to the boys and then we went exploring. I took them to some areas with erosion, which Jacob called the big holes in the ground. It s really quite beautiful in spring, which this cellphone photo completely fails to capture. The boys loved climbing up and down these areas, some of which were quite tall. They discovered different kinds of rock on the way up and down, and with my help avoided discovering too much of the mud at the bottom. We hiked back to our camping spot through grass almost as tall as Oliver much to his delight and then after warming up by the fire for a bit, went off in the other direction. There is a grove of trees by the creek over there, which surprise became another train. Here are the boys explaining how it works. <iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" src="https://www.youtube.com/embed/43EcEK8F_ic?rel=0" width="560"></iframe> They helped pack things back up, too. Actually, it took some convincing to get Jacob to not pull up all the stakes for the tent before I was ready for them. Things didn t go perfectly, but then, they never do, and that was OK with everyone. Camping is an adventure, and it wouldn t be an adventure if you knew every detail beforehand. It is rare in life to be able to think that I have enough time to do anything the boys might want to do. Spend half an hour pretending a tree is a train sure, no problem. Today Oliver asked to go camping again, and was a bit disappointed when I didn t agree to go camping again right this minute, today. Jacob said, we had an EXCELLENT time and gave me hugs thinking about it. I have a lot of happy memories about the creek. We camped at the same spot where I went fishing or camped as a child. There have been family gatherings and even a birthday party out there. The boys and I have enjoyed a hike or a wagon ride to the area, but as I learned, nothing could possibly match the excitement of camping there. It is wonderful to add another happy memory of a time at the creek. And it s even better to see another generation of Goerzens discover that there s a lot of fun to be had down by the creek.

Next.

Previous.