This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users.
Download:
WhoAmI.tar.bz2 – Eclipse project. It’s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions.
WhoAmI.apk – Application installation Android [...]
27 February, 2010 - 9:39 pm
Tags: caps lock, Java, programming, socket, upcase
Posted in english | No comments
Here is a simple server for those who are starting studying sockets or just needs a simple socket server example for reuse while writing your own behavior.
Features:
A client should enter a string and the server would answer the same string, with each symbol in up case, when possible.
Default port at 8080.
One client at time.
No multi [...]
22 February, 2010 - 5:16 pm
Tags: development, i18n, Java, JUnit, locale, programming, String, teste unitário, toString, unit testing
Posted in english | No comments
Today I was programming a toString method for a class widely used in a application, using the very useful String.format that provides a C’s like printf formatter.
@Override
public String toString() {
return String.format("VO[a: %.1f, b: %.1f, c: %.1f]", a, b, a+b);
}
%.1f means a float with one digit precision after the dot separator. The code [...]
Quantos zeros tem entre um e mil?
É mais fácil responder perguntas desse tipo escrevendo pequenos programas usando o suporte a programação funcional e compreensão de lista que algumas linguagens como Python oferecem.
Para contar os zeros de um número, transformamos ele em uma string e contamos quantas substrings ‘0′ ele contém. Por exemplo o 800:
str(800).count(’0′)
# 2
Para [...]
O pre-requisito é o notify-send, um utilitário de linha de comando do libnotify. No Ubuntu:
sudo aptitude install libnotify-bin
E aqui o script em si:
sleep 5m; notify-send “aviso” “tirar o miojo do fogo”
Pronto, depois de cinco minutos isso vai aparecer:
20 January, 2010 - 10:55 pm
Tags: date, datetime, ISO 8601, Jochen Voss, Markus Kuhn, programming, Python, representation, sort, sorting, time
Posted in english | No comments
I was looking for a date and time representation useful for registering stock quotes in a simple plain file.
I found that the standard ISO 8601 is just the answer for this, it’s called “Data elements and interchange formats — Information interchange — Representation of dates and times”. Here is a example:
2010-01-20 22:14:38
There’s this good article from [...]
5 January, 2010 - 6:10 pm
Tags: AWT, fonts, Java, JVM, Larabie, Larabie Fonts, programming
Posted in english | Comments Off
Here’s a program that lists fonts available in your JVM. You can also set the environment variable JAVA_FONTS to specify the font directory.
import java.awt.GraphicsEnvironment;
public class ListFonts {
public static void main(String args[]){
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
for(String font:e.getAvailableFontFamilyNames()){
System.out.println(font);
}
}
}
By using pipes you can count how many fonts you have:
java ListFonts|wc -l
On my Ubuntu machine here I got 556 because [...]
25 December, 2009 - 3:04 pm
Tags: dtd, expat, game, programming, pygame, Python, sax, schema, urllib, XML
Posted in english | 1 comment
Here is a useful tip on Python XML decoding.
I was extending xml.sax.ContentHandler class in a example to decode maps for a Pygame application when my connection went down and I noticed that the program stop working raising a exception regarded a call to urlib (a module for retrieve resources by url). I noticed that the [...]
19 December, 2009 - 7:15 am
Tags: C, Java, Python, Qt, Tiled
Posted in english | 2 comments
I’m using the Tiled Map Editor for a while, I even wrote that tutorial about it. It’s a general purpose tile map editor, written in Java but now migrating to C++ with Qt, that can be easily used with my set of free pixelart tiles.
A map done with Tiled is stored in a file with [...]
11 December, 2009 - 7:47 am
Tags: game, orc, Pixelart, programming, pygame, Python
Posted in english | No comments
Here is a Pygame Sprite animation using the approach presented by Joe Wreschnig and Nicolas Crovatti. It’s not yet exactly what I need but is very suitable.
import pygame, random
from pygame.locals import *
class Char(pygame.sprite.Sprite):
x,y = (100,0)
def __init__(self, img, frames=1, modes=1, w=32, h=32, fps=3):
pygame.sprite.Sprite.__init__(self)
original_width, original_height = img.get_size()
self._w = w
self._h = h
self._framelist = []
for i in xrange(int(original_width/w)):
self._framelist.append(img.subsurface((i*w,0,w,h)))
self.image = [...]
24 March, 2008 - 1:06 am
thank you, man