ago
09
2010

IP representation

Yesterday I came across with an interesting contruction for IP address. Suppose that you want store the address ‘192.168.10.33′ no matter the dot.

192<<24|168<<16|10<<8|33

That produces

3232238113 (0xc0a80a21)

To return is just get the address in hex format and split in 4 sections. Means that: c0 (192) a8  (168) 0a (10) 21 (33). An example using Python generators to return using big endian format (download).

def octet(ip):
        for i in range(-24,8,8):
                yield ip >> -i & 0xff

And got each value:

r = octet(ip)
r.next() # returns 192
r.next() # returns 168
r.next() # returns 10
r.next() # returns 33

ago
06
2010

TTMMHTW: meego, rtos, android, qemu, python, dojo

Some things that made me happy this week.
  • Video MeeGo on BeagleBoard and How-to from scratch.
  • NuttX RTOS that is ANSI/POSIX compliant.
  • ShowMeDoscreencasts to learn with the open source community.
  • BRTOS – My friend Marcelo Barros published his works on Real-time Operating System for MSP430 [code repository ] and explanations (portuguese) sub-divided in part II part III and part IV.
  • Hack a Day series on Android Development 101 Part 1 (Hello WorldPart 2 (Hello World improved) Part 3 (Introduction to DatabasesPart 4 (Advanced Database/GUI Code and DDMS) Part 5 (DroidDraw & Information Tracker Completed)
  • Writing kernels that boot with Qemu and Grub – a tutorial (also this)
  • Release of PySide 0.4.0 including Qt Mobility and Mac OS X support.
  • 5 min. video explaining Coding Dojo basics.
ago
05
2010

Latex Beamer themes

Creating your presentation slides with Latex (Beamer) is quick and easy when you have a template to based on. I’ve created one example describing the main features that an average user might need and setted to different templates. You can run by typing:

$ pdflatex file.tex

Enjoy :-)

I had to rename template file from .tex to .txt to upload. If you were compile, rename to .tex again.

  1. AnnArbor – template (.tex) and example (.pdf)
  2. CambridgeUS – template (.tex) and example (.pdf)
  3. Hannover – template (.tex) and example (.pdf)
  4. Antibes – template (.tex) and example (.pdf)
  5. Copenhagen – template (.tex) and example (.pdf)
  6. Ilmenau – template (.tex) and example (.pdf)
  7. Bergen – template (.tex) and example (.pdf)
  8. Darmstadt – template (.tex) and example (.pdf)
  9. JuanLesPins – template (.tex) and example (.pdf)
  10. Berkeley – template (.tex) and example (.pdf)
  11. Dresden – template (.tex) and example (.pdf)
  12. Luebeck – template (.tex) and example (.pdf)
  13. Berlin – template (.tex) and example (.pdf)
  14. Frankfurt – template (.tex) and example (.pdf)
  15. Madrid – template (.tex) and example (.pdf)
  16. Boadilla – template (.tex) and example (.pdf)
  17. Goettingen – template (.tex) and example (.pdf)
  18. Malmoe – template (.tex) and example (.pdf)
  19. Marburg – template (.tex) and example (.pdf)
  20. Szeged – template (.tex) and example (.pdf)
  21. PaloAlto – template (.tex) and example (.pdf)
  22. Montpellier – template (.tex) and example (.pdf)
  23. Warsaw – template (.tex) and example (.pdf)
  24. boxes – template (.tex) and example (.pdf)
  25. Pittsburgh – template (.tex) and example (.pdf)
  26. default – template (.tex) and example (.pdf)
  27. Rochester – template (.tex) and example (.pdf)
  28. Singapore – template (.tex) and example (.pdf)

I created this template to quick access what that I most use on presentations. Things I forgot on purpose: I didn’t mentioned figures, but is easy too.

Worth seeing: for diagrams I noted that Dia exports to Latex, so It’s a quick way to insert some blocks or some UML interface. Finally, embed Python inside Latex still works too :-)

** See below ONLY if you are interested in HOW I made these templates **

Of course that I didn’t create each file by hand. I used the following lines to create two script files in order to replace the text and run pdflatex. (list.txt)

for i in `cat list.txt` ; do echo  "sed -e
's/^\\\usetheme{.*/\\\usetheme{$i}/' beamer-template.tex &gt; $i-example.tex" ; done
> script.sh
for i in `cat list.txt` ; do echo "pdflatex $i-example.tex" ; done >
script-make.sh
jul
30
2010

TTMMHTW: math, research, network, syscalls and linux

Some things that made me happy this week.


jul
22
2010

Shortening URL

There are many URL shortening services. I just picked one (u.nu) to use from command line interface and chose something really quick and simple. Here’s the code:

# -*- coding: utf-8 -*-
from urllib import urlencode
import httplib
import sys

api_url="u.nu"
var = urlencode({'url':sys.argv[1]})
args = "/unu-api-simple?%s" % (var)
conn = httplib.HTTPConnection(api_url)
conn.request("GET",args)
ret = conn.getresponse()
print ret.read()
Download the script here.

Just run passing the URL, for example:

$ python u.py www.coding.com.br

http://u.nu/72mpd

Easy your life by putting the script on your $PATH and execution (+x) file mode. Worth check the API from other services:

jul
13
2010

A brief on “designated initializers”

The GNU Compiler Collection (GCC) for C language doesn’t initialize variables zeroed. For simple variables types like int or float is just equal to 0 or 0.0 respectively. Now, suppose that you have a “large” struct and doesn’t want to set each member  individually… you could just type “={0}” which means that the first member is explicitly initialized to zero and the remaining members are implicitly initialized, also zero. Let’s see an example:

typedef struct
{
int a;
char c;
char s[10];
int *ptr;
} data;

When you initialize with:

data d;

You got some random value like:

{a = -1208298748, c = -12 ‘\364′, s = “\317\372\267\230\353\377\277\351\203\004″, ptr = 0xb7e94cc5}

When you type:

data d = {0};

You’ll have each struct member initialized to zero.

{a = 0, c = 0 ‘\000′, s = “\000\000\000\000\000\000\000\000\000″, ptr = 0×0}

You can learn much more about designated inits [section 6.26] on GCC docs.

jul
03
2010

Embed Python inside Latex

After a video demostrating the use of Python inside a Tex document. I decided to do a document explaining how to use,  check it:

Embed Python Inside Latex (pdf ~ 100KB)

Update: I also published online through Scribd, check here.

jun
24
2010

Opcode stats

I was trying some GCC options and decided see how they affect assembly code generated. I’ve created a simple Python script that parses .s output and put in a human readable way. Suppose the classical Hello World program. The output will be something like:

$ python stats_opcodes.py file

For Cortex-m3 (check previous post):

At my laptop (x86):

Download the script here.