Defining custom XPath functions on Python lxml
Parsing with lxml (Python library ) is a very good experience, especially compared to PHP.
An example advantage is that every element found by XPath is once again searchable
(whereas with PHP you can only provide it as a context, but you must provide the DOM ).
However, I came across a case where I needed to split the result to a list (split on python, explode on PHP).Posted in TechnologyNew Google Maps
I've recently got an invitation to the new Google Maps.
The slick new interface allows you (among others ) to zoom way out and see the earth.
More than just some Google Earth features that were implemented,
the entire interface is definitely more Social oriented,
you can got photos of the places you're looking at a lot easier.Posted in TechnologyYahoo increases Flickr's storage to 1 Tera Byte
With a move reminiscing of Google’s 1GB Inbox (Gmail) back at 2004,
Yahoo is attempting to set a new standard when it comes to Photo storage.Posted in TechnologyNew Langauge added to App Engine - PHP
Posted in TechnologySlugifying German string with Python
I'm working on this project that has some German titles, and a lot of irregularities inside them
(question marks, underscores, etc.)
Because I have to refer the object (in this case product) by some sort of understandable name, I've decided to slugify the title
(basically turn "THIS EXAMPLE!!" to "this-example") While I'm already doing that, I wanted to cleverly switch the "ä,ö,ü,ß" to "ae,oe,ue,ss" accordingly.
I'm pretty sure this might be useful to someone, and it's pretty harmless to share it so...
this gist was born, and the code is:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# -*- coding: utf-8 -*- def replace_all(text, dic): for replace_with, replace_what in dic.iteritems(): if type(replace_what) is list: for letter in replace_what: text = text.replace(letter,replace_with) else: text = text.replace(replace_what, replace_with) return text #example input: ssdfSERFS - ^#$%43 GSDG ____ :VKbm sdF öüoäßßEF_____-___ d a s d _e <>DFGDFG???? #example output: ssdfserfs-43-gsdg-vkbm-sdf-oeueoaessssef-d-a-s-d-e-dfgdfg def slugify(string,params = []): import re #unescape html entity signs (e.g. &amp; -> &) & lowercase string import HTMLParser string = HTMLParser.HTMLParser().unescape(string).lower() translation_dic = { 'ae' : ['Ä','ä','&Auml;','&auml;'], 'oe' : ['Ö','ö','&Ouml;','&ouml;'], 'ue' : ['Ü','ü','&Uuml;','&uuml;'], 'ss' : ['ß','&szlig;'], } string = replace_all(string,translation_dic) string = re.sub(r'[^a-zA-Z0-9\_\-\s]','',string) string = re.sub(r'[\s]{2,}',' ',string) string = string.replace(' ','-').replace('_','-').strip(' -') string = re.sub(r'[\-]{2,}','-',string) return string
Posted in Technology