venerdì 29 ottobre 2010

I've got a good mark!

While it was quite rare in my shooldays, I got a good mark for my effort on the dblinq provider.

It's a query provider that support MySQL, Oracle, SQL Server, PostgreSQL, SQLite, Ingres and Firebird and I hacked on it quite intensively the last year.

I worked in particular on

  1. performances: I got a 4x performance improvement on expression tree translation and I introduced a Profiler tailored for that code
  2. subqueries
  3. data maps

Moreover I fixed some bugs (and introduced some others :-D)
For such an effort ohloh given me this kudos rank:
Ohloh profile for Giacomo Tesio

I really hope that Epic.NET will be even more used than DbLinq (which btw is the also the Mono default query provider!).

Still, it's nice to get a good mark for homeworks done before.

giovedì 28 ottobre 2010

An exclusive gift...

I recently developed a small Java Mobile application for my wife's phone, called SGA Data Collector.

It's designed to help Sara in the collection of data regarding children born small for gestational age for her thesis.

It's a quite original gift for a woman, I think. :-)

And not a cheap one, according to Ohloh!

martedì 26 ottobre 2010

SyntaxHighlighter on Blogger

Yesterday I installed SyntaxHighlighter on this blog.

Here are the steps I followed:
  1. On the blogger template I added the following code just before the </head> closure.
    This would add the Gorbatchev's base framework with the brush for XML.
    Moreover I add the Haskell brush from Michael Rüegg.
    In the future I could add the following brush too:
  2. Before the </body> closure, insert the SyntaxHighlighter.all(); call.
  3. When composing a blog entry that contains source code, click the "Edit Html" tab and put your source code (with html-escaped characters) between these tags:
    <code language="haskell">
      <pre class="brush: haskell">
      </pre>
    </code>
You can replace the "haskell" brush with whatever language you are using (as far as you included the relative brush js file).

lunedì 25 ottobre 2010

Xml Schema Versioning

It is always cheaper to design the architectural properties of a software at the very early stage of the development process.

Of course which architectural properties are required by a software is a marketing choise: not every software require concurrent access, for example.
Or security. Or easy maintenance.

In some case a code too easy to undestand could actually be a marketing error.
Many big companies live on complex legacy software maintenance.

Unfortunately it's by far more expensive to introduce an architectural property ex post. Most of times such requirement costs more than rewriting from the ground up the application.
Again unfortuately the project managers do not understand this trade off and cut too easily such properties.

A protocol versioning is a good example.

When you deliver a new protocol (eg for comunicating with a third party's software) no one will ask you for a versioning system.
But trust me: the protocol will evolve and you'll have to crack your head against it's versioning and backward compatibility.

I recently had to design a simple xml based protocol for a banking software and I did some research about xml schema versioning.
I found an interesting paper describing the following best practices:
  1. Capture the schema version somewhere in the XML schema
  2. Identify in the instance document, what version/versions of the schema with which
    the instance is compatible.
  3. Make previous versions of an XML schema available.
  4. When an XML schema is only extended, (e.g., new elements, attributes, extensions to
    an enumerated list, etc.) one should strive to not invalidate existing instance
    documents.
  5. Where the new schema changes the interpretation of some element (e.g., a construct
    that was valid and meaningful for the previous schema does not validate against the
    new schema), one should change the target namespace.

I build my versioning solution on top of the second option.
I set the schema version attribute and I define a matching attribute in the root element:


The restriction in simpleType VersionNumber allow me to list the instance versions that are compatible with the current schema.

This would allow the schema to evolve without breaking the previous versions until the break is a semantic one.

martedì 19 ottobre 2010

Al Governo della Repubblica Italiana

Una collega di idee assolutamente liberali (credo abbia votato PdL) mi invita a compilare questo modulo con oggetto: Non voglio il libro "Due anni di governo".

Con riferimento all'annuncio del Presidente del Consiglio On. Silvio Berlusconi di inviare ad ogni famiglia italiana il libro "Due anni di  governo", mi preme comunicarVi che non desidero assolutamente riceverlo, essendo un mio diritto in base al Decreto legislativo 30 giugno 2003, n. 196, Codice in materia di protezione dei dati personali, nella fattispecie articolo 7 comma 4b.

Riterrei altresì opportuno che la somma istanziata per tale attività, fosse meglio destinata al Ministero della Pubblica Istruzione e/o al Ministero della Sanità.

Ringraziando per l'attenzione porgo distinti saluti.

Giacomo Tesio

Sorpreso accetto, compilo, invio e volentieri diffondo.

In un momento di crisi come questo, tale spreco di denaro pubblico risulta assolutamente inopportuno.

Ode al gabinetto

Ti ringrazio Signore, per quel bianco
inesorabile, sfondo perfetto,
tela di ogni più piccolo difetto,
profondità insondata... di cui manco.

Profondità che merita un sonetto,
perché ricorda ad un fedele stanco
l'Umiltà per camminare al Tuo fianco.
Grazie Signore... per il gabinetto.

Rimarrebbe presidio di Uguaglianza
perfino se passasse il lodo Alfano,
rubando ai retti il senso di Giustizia.

Riuscirebbe a diffonder la notizia
se la Carta che fu Patria Speranza
fosse insozzata da un sol deretano?

lunedì 18 ottobre 2010

RPN calculator (without custom stack)

I finally managed to write an RPN Calculator without a stack, except the call stack.

I build two diffirent solution:

  • v0.1 That use two different data type (Computation and Expression) to parse recursively the expression's tokens. This is a bit more convoluted than v0.2 but could probably be simplified with a Writer.
  • v0.2 That use foldr and Computation and hack function closures (from an idea suggested by Pieter Wuille).
    Actually, this is a bit like a trickery, since it use a kind of stack of function embedded in closures instead of a stack of value.
    BTW it's funny enought to be proud about it. :-)

I'm also thinking about a v0.3 with a different approact, but for now I've played enough.

Of course, using a custom stack (like a list), would reduce the code to 10 to 15 lines.
But it would not be such a funny hack!

domenica 17 ottobre 2010

Rotate a video on Debian GNU/Linux

I have a huge number of mp4 videos from my n95. They are all related to my wonderful family.

Some of them have to be rotated but unfortunately the main Debian distribution can not include many video manipulation softwares due to patents and other similar issues.

So I had to use the Debian Multimedia unofficial repository.

I downloaded and installed the keyring with
wget http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2008.10.16_all.deb
dpkg -i debian-multimedia-keyring_2008.10.16_all.deb

Than, I added to my /etc/apt/source.list the line:

deb ftp://ftp.debian-multimedia.org squeeze main non-free

Finally I run a apt-get update && apt-get install avidemux.

On Avidemux I used the MPEG-4 ASP (Xvid) as video codec with rotate filter and MP3 (lame) with a 3 second delay to convert it.

mercoledì 13 ottobre 2010

RPN calculator without stack

I'm tring to write an RPN calculator that do not use a stack (a part from the recursion callstack itself).

While it seem easy at a first look, it's not.

I asked some question about the approach on the #haskell freenode.net channel and got an interesting link from mm_freak and a wonderful solution from sipa.

data RPN = Const Float | Op (Float -> RPN)

count :: RPN -> Int -> Int
count (Const _) i = i
count (Op f) i = count (f 0) (1 + i)

instance Show RPN where
  show (Const v) = show v
  show q = "<<" ++ (show $ count q 0) ++ "-ary function>>"

infixr 3 @@

(@@) :: RPN -> RPN -> RPN
_ @@ (Const v) = Const v
(Const v) @@ (Op f) = f v
(Op f1) @@ r = Op (\v -> f1 v @@ r)

rpnBinOp :: (Float -> Float -> Float) -> RPN
rpnBinOp op = Op (\a -> Op (\b -> Const $ b `op` a))
rpnUnOp :: (Float -> Float) -> RPN
rpnUnOp op = Op (\a -> Const $ op a)

push :: Float -> RPN
push v = Const v
rpnAdd = rpnBinOp (+)
rpnSub = rpnBinOp (-)
rpnMult = rpnBinOp (*)
rpnNeg = rpnUnOp negate

main = do
  let rpn = push 2 @@ push 3 @@ rpnSub @@ push 5 @@ rpnMult @@ rpnNeg
  print rpn



Even if the solution is not still what I'm looking for, it's extremely clear and mind opening.

I blogged it for further studies...

martedì 12 ottobre 2010

Ext.NET TabPanel TabPosition

On Ext.NET's TabPanel, setting TabPosition to TabPosition.Bottom will not work when EnableTabScroll is set to true.

domenica 10 ottobre 2010

Problem 7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10001st prime number?

solution = primes!!10000
    
primes :: Integral a => [a]
primes = 2 : iterate nextPrime 3
    where nextPrime x = head $ filter isPrime[(x+1)..] 

isPrime :: Integral a => a -> Bool
isPrime x = and $ [mod x p /= 0 | p <- takeWhile lowerThanSqrtX primes]
    where lowerThanSqrtX candidate = candidate <= (round $ sqrt $ fromIntegral x)

sabato 9 ottobre 2010

Problem 6

The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385

The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

solution = sumSquare - squareSum
    
squareSum = sum $ map (^2) [1..100]
sumSquare = (^2) $ sum [1..100]

Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

solution =  head $  filter (isEvenlyDivisibleFor [2..20]) [21..]
     
isEvenlyDivisibleFor range candidate = and [candidate `mod` x == 0 | x <- numbersToTest range]
    where numbersToTest = removeDivisors . reverse
          removeDivisors [] = []
          removeDivisors (x:xs) = x : (removeDivisors $ filter ((/=0).(mod x)) xs)

Problem 4

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.

Find the largest palindrome made from the product of two 3-digit numbers.

solution = maximum $ filter isPalindromic [x*y | x ← [2..999], y ← [2..999]]

isPalindromic x = text ≡ (reverse text)
    where text = show x