26
May 10

IA-32 (x86) Assembly in Linux

segment .data
hello: db ‘Hello, world!’,10
helloLen: equ $-hello

segment .text
global _start
_start:
; Write ‘Hello world!’ to the screen
mov eax, 4 ; ‘write’ system call
mov ebx, 1 ; file descriptor 1 = screen
mov ecx, hello ; string to write
mov edx, helloLen ; length of string to write
int 80h ; call the kernel

; Terminate program
mov eax, 1 ; ‘exit’ system call
mov ebx, 0 ; exit with error code 0, we want to exit without any errors.
int 80h ; call the kernel

To Compile:
nasm -f elf helloworld.asm
ld -s -o helloworld helloworld.o


01
Nov 09

uTorrent Tray Icon Windows 7 Style

I really like Windows 7. Here is something I’ve done really quick with Inkscape and Gimp, a new uTorrent tray icon in Windows 7 style.

Download


14
Jun 09

Minimal Arduino

It could be even less if I just used ATmega168′s internal 8MHz Oscillator but I wanted to be as compatible with the Arduino as possible. I want to be able to program the microcontroller using the Arduino IDE and I don’t want to use the actual Arduino to keep it alive or to have an Arduino to each project I make. More! With this setup we will have a really tiny footprint compared to the development board.

True Minimal Arduino/ATmega168

This is true minimal but can we still call it Arduino? We don’t even use the bootloader!

ATmega168 pin mapping

So what we need in our version:

AVR 28 Pin 20MHz 16K 6A/D – ATmega168 with Arduino Bootloader

Breadboard Mini Black (170 tie points)
+5V Fixed-Voltage Regulator 7805

10K Resistor (for Reset)

Electrolytic Decoupling Capacitor 100uF/16V Capacitor

2x Capacitor Ceramic 22pF
Crystal 16MHz

Here is a photo from a mood lamp I created with an RGB Led, just need to put it inside a Ikea Fado Lamp with a paper for difusion, power it and it’s done. ;)

Minimal Arduino (2nd Try) SUCCESS


23
Apr 09

Ubuntu Desktop Notification Server

With Ubuntu 9.04 (Jaunty Jackalope) just released today (23 Apr 2009) I could finally have some hands-on experience with it’s new notification server, Notify OSD.

Mark Shuttleworth had mention this in his blog some months ago (Dec 2008) with a nice mockup.

This means notifications are now centralized and they aren’t visually dull, they actually show up in a rounded rectangle on the top right corner of the screen with an awesome translucent visual appeal very similar to the «Smoke Notification» from Growl in OSX. If more than one alert is active at the same time, they stack up beneath each other. We can’t click them and they go away after a few seconds.

I don’t believe it is finished yet as it was said in the release about an application to control the what, where and when of this new notification system.

If you are a software developer, you should play with it and think of ideas (and share them too) to use Notify OSD and make your software compatible with it.

You can start by installing Freedesktop notifications library (libnotify-bin)

sudo apt-get install libnotify-bin

Then use notify-send to test it out

notify-send -i file:///usr/share/pixmaps/gnome-logo-white.svg "@joaoamaral" "Ubuntu 9.04 (Jaunty Jackalope) New Notification Server is AWESOME"

A simple bash shell script
#!/bin/bash -x
echo Please, enter your message
read MESSAGE
echo "Message sent: $MESSAGE"
notify-send -i file:///usr/share/pixmaps/gnome-logo-white.svg "joaoamaral says:" "$MESSAGE"

Also check the Notification Development Guidelines


23
Apr 09

LAMP Development Server

The acronym LAMP stands for Linux Apache MySQL PHP and refers to a solution of free and open source software used to run dynamic web sites or servers.

I was in need of a new development server that matched my production server that is already online and is hosting my clients websites and that has the most recent versions of the software (Apache version 2.2.11 (Unix), PHP version 5.2.6, MySQL version 5.0.67-community)

So in this particular server I’ll have:

  • Ubuntu Linux 9.04 (Jaunty Jackalope) that just came out as the operating system – I’m using wubi in Windows Vista tbh, it’s not really important;
  • Apache2 as the Web server;
  • MySQL, for the time being as the database management system or database server (PostgreSQL will replace it in the future as Oracle bought Sun)
  • PHP5 as the preferred scripting language

To install everything in Ubuntu I just launched the Terminal (I really enjoy using it).
First we are going to install apache2 meta package.

sudo apt-get install apache2

After that you’ll get a “It works!” page if you go to http://localhost actually that are the html contents of index.html file in /var/www/

To start/stop/restart apache2
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart

Next we’ll have php5 meta package installed

sudo apt-get install php5 libapache2-mod-php5

You may need to restart apache2 daemon so let’s just do it anyway as we are just in a development server, np.
sudo /etc/init.d/apache2 restart

Let’s test php5 installation.
sudo gedit /var/www/test.php &

The & is to run gedit in the background so we can still use the terminal.
To test it we gonna create a php file with the following code:

<?php echo "It works! apache2 + php5"; ?>

Save it. Now let’s run it in Firefox the following URL http://localhost/test.php

Finally MySQL
sudo apt-get install mysql-server php5-mysql mysql-client

You’ll be asked to set a root password for mysql root user.
When it finishes downloading and installing MySQL we need to link the extension mysql.so to php5 in order to make mysql run with it.

Edit php.ini
sudo gedit /etc/php5/apache2/php.ini

and add to it this line in Dynamic Extensions part just before Module Settings and restart apache2:

extensions=mysql.so

Let’s just try running it.

mysql -uroot -p

Enter the password you just defined for MySQL root. If you get a mysql> prompt it’s done.

A final test just to see all working. :) Let’s create a db.php file

sudo gedit /var/www/db.php

and type:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$connection = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql: '.mysql_error());
$dbname = 'mysql';
mysql_select_db($dbname)
or die('Error selecting database: '.mysql_error());
$result = mysql_query("select user, host, password from user")
or die('Error querying database: '.mysql_error());
?>

<table>
<tr><th>user</th><th>host</th><th>password</th></tr>

<?php while($row = mysql_fetch_array( $result )) { ?>

<tr><td><?=$row['user'] ?></td>
<td><?=$row['host'] ?></td>
<td><?=$row['password']?></td></tr>

<?php } ?>
</table>

Save it and run it in Firefox http://localhost/db.php
Don’t forget to the change password on line 4 in db.php

That’s it.

Some useful commands to test MySQL
mysql> quit
mysql> select version(), user(), now();
mysql> show databases;
mysql> use mysql;
mysql> show tables;
mysql> select user, host, password from user;


22
Apr 09

SMS Notification

Basically I wanted to add SMS Notification using Google Calendar SMS feature as an upgrade to joaoamaralbot.

First I created a new Google Calendar account for joaoamaralbot, then activated SMS notification with my mobile phone number. In Twitter I added gcal as friend and requested the authorization code to grant access to the Google Calendar account recently created. You can get it here. Now we can add any events by sending a direct message to gcal for example:

D gcal 13:00 Remember the Milk!

To send direct messages in Twitter to gcal using cURL

curl -u user:password -d "text=13:00 Remember the Milk!&user=gcal" http://twitter.com/direct_messages/new.xml


20
Apr 09

Twitter Bot

Created a new account in Twitter joaoamaralbot with all messaging that I think it is interesting to use instead of the email for hardware notificiations (router) or daemons/services status (webserver, mailserver, dbserver, security updates, bitorrent downloads, etc…).

To accomplish this I used cURL and the Twitter API.
Examples (username and password are to be replaced with your own) :

Basic tweet

curl --basic --user username:password --data status="hello, world!" http://twitter.com/statuses/update.xml

Using as a notificiation from uTorrent and sending a tweet to myself

curl --basic --user username:password --data status="@joaoamaral Finished Downloading %N" http://twitter.com/statuses/update.xml

If you are on Windows after downloading cURL with SSL and SSPI (recommended) you will also need OpenSSL.


20
Apr 09

Hello world!

Welcome to my blog, my little cocoon on the web. This is my first post. (^^)