Sunday, December 19, 2010

Static Maps Creator

Pamela Fox has published a static maps creator that encodes polylines from "My Maps":

http://imagine-it.org/google/staticmap/encodemymap.php

And I improved it:

http://static-maps-generator.appspot.com/

There is this interactive maps creator (API v1)

http://www.solvium.de/static-map/

But the one below also supports polylines (API v2)

http://gmaps-samples.googlecode.com/svn/trunk/simplewizard/makestaticmap.html

Monday, November 1, 2010

Sunday, October 31, 2010

How to publish a private method at runtime?

Here's how:

    class AClass
    {
        void Private()
        {
        }

        public Action Publish()
        {
            return Private;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var anInstance = new AClass();
            var publishedInstance = anInstance.Publish();
            publishedInstance();
        }
    }

Saturday, June 19, 2010

How to play raw PCM audio data in .NET using C#?

There is a Windows API for that. You can use the .NET Wrapper in RageLib. RageLib can be found in http://code.google.com/p/gtaivtools/source/browse/#svn/trunk/RageLib

class Program
{
    static byte[] _queue = new byte[0];
    static void Filler(IntPtr data, int size)
    {
        var length = Math.Min(size, _queue.Length);
        Marshal.Copy(_queue, 0, data, length);
        _queue = _queue.Skip(size).ToArray();
    }
    static void Main(string[] args)
    {
        var encoded = args[0];
        var decoded = Convert.FromBase64String(encoded);
        var samplingFrequency = 8000;
        var bits = 8;
        var channels = 1;
        var bufferSize = 256;
        var waveFormat = new WaveFormat(samplingFrequency, bits, channels);
        using (var waveOutPlayer = new WaveOutPlayer(-1, waveFormat, bufferSize, 1, Filler))
            while (_queue.Length > 0)
            {
            }
    }
}

How to play raw PCM audio data in Matlab?

function record()
    Fs = 8000;
    nBits = 16;
    nChannels = 1;
    recorder = audiorecorder(Fs, nBits, nChannels);
    disp('Start speaking for 2 seconds');
    recordblocking(recorder, 2);
    disp('End of Recording.');
    audiodata = getaudiodata(recorder, 'uint8');
    player = audioplayer(audiodata, Fs);
    playblocking(player);

Sunday, June 6, 2010

How to prevent Serial-to-USB devices from messing with your mouse on Windows

Since I am using one of my USB ports to receive RS232 data, it began to scramble my mouse pointer. It move randomly across the screen. It happens because Windows recognizes it as a serial mouse.

The solution for this is simple. Your USB device will be listed twice in the Windows Device Manager. All you have to do is disable the mouse entry.

Friday, June 4, 2010

Examples of Memcached telnet commands

I was looking for a example of a memcached telnet session, here is what I created. It shows the behavior of the set, get, add, gets, cas and replace commands.

I introduced the '>' sign before each input line to differentiate it from the output.

>add mykey 0 60 11
>hello world
STORED

>get mykey
hello world
END

>add mykey 0 60 11
>hello world
NOT_STORED

>replace mykey 0 60 7
>hello w
STORED

>get mykey
hello w
STORED

>replace newkey 0 60 7
>hello w
NOT_STORED

>get newkey
END

>set mykey 0 60 5
>hello
STORED

>set newkey 0 60 5
>hello
STORED

>gets newkey
VALUE newkey 0 5 999999
hello
END

>cas newkey 0 60 4 111111
>hola
EXISTS

>cas newkey 0 60 4 999999
>hola
STORED

Tuesday, June 1, 2010

How to send Memcached stats to a monitoring tool using bash?

Zabbix is my network monitoring tool of choice. You can send Memcached stats to it using the simple code bash script below:


#!/bin/bash
ZABBIX_SENDER="/usr/local/sbin/zabbix_sender"
ZABBIX_TRAPPER="localhost"
ZABBIX_TRAPPER_PORT=10051
ZABBIX_ITEM_KEY_PREFIX="memcached_"
ZABBIX_HOST="Memcached"
MEMCACHED_SERVER="localhost"
MEMCACHED_SERVER_PORT=11211
STATS=`(sleep 1 ; echo "stats"; sleep 1; echo "quit") | telnet $MEMCACHED_SERVER $MEMCACHED_SERVER_PORT`
STAT //' | sed -e 's/ /:/g' | sed -e 's/:STAT:/\n/g')
do
OLD_IFS="$IFS"
IFS=":"
KEY_VALUE=($i)
IFS="$OLD_IFS"
ITEM_KEY=$ZABBIX_ITEM_KEY_PREFIX${KEY_VALUE[0]}
echo $ITEM_KEY:${KEY_VALUE[1]}
$ZABBIX_SENDER --zabbix-server $ZABBIX_TRAPPER --port $ZABBIX_TRAPPER_PORT --host $ZABBIX_HOST --key $ITEM_KEY --value ${KEY_VALUE[1]}
done

Save it to a file and schedule it with CronD. You will also have to add the Memcached template to all your memcached hosts.

Never uninstall the Team Foundation Server component that comes with Visual Studio 2010

This component is essential to open solutions that were originally binded to a TFS server (ie. Codeplex projects)

Tuesday, May 18, 2010

OneWay OperationContract in WCF implications

OneWay OperationContract in WCF implications causes WebHttpBinding to answer HTTP 202, instead of HTTP 200

Friday, May 14, 2010

How to discover the RGB code for a color on the screen

If you use Google Chrome you should check out this Eye Dropper extension.

Monday, May 10, 2010

Common acronyms in internet forums, or WTF is IIRC?

The more polite initialisms:

OP = original poster
AFAIK = as far as I know
IIRC = if I remember correctly
IMHO = in my humble opnion
RSVP = Répondez s'il vous plaît (answer if it pleases you)

The others:

LMGTFY = let me google that for you
RTFM = read the fucking manual
WTF = what the fuck
LOL = laughing out loud
ROTFLOL = rolling on the floor laughing out loud

In instant messaging and chat rooms:

BRB = I'll be right back
G2G = I got to go

Wednesday, May 5, 2010

What is the best Javascript LINQ implementation?

When you search for "javascript linq" you'll see:
  • linq.js
  • jslinq
  • jsinq
  • jlinq
  • and many others....
I all have to say is that jslinq don't have GroupBy, Except and many other methods. While linq.js does.

Monday, April 5, 2010

5 ways of optimizing WCF performance

Try to use the following options
  •  transferMode : streamed
  • oneWay
  • unordered
  • asynchronous
  • netTcpBinding or netMsmqBinding

Saturday, February 20, 2010

One reason why we can't trust online password storage

LastPass.com, Passpack.com and many other sites claim that they can store your sensitive data, like credit card numbers and passwords, in an encrypted form, so they don't have access to it. While the services they offer really save you from a lot of work (password memorization and typing) there is a fundamental flaw.

The problem is that most of the code that decrypts your sensitive data can be updated in few seconds without sending warnings to you. If someone compromises the host, he can modify the code they serve to send the key or the decrypted data back to him, and he can update the code again to behave normally whenever he wants.

To retrieve and decrypt my passwords, I would trust only a tool that:

1. Is open source
and
2. Isn't updated automatically

Sunday, January 17, 2010

Did you know that you are helping to save the planet?

We developers are changing the world, as shown in this IBM presentation:

http://www-03.ibm.com/innovation/us/thesmartercity/index.shtml

Introducing Google Chrome Frame, the solution for Internet Explorer