Check mail from command line

I’m not using an email client to check my mail for quite some time mainly because I don’t like being interrupted while I’m in the middle of something. Since I’m developing from a command line (guake), for convenience, I would like to check my mail without changing context so I found this:

curl -u username --silent "" | perl -ne 'print "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/

You cand use username:password if you’re comfortable with storing your password in plain text.

I’ve placed the above command in a script file added executable rights (+x) to that and I’m using it like: gmail my_account to check for incoming new mail.

Since I’m using multiple accounts, I’ve modified the script file to include the “all” command which will check all my email accounts. Currently you’ll have to introduce your password for each account. I’ll change this in a future post so that you can “safely” store you passwords and have a master password for checking all your accounts.

Here’s the script for checking multiple gmail accounts by issuing the command: gmail all

Posted in Uncategorized | Tagged , | Leave a comment

Arduino twinkle, twinkle little star

I recently bought an arduino board and yesterday I took it out for a spin.

They have some thorough tutorials on their website here

I’ve used this tutorial to play some sounds with a piezo speaker and then I’ve changed a little bit the program to play my own baby. Since I don’t know which cord is which note (I suck reading guitar notes) I’ve used this tutorial to find what’s what.

This is what it came out .

And here is the complete source code:

 #include "pitches.h"
// notes in the melody:
int melody[] = {

    N_B4, N_B4, N_FS5, N_FS5, N_GS5, N_GS5, N_FS5
  , N_NONE
  , N_E5, N_E5, N_DS5, N_DS5, N_CS5, N_CS5, N_B4
  , N_NONE
  , N_FS5, N_FS5, N_E5, N_E5, N_DS5, N_DS5, N_CS5
  , N_NONE
  , N_FS5, N_FS5, N_E5, N_E5, N_DS5, N_DS5, N_DS5, N_DS5, N_CS5
  , N_NONE
  , N_B4, N_B4, N_FS5, N_FS5, N_GS5, N_GS5, N_FS5
  , N_NONE
  , N_E5, N_E5, N_DS5, N_DS5, N_CS5, N_CS5, N_B4
  , N_NONE

int noteDurations[] = {

void setup() {}

void playSong(){
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(int); thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. half note = 1000 / 2
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // stop the tone playing:

void loop() {
Posted in arduino | 7 Comments

Log4net configuration

I always forget how to configure log4net to enable it’s powerful logging capabilities. So here’s how:

For web applications: in your global.aspx file, when the application starts, add this line: XmlConfiguration.Configure();

For desktop applications add the same line in the main function.


protected void Application_Start()
In  web.config / app.config add this configuration:
Declare the section in the section configuration
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” />
Configure the logger for file logging:
<appender name=”LogFileAppender” type=”log4net.Appender.FileAppender”>
<param name=”File” value=”Logs\\Log4Net.log” />
<layout type=”log4net.Layout.PatternLayout”>
<param name=”ConversionPattern” value=”%d [%t] %-5p %c %m%n” />
<logger name=”File”>
<level value=”All” />
<appender-ref ref=”LogFileAppender” />
That’s it, hope this helps!
Posted in Uncategorized | 1 Comment

How to securely call amazon webservices from a client application

If you are going to use the amazon sdk in order to create calls to s3 or other amazon web service, you will notice that in order to upload files or create get requests you have to work with an object that requires your accessKeyID and secretAccessKeyID.

Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID)

The problem is that since this is a client application, you will have to give your password to client applications in order to create calls using the amazon sdk. However, this is not safe at all. Even if you encrypt your password it’s only a matter of time until some evil hacker decrypts it and you don’t want to pay for illegal stuff hosted in your bucket.

There are two solutions in order to avoid this:

1. Create a proxy that fronts the remote AWS service (however this is not recommended)

2. Create a signed request to your server, sending all the details needed so that you can generate the authentication string and then send back the authentication string to your client in order to complete the request header.

Here’s how it works

If you want to upload a file to amazon s3 this is how your request looks like:

PUT /my-image.jpg HTTP/1.1
Date: Wed, 12 Oct 2009 17:50:00 GMT
Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE=
Content-Type: text/plain
Content-Length: 11434
Expect: 100-continue
[11434 bytes of object data]

We can clearly notice the only thing that authenticates our request is the following line:

Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE=

Here is how the authorization string can be created:

Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;

Signature = Base64( HMAC-SHA1( UTF-8-Encoding-Of(
                                YourSecretAccessKeyID, StringToSign ) ) );

StringToSign = HTTP-Verb + "\n" +
	Content-MD5 + "\n" +
	Content-Type + "\n" +
	Date + "\n" +
	CanonicalizedAmzHeaders +

CanonicalizedResource = [ "/" + Bucket ] +
	<HTTP-Request-URI, from the protocol name up to the query string> +
	[ sub-resource, if present.
        For example "?acl", "?location", "?logging", or "?torrent"];

CanonicalizedAmzHeaders = <described below>

What this means is that we just have to send the details about the file we want to upload to our website, where we will calculate the authorization string, then, we can use the authorization string to complete the request from our client application.

Posted in Uncategorized | 2 Comments