As a toy project to play a little bit more with Python and accessing Twitter, I came out with the idea of calculating the Internal Fragmentation of user’s tweet.

To interface with Twitter services I used the Twitter extension located at http://code.google.com/p/python-twitter/, which has a pretty straightforward API.

The script shown below gives you back what average percentage of your last 20 tweets have been wasted.

  1.  
  2. import  twitter
  3. import  sys
  4.  
  5. if len(sys.argv) != 2:
  6.         print   "Provide a Twitter Username as Argument"
  7.         exit(-1)
  8.  
  9. api = twitter.Api()
  10. st = api.GetUserTimeline(sys.argv[1])
  11. sum = 0.0
  12. for s in st:
  13.         sum += (140.0len(s.text.encode("utf-8")))/140.0
  14.  
  15. print "%s internal fragmentation is %.2f%s" % (sys.argv[1], round(sum / len(st) * 100, 2), "%")
  16.  

And now some results:

$ python twinternal.py GabrielGonzalez
GabrielGonzalez internal fragmentation is 39.89%
$ python twinternal.py 48bits
48bits internal fragmentation is 36.79%
$ python twinternal.py reversemode
reversemode internal fragmentation is 38.72%
$ python twinternal.py aramosf
aramosf internal fragmentation is 32.41%

, , , , ,

Last week I faced a new problem, I had to program a installer for Windows in order to deploy some software we have produced at work. After a quick googling I found NSIS an installer generator, open source and with a simple scripting language.

NSIS comes with a compiler which parses the sentences writting in its own language and produces a pretty decent installer. It also has a look-and-feeling similar to latets Windows versions, so it was the perfect choice!

The scripting language is really simple, we can generate a simple installer with only the next few lines:

outFile “installer.exe”
installDir $DESKTOP
section
userInfo::getAccountType
pop $0
strCmp $0 “Admin” +3
messageBox MB_OK “not admin: $0″
return
messageBox MB_OK “is admin”
setOutPath $INSTDIR
file test.txt
writeUninstaller $INSTDIR\uninstaller.exe
createShortCut “$SMPROGRAMS\new oxtias.lnk” “$INSTDIR\uninstaller.exe”
sectionEnd
section “Uninstall”
delete $INSTDIR\uninstaller.exe
delete $INSTDIR\test.txt
delete “$SMPROGRAMS\new oxtias.lnk”
sectionEnd

OutFile “simpleAdvansenInstaller.exe”

InstallDir $DESKTOP

Section

SetOutPath $INSTDIR

WriteUninstaller $INSTDIR\uninstaller.exe

CreateShortCut “$SMPROGRAMS\simpleAdvansen.lnk” “$INSTDIR\uninstaller.exe”

SectionEnd

Section “Uninstall”

Delete $INSTDIR\uninstaller.exe

Delete $INSTDIR\test.txt

Delete “$SMPROGRAMS\simpleAdvansen.lnk”

SectionEnd

After compiling the script with the tool NSIS package’s comes with, two executables are generated:

simpleAdvansenInstaller.exe

Which will copy the uninstaller.exe to the Installation Dir set up to the Desktop and will add an entry in the Programs Menu for the uninstaller.

uninstaller.exe

Will delete itself and remove the entry in the Programs Menu.

NOTE: NotePad++ highlights the syntax of NSIS as well.

, ,

The problem I faced was the following:

  • Two processes I have to communicate with in order to validate data using stdin/stdout
  • No source code of this programs
  • Windows Platform

Since I am a UNIX guy I haven’t ever done anything advanced in Windows so I didn’t have the time to learn how to achive this in Windows as I would have done in any other Unix. Obviously I downloaded Mingw and I tried to used the proper POSIX functions but it didn’t work.

Now is when Python comes into play. It is an “easy to learn” (at sometime I will be discussing this topic) scripting language with a pretty well support in Windows platform, at some point this support seemed better than perl’s one so I chose Python.

After googling for 2 minutes about basic Python syntax and looking for function descriptions I came up with the solution, which was really straightforward and worked super-duper.

import subprocess

program = subprocess.Popen(['C:\path\to\program.exe, arg1, argn'], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE);

ret = check_ad.communicate(username + ” ” + group[0])

ret = program.communicate(“writing to stdin”);

print ret

Read from stdout

Really easy and simple code that can save someones life when working under pressure and do not have time to read a dozen of C/C++ examples.

I have just published a new paper under the “Good Coding Practices” section, which I think can be useful for someone else.

In this article I classify the bugs depending where in the life cycle of development they can be produced. This would be helpful to reduce the bugs which can be produced in the softwae development and will help if any bug appears since we know, just with its behaviour, where in the life cycle was produce. Therefore we will be able to react sooner and fix it in less time.

This is the base of comming papers about building secure software systems from a software engineering point of view.

Besied the PDF and HTML versions I always provide this time I have the Google version as well.

This is quick review of the article written by Martin Fowler about Continuous Integration, which basically explains that you should use a control version system and commit and build every day.

I only find, the advice regarding the periodicity of the commits and builds, not right at all since I think it would much better building a few times a day rather than a build per commit.

So I propose a fixed building times spread over the working hours which, as I explain in the paper, leads to an improvement of the productivity while keeps the developers happy, which I think is a must for all the project managers.

You can find the article in the Good Coding Practices section or get the pdf just here.

UPDATE: HTML version available!

Hi there, here is my very first Audio Show called “NITS” (Nothing Interesting To Say). Apologizes for my very bad speaking English but I haven’t been able to improve it as much as the written one.

The goal of this show is chat with someone about the computer related stuff I am working on, maybe I haven’t done my best this first time but I will keep on improving so stay tuned for the second show!

This I have talked:

- Aspect Oriented Programming

- Generative Programming

- Bluetooth Projects

PS: I think I haven’t spoken very much about technical stuff just a few general ideas really so I will focus on it a little more :)

Now GALD can be used to implement design by contract techniques. With just including a header and enabled the “By Contract” feature from the C preprocesor you will be able to enable pre/post conditions checks, completely written in straight forward C code, to your modules public interfaces.

Soon I will release a new version of GALD with just a short manual to help using this new and very HELPFUL features.

I have created a project in Sourceforge to improve the development cycle of GALD as well as making easier to those interested on it to track updates and even collaborate with the project. GALD will not be longer updated in this server.
I still need to create a mini webpage for it but as some of you know I am not any good in the web world so it will be delayed for a few days.

I have just released a simple tool, called GALD, which will make our life as developers easier since it allows you to detect the line where the memory problem is.

The good thing is you don’t need to replace the standard malloc(), calloc(), realloc() or free() functions since a macro subsystem will address link these to the GALD’s functions.

You just need to #include and run the application to check if you missed something while coding.

I look forward to hearing from you with desired improvents or any other comments.

1. Thou shalt not trust user inputs.

2. Thou shalt not trust other applications usage of your APIs.

3. Thou shalt not trust any files, network incoming data yourapp may process.

4. Thou shalt not overstimate the size of the destinations buffers.

5. Thou shalt close all the strings (with the NULL character).

6. Thou shalt free all allocated memory.

7. Thou shalt not allocate more resources than needed.

8. Thou shalt reuse as much code as possible.

9. Thou shalt design before coding.

10. Thou shalt DOCUMENT!!