Posts de ‘Fernando Meyer’

[] Writing a domain specific language DSL with python

Saturday, September 5th, 2009

A domain-specific language is a piece of software designed to be useful for a specific task in a fixed problem domain, they’re gaining popularity because they enhance productivity and reusability of artifacts. DSLs also enable expression and validation of concepts at the level of abstraction of the problem domain, this approach is very useful when you need to describe a user interface, a business process, a database, or the flow of information.

// <![CDATA[
google_ad_client = "pub-9202186284112152"; /* 300x250 blog content */ google_ad_slot = "4279590471"; google_ad_width = 300; google_ad_height = 250;
// ]]>

The DSL concept isn’t new after all, special-purpose programming languages and all kinds of modeling, specification languages have always existed, but this term rise due the popularity of domain-specific model.

You can easily implement dsls using the ruby language, Java or even C# if you prefer, but this isn’t the main propose of this article. The sine qua non become visible when I was implementing a simple test case with python. Indeed, there are a lot of python BDD-like frameworks, mostly who are self claimed the silver bullet, that are mismatching a lot of basic principles, but like I said, we are talking about dsls =)

With python we can easily create a piece of software that expresses some basic desired behavior, like rspec does, but much more pythonic.

spec.py

# coding: pyspec
    class Bow:
        def shot(self):
            print "got shot"
 
        def score(self):
            return 5
 
    describe Bowling:
        it "should score 0 for gutter game":
            bowling = Bow()
            bowling.shot()
            assert that bowling.score.should_be(5)

we can easily make this test dsl a runnable piece of python code, whiteout writing incompressible regular expressions, just using the python codecs and tokenizer.

Fist of all we need to define a new encoding for pyspec – our pre defined spec file syntax – this neat hacking enables a new path to tokenize this file

tokenizer.py

import tokenize
    import codecs, cStringIO, encodings
    from encodings import utf_8
 
    class StreamReader(utf_8.StreamReader):
        def __init__(self, *args, **kwargs):
            codecs.StreamReader.__init__(self, *args, **kwargs)
            data = tokenize.untokenize(translate(self.stream.readline))
            self.stream = cStringIO.StringIO(data)
 
    def search_function(s):
        if s!='pyspec': return None
        utf8=encodings.search_function('utf8') # Assume utf8 encoding
        return codecs.CodecInfo(
            name='pyspec',
            encode = utf8.encode,
            decode = utf8.decode,
            incrementalencoder=utf8.incrementalencoder,
            incrementaldecoder=utf8.incrementaldecoder,
            streamreader=StreamReader,
            streamwriter=utf8.streamwriter)
 
    codecs.register(search_function)

Our tiny translate function defines a easy way to translate both describe and it into a traditional python class and method definition.

def method_for_it(token):
        return token.strip().replace(" ", "_").replace("\"","" ) + "(self)"
 
    def translate(readline):
        previous_name = ""
        for type, name,_,_,_ in tokenize.generate_tokens(readline):
            if type ==tokenize.NAME and name =='describe':
                yield tokenize.NAME, 'class'
            elif type ==tokenize.NAME and name =='it':
                yield tokenize.NAME, 'def'
            elif type == 3 and previous_name == 'it':
                yield 3, method_for_it(name)
            else:
                yield type,name
            previous_name = name

Clever isn’t ? Now, fell yourself free to fork this project on GitHub and finish the job =) maybe someday we can have a real BDD python framework. http://github.com/fmeyer/pydsl/tree/master

References:

  1. [codecs — Codec registry and base

classes][5]

  1. [tokenize — Tokenizer

for Python source][6]

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Venha trabalhar na globo.com

Wednesday, September 2nd, 2009

A vaga é para uma das equipes responsáveis pelo desenvolvimento de novos produtos globo.com[bb]. Somos uma equipe multidisciplinar totalmente responsável pelos projetos desde sua concepção, criação, desenvolvimento, deployment até o suporte.

Não estamos procurando especificamente desenvolvedores Java, PHP, Ruby, Python, C ou C++, queremos uma pessoa totalmente agnóstica que não tenha medo de experimentar e aprender. É óbvio que cada um tenha suas especialidades e/ou preferências, mas estamos procurando programadores multidisciplinares e que além disso sejam capazes não só de programar mas de arquitetar, analisar, testar e trabalhar com novas tecnologias o tempo todo.

Mesmo assim, fortes conhecimentos em Ruby, Javascript, CSS, HTML, Banco de dados schema free, Infra e Amazon EC2 são um grande diferencial.

Por último mas não menos importante, todos nós somos geeks, apaixonados por tecnologia e super atualizados com as últimas novidades da Internet[bb] e do mercado. Nossa equipe é jovem, irreverente, descontraída e em constante evolução. É uma pessoa assim que estamos procurando.

A empresa oferece contratação apenas por CLT, com salário de mercado e plano de benefícios. Estamos localizados na Barra da Tijuca (Rio de Janeiro[bb]).

Se você acha que se enquadra, mande um email para nós beta@corp.globo.com com uma breve introdução, com todos os seus contatos github, twitter, LinkedIn e blog, mande também a lista dos 3 últimos livros[bb] que leu.

@fmeyer, @gcirne, @nevesbruno, @peleteiro

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Pagerank isn’t for humans

Sunday, August 30th, 2009

Transitioning from a web of links and a sequence of words to a web of content, meaning and knowledge is probably the next great moving that we are going to see on the next two or maybe three years.

I was chatting with a friend, how can we bring knowledge to the web, how can we use the web to make a really efficient human driven search engine, last week a few former Googlers made some noise about a totally new SE named cuil, I tried some queries on that page, but it does work almost like google, you must be pretty much binary to retrieve some interesting information, in another words, nothing has changed since 90’s on this area. This problem is around researcher’s minds for a long time, trust, influence, authority when applied to the web are essentially people based issues.

The propose is the content being an asset with information about what it really means running against the link/words algorithms with no explicit meaning and a simple assumption “yes … we know you’re a good reference because you have a lot of links”.

Make yourself a question, how to ask something? How do I ask for information?

You ask your close friend: “Sunday night guitar red cap TV?” when you really want to know about the Sunday night TV show where a girl with a funny red cap playing a guitar. Things does change when you bring meaning to it, thats what a human being does.

Indeed, Google is still leading this running, with several fields under extreme research, articles about Data Mining, Collective Intelligence and AI being published denotes the new approach.

Yes … things are about to change

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] O scrume

Friday, August 28th, 2009

Como varias pessoas próximas a mim ja sabem eu deixei a RedHat em abril deste ano por motivos pessoais, o trabalho remoto mesmo tendo suas vantagens não conseguiu despertar em mim a mesma proatividade e cumplicidade que eu teria trabalhando com pessoas reais durante o dia-a-dia. Trabalhar em uma empresa em que eu pudesse estar fisicamente locado com um time e desenvolvendo um software incremental foram os motivos que me levaram a globo[bb].com.

Dentro da gcom trabalhamos usando a metodologia Scrum[bb], temos varios casos de sucesso e uma boa reputaçao no mercado brasileiro com a adoção desta metodologia. Mas o sucesso dos projetos não vem apenas do uso de uma metodologia agil, pessoas com otimas noções de negócio e tecnologia fazem o barco andar de forma gloriosa. Tive a sorte de participar logo no primeiro contato na empresa com profissionais que valorizam a qualidade de seu código, alem de entregar algo rápido e funcional também olham para o como fazer melhor, refatorar um algoritmo que não ficou bom em uma primeira abordagem, ou seja fazemos software.

Sempre brinco pelos corredores, que hoje em dia que as empresas se preocupam mais em vender a imagem que fazem o negocio de uma forma diferente das demais e deixam totalmente de lado as boas praticas de desenvolvimento que foram esculpidas durante anos de tentativas, erros e evoluções. Nasce ai o Scrume, a desculpa de usar a metodologia e/ou a abordagem agile com pessoas que não levam à paixão seu trabalho. Conversas que tive com o Philip calçado e artigos como “The Decline and Fall of Agile” veem apenas confirmar esta visão, anos de evolução sendo deixadas de lado por modismos.

Se você pensar de uma maneira racional, software vem sendo desenvolvido ao longo dos anos possibilitando avanços significativos em vários campos como biologia[bb], astronomia[bb] e finanças[bb] para não me alongar, a não adoção do “scrum” não fez projetos como linux ou colocar o homem na lua com um tubo de 8088 por exemplo ser fadado ao fracasso. Ocorreram erros, acertos e em alguns momentos pessoas precisaram se sobrepor para trazer o bom senso a tona.

Concordo plenamente que a adoção do scrum por exemplo, aumenta a visibilidade dos problemas que ocorrem no desenvolvimento de features por termos um feedback[bb] rápido do cliente ou da organização, mas não é tendo apenas essa abordagem que fara seu projeto ser bem sucedido.

Os projetos hoje que dão certo, estão envoltos em uma gama de outros fatores que equilibram essa equação. Fica meu conselho, não é trazendo um evangelista[bb] e adotanto Scrum para sua empresa que fará seus projetos darem certo, mas se e somente se as pessoas envolvidas acreditarem no que estão fazendo.

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Configuring Joseki + Pellet + TDB

Thursday, August 27th, 2009

I was looking for some documentation about using TDB and Pellet
reasoser on Jena without pet peeves, didn’t found anything usable at all, so after a few
attempts I was still fighting against an ambiguity error,
whenever Joseki tries to build a dataset, the following exception pops up

18:18:49 WARN  Configuration        :: Failed to build dataset from
description (service name: reason): cannot find a most specific type
for file:///joseki-config.ttl#dataset_reason, which has as
possibilities: ja:RDFDataset ja:InfModel.
com.hp.hpl.jena.assembler.exceptions.AmbiguousSpecificTypeException:
cannot find a most specific type for file:///Users/fmeyer/projects/semantic/
servicos/joseki/joseki-config.ttl#dataset_reason, which has as possibilities:
ja:RDFDataset ja:InfModel.
 at com.hp.hpl.jena.assembler.assemblers.AssemblerGroup$PlainAssemblerGroup.
 open(AssemblerGroup.java:104)
 at com.hp.hpl.jena.assembler.assemblers.AssemblerGroup$ExpandingAssemblerGroup.
 open(AssemblerGroup.java:70)
 at com.hp.hpl.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:41)
 at com.hp.hpl.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:38)
 at org.joseki.DatasetDesc.newDataset(DatasetDesc.java:65)
 at org.joseki.DatasetDesc.initialize(DatasetDesc.java:60)
 at org.joseki.Configuration.processModel(Configuration.java:112)
 at org.joseki.Configuration.(Configuration.java:83)
 at org.joseki.Dispatcher.setConfiguration(Dispatcher.java:130)
 at org.joseki.Dispatcher.initServiceRegistry(Dispatcher.java:100)
 at org.joseki.Dispatcher.initServiceRegistry(Dispatcher.java:93)
 at org.joseki.RDFServer.init(RDFServer.java:79)
 at org.joseki.RDFServer.(RDFServer.java:64)
 at joseki.rdfserver.main(rdfserver.java:85)

We just need to define a GraphTDB as a subclass of a Model as follow to fix this issue

@prefix ja:     <http ://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix tdb:     </http><http ://jena.hpl.hp.com/2008/tdb#> .
 
## Initialize TDB.
 
[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .
 
## ---- A whole dadaset managed by TDB
< #dataset_reason> rdf:type      ja:RDFDataset ;
  ja:defaultGraph < #inf_graph> .
 
< #dataset> rdf:type      ja:RDFDataset ;
  ja:defaultGraph < #def_graph> ;
  .
 
< #inf_graph> rdf:type  ja:InfModel ;
    ja:reasoner [
        ja:reasonerClass
            "org.mindswap.pellet.jena.PelletReasonerFactory" ;
       ] ;
    ja:baseModel < #tdbGraph> .
 
< #def_graph> rdf:type  ja:InfModel ;
    ja:baseModel < #tdbGraph> .
 
< #tdbGraph> rdf:type tdb:GraphTDB ;
    tdb:location "DB" ;
    .

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Berkeley e-classes for your IPod

Wednesday, August 26th, 2009

Last April, UC Berkeley, one of the premiere schools in the United States, announced its plan to put complete academic courses on iTunes. Fast forward nine months, and you can already find 59 full courses ready for your iPod. Simply click here to access Berkeley’s iTunes site (or here for the Rss feed).

No matter where you live, you can access at no cost the very same courses attended by students paying full tuition. And, given the critical mass of courses being offered across a range of disciplines, you can put together your own personalized curriculum and expand your horizons on the fly.

That’s include interesting computer’s science coursers like, CS 162 – Operating systems and System programming and CS 61C – Machine Structures. You can listen this podcast and forget about these classes in university (but I think that your teacher will not appreciate)

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Firefox is crashing on my macbookpro

Wednesday, August 26th, 2009

I don’t know why but it’s happening, every time when i open a second gmail tab my Firefox crashes

Exception:  EXC_BAD_INSTRUCTION (0×0002)
Code[0]:    0×0000000d
Code[1]:    0×00006e64

Thread 0 Crashed:
0   libSystem.B.dylib                  0×90029ae5 _longjmp + 37
1   00000000     0xc00101dd 0 + -1073675811

I was looking for some similar bug at firefox bugzilla but, I didn’t found anything about it. That isn’t the unique problem, I’m coding a web interface to access and test some Webservices, then I discovered another bug: div element with visibility:hidden still show scrollbars, I couldn’t reproduce the problem on Firefox running over Win32 with the same html file, so I think that’s a bug.

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Linux Kernel in a Nutshell is now Creative Commons: free pdf download

Wednesday, August 26th, 2009

Written by a leading developer and maintainer of the Linux kernel, Linux Kernel in a Nutshell is a comprehensive overview of kernel configuration and building, a critical task for Linux users and administrators.The book is available for download in either PDF or DocBook format for the entire book, or by the individual chapter.

To quote of the book’s author:

If you want to know how to build, configure, and install a custom Linux kernel on your machine, buy this book. It is written by someone who spends every day building, configuring, and installing custom kernels as part of the development process of this fun, collaborative project called Linux. I’m especially proud of the chapter on how to figure out how to configure a custom kernel based on the hardware running on your machine. This is an essential task for anyone wanting to wring out the best possible speed and control of your hardware.

http://www.kroah.com/lkn/

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Switching from bloglines to vienna

Wednesday, August 26th, 2009

I’m changing my default RSS reader from the web-based bloglines to Vienna, a rss reader for Mac OS X, Vienna keeps following RSS feeds simple and functional with smart folders, groups, an integrated browser and item flagging. It’s the perfect tool for offline readers like me.

ps: Yeap, I’m having some problems to get an internet connection here in Colombia; (sic)

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark


[] Debug Backwards in time

Wednesday, August 26th, 2009

What if a debugger could allow you to simply step BACKWARDS? Instead of all that hassle with guessing where to put breakpoints and the fear of typing “continue” one too many times… What if you could simply go backwards to see what went wrong? This is the essence of the “Omniscient Debugger” — it remembers everything that happened during the run of a program, and allows the programmer to “step backwards in time” to see what happened at any point of the program. All variable values, all objects, all method calls, all exceptions are recorded and the programmer can now look at anything that happened at any time

HomePage: http://www.lambdacs.com/debugger/debugger.html

Article: http://www.lambdacs.com/debugger/Article.html

Video: http://video.google.com/videoplay?docid=3897010229726822034&q=engedu+debugging

Facebook Slashdot WordPress LiveJournal Plurk Read It Later Digg Posterous Reddit Tumblr Orkut Yahoo Bookmarks DZone Google Bookmarks Twitter Google Gmail Delicious Google Reader LinkedIn Yahoo Messenger Share/Bookmark