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
tags: python
posted in programação by Tiago Maluta | No Comments
Some things that made me happy this week.
- Video MeeGo on BeagleBoard and How-to from scratch.
- NuttX RTOS that is ANSI/POSIX compliant.
- ShowMeDo – screencasts 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 World) Part 2 (Hello World improved) Part 3 (Introduction to Databases) Part 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.
posted in ttmmhtw by Tiago Maluta | 1 Comment
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.
- AnnArbor – template (.tex) and example (.pdf)
- CambridgeUS – template (.tex) and example (.pdf)
- Hannover – template (.tex) and example (.pdf)
- Antibes – template (.tex) and example (.pdf)
- Copenhagen – template (.tex) and example (.pdf)
- Ilmenau – template (.tex) and example (.pdf)
- Bergen – template (.tex) and example (.pdf)
- Darmstadt – template (.tex) and example (.pdf)
- JuanLesPins – template (.tex) and example (.pdf)
- Berkeley – template (.tex) and example (.pdf)
- Dresden – template (.tex) and example (.pdf)
- Luebeck – template (.tex) and example (.pdf)
- Berlin – template (.tex) and example (.pdf)
- Frankfurt – template (.tex) and example (.pdf)
- Madrid – template (.tex) and example (.pdf)
- Boadilla – template (.tex) and example (.pdf)
- Goettingen – template (.tex) and example (.pdf)
- Malmoe – template (.tex) and example (.pdf)
- Marburg – template (.tex) and example (.pdf)
- Szeged – template (.tex) and example (.pdf)
- PaloAlto – template (.tex) and example (.pdf)
- Montpellier – template (.tex) and example (.pdf)
- Warsaw – template (.tex) and example (.pdf)
- boxes – template (.tex) and example (.pdf)
- Pittsburgh – template (.tex) and example (.pdf)
- default – template (.tex) and example (.pdf)
- Rochester – template (.tex) and example (.pdf)
- 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 > $i-example.tex" ; done
> script.sh
for i in `cat list.txt` ; do echo "pdflatex $i-example.tex" ; done >
script-make.sh
tags: beamer, latex, pdf
posted in unifei by Tiago Maluta | 1 Comment
Some things that made me happy this week.
posted in ttmmhtw by Tiago Maluta | No Comments
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:
tags: python web
posted in blog by Tiago Maluta | No Comments
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.
posted in blog by Tiago Maluta | No Comments
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.
tags: latex, python
posted in linux by Tiago Maluta | No Comments
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.
tags: arm, gcc, python, x86
posted in embarcado by Tiago Maluta | No Comments