Archive for the ‘howto’ Category

Using a spare router as an access point for increased wireless range

September 27th, 2013 Comments off

Just moved to a new home, with a layout that makes wireless signals a bit difficult to catch reliably in the far corners of the apartment. To solve that I wired both ends of the apartment with CAT5e and had an extra access point placed at the far end, to complement the main modem+router combo from the phone company. For the function, I took an extra router I had and tweaked its configuration.
The setup is actually rather simple:

Main modem+router
primary access point
Spare router
secondary access point
Fixed LAN IP: Fixed LAN IP:
DHCP Range: DHCP: disabled
Wireless channel: 1 Wireless channel: 13

The important things to keep in mind are just a few:

  • You want the secondary router to act just as an access point, so *disable DHCP*. It is very important that you have only one device handing out IP addresses on your network
  • Connect both the main router and the access point with a run of CAT5. Connect both using their LAN ports, as you don’t want any routing to happen in the secondary device
  • Use fixed IP addresses for both devices, I used and, but it’s just a suggestion
  • Remember to leave some room in your DHCP configuration (in the primary router) for configuring some fixed IPs. In the default LAN configuration for home devices you have 254 valid addresses, so leave the first 10 or 20 reserved for fixed allocation.
  • To make your life easier, configure one device at a time, and have the other turned off while doing so. Helps avoid conflicts if the default configurations on both overlap (example: same default IP address)
  • Finally, use the exact same Wireless parameters (SSID, security, password) in both devices, and make sure you let them pick the channel automatically, or else pick manually two channels that are far appart

This idea of re-using a router as a dumb access point is not new; I first saw it written here:

Categories: howto Tags: , , ,

Preventing spam via a blacklist

December 13th, 2012 2 comments

This one came from the excellent Jefferson Ryan: Como vetar / deletar automaticamente spam no wordpress (in Portuguese), and was later extended by Luciano Sturaro to use regular expressions for the word matching.

I’m repeating the gist of it here so that I can remember it in case I switch themes in the future and lose customizations made :-)

Basically, Jefferson is proposing a hard-line approach to spam filtering, by passing comments through a blacklist of forbidden words before accepting them. This makes for a much leaner list of pending comments to be analysed later, and it also has the added benefit of letting the users know immediately if something is wrong with their comments.

To put the blacklist in place in wordpress, just edit “functions.php” in your theme and add the following: (all credits go to Jefferson and Luciano, I’m only re-posting it here for reference)

//Acrescente isso no final de functions.php (é um arquivo do tema, não do wordpress)
//pode ser imediatamente antes da linha final com um " ? > ".
function in_comment_post_like($string, $array) {
      foreach ( $array as $key => $value ) {
          if (preg_match("/\b".$value."\b/i", $string)) { return true; }
      return false;
function drop_bad_comments() {
    if (!empty($_POST['comment'])) {
        $post_comment_content = $_POST['comment'];
        $lower_case_comment = strtolower($_POST['comment']);
        // Lista de palavras banidas.
        // Comentários com essas palavras serão automaticamente deletados
        // e quem postou, se não for um bot, verá um alerta.
        // Mas caso seja um bot, receberá o erro http 503.
        // Coloque somente palavras na lista, não coloque símbolos como: [ { ( *
        $bad_comment_content = array(
            'no prescription',
            'without a prescription',
            'sex pics',
            'family incest',
            'online casinos',
            'online dating',
            'rocket attacks',
            'blue spoon'
        if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {
            wp_die( __('<b>Seu comentário contém palavras ou expressões banidas.</b><br><br><i>'.$post_comment_content.'</i>'),('Erro'),array( 'response' => 503, 'back_link' => true ) );
add_action('init', 'drop_bad_comments');

Any downside? Yes indeed, thanks for asking. If your comment is rejected, hitting “back” on the browser will get you to an empty comments page, so you essentially lose all your carefully worded thoughts. This is unfortunate and I’ll have to see about preventing it, but for now I’ll just have to deal with the hate mail.

Also, be careful editing functions.php; if you mess-up the syntax you can render your blog (site and admin) completely inaccessible, and you’ll have to restore a backup or login via ssh and fix the mistake.

Edit Dec/14th: Updated the script to use regular expressions, pasting the version from Luciano Sturaro.

Categories: howto Tags:

A watchdog to restart Transmission periodically

July 14th, 2012 Comments off

NS-K330 NAS from DealExtreme, which become especially useful when paired with the SnakeOS custom firmware built by Douglas Gazineu and collaborators. I use this device (with SnakeOS) for sharing an USB laser printer over the network, exposing SMB shares from a large USB drive and downloading torrents unattended using the Transmission client.

NS-K330 NAS from DealExtreme

And the Transmission bit torrent client is the reason for this post: I’m using the version bundled with the release 1.2.0 of SnakeOS, and it works great, however the daemon sometimes stops working, especially under heavy load. SnakeOS version 1.3.2 has a handy “watchdog” feature to restart Transmission if it stops unexpectedly, but the version of Transmission bundled with that release plays havoc with my home router, bringing my local network to its knees.

So, since I’m otherwise very happy with 1.2.0, I just implemented a simple watchdog script as a cron job to keep an eye on Transmission and restart it if stopped. It is actually quite simple, but let me spell out the steps for anyone with little experience on Linux systems:

1) To be able to perform these modifications, you need to enable SSH on the NAS, and login with your admin password.

2) To connect to the NAS, use an SSH client, such as Putty. Just remember to login as root, using the password that you had set for your admin user on the web interface.

3) This is the watchdog script, which I saved as /etc/watchdog in the NAS filesystem:

pgrep -f transmission-daemon &> /dev/null
if [ $? -eq 0 ]
  echo "transmission is running"
  echo "transmission is not running"
  /etc/init.d/transmission restart

To create the script, cd into the /etc folder and use vi to create the file. If you’re not familiar, just follow exactly the steps below:

  • Type: “cd /etc” [ENTER]
  • Type: “vi” [ENTER]
  • Type “i” to enter the INSERT mode on VI
  • Type or paste the code for the script, exactly as shown above
  • Press [ESC] to exit the INSERT mode
  • Type “:wq” to save (the “w”) and quit VI (the “q”)
  • Now you should be back to the prompt
  • Type “cat” and confirm that the script is correct
  • To make the script executable, type “chmod a+x watchdog” [ENTER]

4) In order to confirm that the script is indeed working, manually start it from the prompt, by typing “./” [ENTER]:

# ./watchdog
transmission is running

If Transmission was already running, you should see a message like the one above. If it wasn’t, it should now have been restarted, and running the script again should confirm that.

5) As the final step, we want to make this script run periodically on the NAS. For that we’ll rely on the CRON daemon, by adding a few likes to its configuration. Type or paste the following on the prompt:

echo "0 * * * * /etc/watchdog" >> /etc/cron.d/root
echo "15 * * * * /etc/watchdog" >> /etc/cron.d/root
echo "30 * * * * /etc/watchdog" >> /etc/cron.d/root
echo "45 * * * * /etc/watchdog" >> /etc/cron.d/root

After that, confirm the lines have been inserted by taking a look at the contents of the cron file. The lines we just entered will make the job run once every 15min, which should be good enough.

# cat /etc/cron.d/root
10 * * * * /usr/share/snake/setntp
0 * * * * /etc/watchdog
15 * * * * /etc/watchdog
30 * * * * /etc/watchdog
45 * * * * /etc/watchdog

6) One thing to remember is that you must always persist your changes to the configuration, or else in the next reboot of the NAS they will vanish. To save the config and restart the cron daemon, use the following commands:

/usr/share/snake/config save
/etc/init.d/cron restart

And that’s all. Happy downloading! :-)

Categories: howto Tags: , , ,

Checking dropbox for synchronization conflicts

April 11th, 2012 Comments off


So it turns out Dropbox, while extremely useful, is not the smartest cookie when it comes to handling synchronization conflicts. If you have a file changed in two different computers before synchronization kicks in (it might happen if you’re offline, for instance), you will a copy of the file containing the words “conflicted copy” plus the name of the device where it originated from and the date.

This approach is mostly fine, but my gripe is that it is a bit too stealth. If you don’t actively look at your files, you might miss the conflict and some data might get lost or forgotten in the process. With subfolders within your dropbox and a large amount of files, that can be a real possibility – it has happened to me on occasions.

But worry not, there’s an easy way out: with a simple command you can recursively check all folders within your dropbox for synchronization mishaps, and decide what to do with any conflicting files. In order to do that, we’ll rely on the fact that the conflicted files have the words “conflicted copy” on their names, and search for it – incidentally, if you name any legitimate files with these words, you’re on your own buddy :-)

In its simplest form, all it takes to find conflicts is to run a ‘dir *conflicted* /s /b’ in the root of your dropbox. The stars (*) surrounding the word means “with any prefix or suffix”, the ‘/s’ tells dir to search subfolders, and the ‘/b’ specifies the bare output format (just filenames, one per line, with file path). All it takes is placing a file called “check_conflicts.bat” at the root of your dropbox folder, with the following contents:

@dir *conflicted* /s/b

But because ‘dir’ will return set an ERRORLEVEL greater than zero, we can use this information to present a nicer message than the default “file not found” which would be the output from ‘dir’ in case of no conflicts. To do that, we first need to redirect the output of the ‘dir’ command (both the standard output and the error output) to ‘nul’. Then, we check the ERRORLEVEL for an indication of conflicts; in case of none, we present a nice “fell-good” message, and in case of conflicts, we re-run the ‘dir’ this time showing the conflicting files. The final version of “check_conflicts.bat” looks like this:

@echo off
echo Looking for synchronization conflicts ...
dir *conflicted* /s/b > nul 2>&1
if errorlevel 1 goto NOTFOUND
goto FOUND

rem -------------------------------------------------
echo No conflicts found ...
goto EOF:

rem -------------------------------------------------
echo ********** Found the following conflicts: ********** 
dir *conflicted* /s/b
goto EOF:

rem -------------------------------------------------

In the first ‘dir’ above, the ‘> nul’ redirects the standard output from the command to the ‘nul’ device, ignoring it; then the ‘2>&1′ redirects the stderr output (where the ‘file not found’ message would go by default) to the stdout, which we already redirected to ‘nul’, and as such, stderr is also suppressed. So, the sequence ‘> nul 2>&1′ can be understood as forcing both stdout and stderr to be suppressed. With the command now silenced, we just need to check the ERRORLEVEL to see if any file matched the pattern, and if so, re-run the command, this time leaving its output go to the console window.

Instructions: just paste the contents above in a text file named “check_conflicts.bat” and place it at the root of your dropbox folder. Then run it from time to time or, for added convenience, schedule a task to run it periodically for you (instructions for task scheduling can be seen at the end of this post). If you do schedule it for a periodic run, remove the ‘pause’ command on the NOTFOUND branch, so that you don’t get bothered by periodic remarks about no conflicting files being found …

Categories: howto Tags: ,

Building a multimeter from scratch

July 3rd, 2011 Comments off

Well, not really "from scratch; as a very wise man once said, "if you want to make an apple pie from scratch, you must first create the universe". Since that’s way beyond my budget, I’ll make copious use of scrap materials :-)

Turns out that my nephew had to build a multimeter for his high-school electronics class. What he needed was a measurement instrument for voltage, current and resistance, with at least a few different ranges in each mode, all using a single galvanometer. It’s now more than 20 years since I was taking electronic classes myself, but I guess I still remember enough of the basics to be able to help him out. Here’s what we did and how:

The basic building blocks

I decided to left the ohm meter (resistance) out of the equation at first, so we set out to build voltage and current meters. We had a galvanometer with an end-of-scale current of 0.5mA and a DC coil resistance of 635 ohm. For the voltage meter, we’d put the galvanometer in series with a shunt resistor, making a voltage divider; for the current meter, we’d make a current divider, by putting the galvanometer in parallel with a shunt resistor. And with a couple of switches we’d switch instruments. The following diagram illustrates this line of thought:


The galvanometer

The layout proposed above dictated that we needed an instrument with a low internal resistance and we’d measure current. The only thing I found in my junk parts box was a tuning indicator salvaged from an old FM receiver. Some quick experimentation shown that it had a coil resistance of 635 ohm and that it needed exactly 0.5mA to deflect the needle to the end of the scale. And it had a nice 0,1,2,3,4,5 scale printed on its face. Perfect!


Calculating the shunt resistor for the voltmeter

For each desired measurement range, a different value of the shunt resistance R must me used. To calculate the value of R, we start from what we know about the circuit: since this is a series circuit, the current I through the galvanometer is the same as the one through the shunt R. Also, being a voltage divider, the voltage in the input probes is equal to the sum of the voltage drop in the galvanometer and that in the shunt R. Since we know that the galvanometer has a resistance of 635 ohm, and the current to deflect its needle to the end of the scale is 0.5mA; from that we calculate that the voltage drop over the galvanometer at the end of the scale is Vg = Ig x Rg, or 0.3175v; knowing that we can derive an expression for the value of the shunt resistor R for different ranges of the input voltage V. This is shown in the diagram below:


Calculating the shunt resistor for the ammeter

For the current meter, the calculation is similar, but this time we have a current divider, and we’re trying to measure the input current I. Because the galvanometer and shunt are in parallel, the voltage drop is the same on each of them, and we already know that at the end of scale, the voltage drop across the galvanometer is 0.3175v; being a current divider, the sum of the current across the galvanometer and the current across the shunt resistance is equal to the input current I. Having established those, we can isolate the shunt resistance R in terms of the end-of-scale input current I, as described below:


Putting it all together

We’ve calculated three different ranges for each mode (voltage and current), each conveniently enough in the form of 5×10^n, because our meter already has a 0-5 scale printed on its face. To switch between the voltage and current mode, we use two simple switches (see first diagram). To select the range on each mode, we connect the shunt resistances to a dip switch. And, in order to allow precise (more or less) calibration, each shunt will have a trimpot (adjustable resistor) in series with zero or more resistors, so as to achieve the correct calculated value.

The final Frankenstein – built in a hurry during a rainy afternoon, with a limited supply of parts to chose from – ended-up looking like this:

I’m not exactly proud of its looks, bur it worked beautifully and we had fun doing the calculations and building it, so I guess that’s the important part. The implemented piece is not going to stick around anyway.

Categories: howto Tags:

Desktop Background Slideshow in Windows Home Basic, with Powershell

March 29th, 2011 9 comments

I’m using Windows 7 Home Basic in my home computer, since this was the version that came bundled with the hardware. For the most part I don’t miss what the higher SKUs have to offer, although every now and then I’ll stumble at something missing and wish it was available. This is the case with the “desktop background slideshow”.

The desktop background slideshow

This is an interesting feature (available in all SKUs *above* Home Basic) which allows you to select a group of photos and have the desktop background change on an interval (say every 15m) to a new image. Quite interesting when you have a folder full of very nice images. But alas, Home Premium only allows you to point at a single image, no slideshow goodness for you.

Desktop background slideshow feature in Microsoft Windows

One thing I don’t like about the implementation of the feature in Windows is that you have to select which images will be part of the whole slideshow, you doesn’t just point to a folder and forget. The consequence of this design decision is that if later you add new images to that folder they won’t immediately become part of the slideshow, you’ll have to come back to this dialog and add them in. Not ideal …

Hacking a slideshow on a budget

Changing the desktop background is not a very difficult proposition. There’s an API call which can do just that: SystemParametersInfo, in user32.dll (using the SPI_SETDESKWALLPAPER action parameter).

In earlier versions of Windows you were limited to BMPs for background, so even if the UI gave you de appearance of accepting any image file, behind the scenes a conversion would take place and what would get stored in the registry was the path to the converted image. In Windows 7 things are easier, you just set the desktop background to any image you’d like the OS takes care of the details.

A note about Windows XP

If you search the interwebs for scripted methods for changing the desktop background, you’ll come upon several references suggesting that you write to the registry key HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper and then make a call to UpdatePerUserSystemParameters method on user32.dll, in order to let the OS know of the changed setting. Well, this method don’t work reliably on Windows 7 any longer: the registry key still controls the user’s desktop background, but the call to UpdatePerUserSystemParameters no longer reliably updates the active session (once the user logs out and in again, things will be updated though). Bottom line, the correct (supported) method to update the desktop background and many other system parameters is through a call into SystemParametersInfo.

Putting it all together with Powershell

In order to accomplish a slideshow, we need to script the following sequence of opperations:

  1. List the images within a given folder
  2. Select one of the images at random
  3. SystemParametersInfo giving it the full path to the image

Any scripting language which would let you accomplish all of the above would do, but for the sake of this implementation I’ll use Microsoft’s Powershell, which comes pre-installed in Windows 7 (all SKUs, Home Basic included!). Powershell is a very nice scripting language overall, and it makes performing the steps above a real breeze:

Listing images within a given folder

$folder = "c:\Users\Public\Pictures\Wallpaper"
Get-ChildItem $folder

And the results of the above would look something like this:

    Diretório: C:\Users\Public\Pictures\Wallpaper
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        10/03/2011     14:45     522419 01178_chicagoatnight_1680x1050.jpg
-a---        10/03/2011     14:51     293592 01301_rubik_1680x1050.jpg
-a---        10/03/2011     14:58     390960 01338_crazysun_1680x1050.jpg
-a---        10/03/2011     14:45     556026 01356_crepuscule_1680x1050.jpg
-a---        10/03/2011     14:36     948187 01542_thebirthofeuropa_1680x1050.jpg
-a---        10/03/2011     14:57     687594 01603_droplets_1680x1050.jpg
-a---        10/03/2011     14:57     609453 01637_rb_1680x1050.jpg
-a---        10/03/2011     14:38     699733 01645_bergs_1680x1050.jpg
-a---        10/03/2011     14:51    1176550 01663_lakelouise_1680x1050.jpg
-a---        10/03/2011     14:59    1201259 01700_fallisintheair_1680x1050.jpg
-a---        10/03/2011     14:45     791767 01705_sunsetinfrontofme_1680x1050.jpg
-a---        10/03/2011     14:48    1124629 01729_monumentalsimplicity_1680x1050.jpg
-a---        10/03/2011     14:51     710181 01737_elemental_1680x1050.jpg

One of the nice things about Powershell, and which sets it apart from most other shell environments, is that although the output above appears as just a bunch of text, it is actually a collection of files, for which the default representation happens to be the listing above (technically, it is a System.IO.DirectoryInfo object, which has information about the directory itself, along with its contents). The significance of this is that instead of having to manipulate text in order to work with this result, I can just pass it along to other methods which work on collections of stuff and not have to worry at all about formatting. For the next step:

Selecting a single image, at random

Easier than taking candy from a kid: there’s a commandlet (a command, in Powershell parlance) which selects a random element from any list (any iterable collection), conveniently named Get-Random. Since the results of our directory listing are iterable, we can just pipe them through Get-Random:

Get-ChildItem $folder | Get-Random

And the result would be something like this:

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        10/03/2011     14:51    1176550 01663_lakelouise_1680x1050.jpg

The resulting text output resembles that of the directory listing, but with only one entry. However, because we’re now referencing a single item in the listing, the object type for the result is System.IO.FileInfo – if the listing included sub-directories and one of them was selected at random, we’d have a result of type System.IO.DirectoryInfo here.

Calling the Win32 API to set the desktop background

Here’s where we hit a bit of a snag: PowerShell, as awesome as it is, don’t have an easy way to call into a native API. To solve this problem we could compile a managed or native executable to serve as a call proxy, and invoke this program from the script; but this would make for a solution which is not self-contained, and I’d rather have everything required in the script file itself, no extra dependencies.

And there is a way: we get some help from the Add-Type cmdlet, which allows you to compile code inline and build new types at runtime. All we need is a suitable piece of C# code for PInvoking the user32 method; with a little help from, we get the following definition:

public static extern uint SystemParametersInfo(
    uint uiAction,
    uint uiParam,
    string pvParam,
    uint fWinIni);

Using Add-Type to compile and then invoke this method is very straight forward:

$type = Add-Type -MemberDefinition $signature `
    -Name Win32Utils -Namespace SystemParametersInfo `
$null = $type::SystemParametersInfo(20, 0, $fileName, 3)

Putting it all together in a single script

To conclude this part of the exercise, lets combine all steps above in a very long and complex script which will select a random image from a given folder and set it as the new desktop background:

$folder = "c:\Users\Public\Pictures\Wallpaper"
$file = Get-ChildItem $folder | Get-Random
$signature = @'
public static extern uint SystemParametersInfo(
    uint uiAction,
    uint uiParam,
    string pvParam,
    uint fWinIni);
$type = Add-Type -MemberDefinition $signature `
    -Name Win32Utils -Namespace SystemParametersInfo `
$null = $type::SystemParametersInfo(20, 0, $file.FullName, 3)
"Wall paper is now set to $($file.FullName)"

Save this script in a text file with the extension “ps1” and you’re ready to execute it at will. Well, almost, as we’ll see:

Executing the script outside of the Powershell prompt

Once you have the script saved, you can execute it from any prompt as follows:

powershell path-to-your-script\name.ps1

But chances are you’ll get an error like this:

O arquivo C:\Users\Public\Util\Shuffle_desktop_background.ps1 não pode ser carregado. O arquivo C:\Users
\Public\Util\Shuffle_desktop_background.ps1 não está digitalmente assinado. O script não será executado
no sistema. Consulte "get-help about_signing" para obter mais detalhes..
Em linha:1 caractere:31
+ Shuffle_desktop_background.ps1 &lt;&lt;&lt;&lt;
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

What just happened is that Powershell comes out of the box with a policy in place which onl allows for signed scripts to be executed. This is fine for most users, which will not fiddle with creating scripts of their own, but a bit too harsh for most power users. You can check your current execution policy by invoking the cmdlet Get-ExecutionPolicy, which should display AllSigned as its result.

To modify the policy you must open a Powershell prompt as administrator, then type the following command:

Set-ExecutionPolicy RemoteSigned

This call configures the system to require signatures in all non-local scripts, but allow the execution of unsigned local scripts. After this change, try re-running the image script and see what happens it should succeed this time.

Turning this one-time change into a proper slideshow

Task-SchedulerNow that we have the script, all we have to do in order to get a new desktop background every 15min is to remember to open the command line and execute this script once every 15min; pretty easy, uh? Well, if you’re anything like me, you’re lazy and want to assign this task to someone else; that someone else being your computer. Windows has a handy task scheduler built-in which is used for all kinds of pre-programmed tasks. You can create a task and have its action be the script call (powershell path-to-script). For the action trigger, either have it run every few minutes/hours, or at every logon, if you only want to change the background once every time you log onto the machine.

Getting rid of the Powershell Command Window Pop-up

As commenter Vikram pointed out (thanks!), when you invoke the Powershell interpreter to run the script, you get the Powershell command window to briefly show-up on your desktop. If you set an aggressive schedule for your task, like every 5min, this gets really annoying. Although the Powershell executable accepts a “-WindowStyle Hidden” parameter, the window will still flash briefly, before PS decides to hide it. Not good.

The best way that I’ve found to work around this issue is to have an intermediate program act as a Powershell host with no window, and use that to launch the script. This was suggested by Scott Weinstein in his post entitled Scheduling PowerShell tasks without a console window.

To implement his suggestion, in your Task Scheduler action, instead of calling Powershell.exe to run the script, you call the PoshExec.exe host you created following Scott’s instructions. And just in case you have any trouble creating the EXE from the source code, I’m leaving here a compiled version of the World’s Smallest Powershell Host Application that you can download (executable, source-code, MD5 hash).

To summarize, your action in TaskScheduler will look something like this:

  • Action: Start a program
  • Program/Script: c:\Path-to-program\PoshExec.exe
  • Arguments: c:\Path-to-script\YourScript.ps1
Categories: howto Tags: ,

How much it costs to operate your home appliances?

August 10th, 2010 Comments off

Winter on the southern hemisphere has brought some very cold days upon us, and with them the pressure to turn on (or up) the heating. As it is common in most residences in this neck of the woods, mine does not have central heating and cooling, relying on A/C units to do the job on select rooms.

PMM2010 power consumption meter

But, electric heating does not come cheap, so I was left wondering how much does it cost me to run the A/C …

Well, I’m wondering no more! Enter the PMM2010, which can be seen as “generic” alternative to the better-known Kill-a-watt.

This device measures the instantaneous power consumption of devices connected to it, as well as measuring accumulated consumption for the last hour, day, month and since the last reset – and these accumulated logs are what is useful to evaluate things like A/C units, which turn on-and-off several times when operating.

Now, let’s look at some results

The A/C unit being evaluated is an LG 12,000 BTU air conditioner in “split” configuration, with reverse cycle (heating), which is the mode being measured here. In the heating cycle, it draws 2,000W of electric power when actively heating, and about 6W otherwise – differently from the cooling cycle, the fans only work when the unit is actually putting out heat; in the cooling cycle the fans always work, but the compressor is switched on/off at intervals.

I’ve tested the unit on four different nights, with outside temperatures which ranged from 8oC to 12oC, and having set the temperature control on the unit always at 18oC. The time of operation was not strictly the same on all runs, but was approximately 9h on each tests, give or take 1h.

Results: The energy required to keep the room at the setpoint of 18oC varied from 2.87 KWh on the coldest night, to 2.34 KWh on the warmest, averaging at 2,58 KWh

Show me the money!

Once you have figures for KWh usage, it’s a cool leap to start thinking about the dollar amount it cost to run these appliances. Where I live I am charged R$0.40 (or US$0.23) per KWh, flat – the rate don’t change according to time or the day or day of the week. That translates into an average cost of R$1.0 or US$0.59 to run the A/C for one night, in a single room. This is not bad taken in isolation, but it is worth keeping in mind that my usual daily power consumption in the house is in the order of 6.25 KWh, so adding another 2.58 KWh (or more, as this is only one room) is a huge increase.

Tips for using the PMM2010

This device comes with a little manual that explains everything you need to know in order to use it. In Chinese. If you’re like me and don’t understand a word in Chinese, there is a good explanation about it on Jefferson Ryan’s blog entry about the PMM2010. It’s in Portuguese, so grab your favorite web translator if that’s not much better than Chinese.

In summary here are a few points worth mentioning:

  • The device is intended for 220V/60Hz
  • The male pins are probably for the Chinese wall sockets; Ryan’s site (above) has some creative options for modifying it. My solution was just to remove the ground plug and twist the phase and neutral pins so that they become parallel, hence making it fit into an US-style wall socket
  • The female plugs where you put the load have big openings. I recommend using the one with the smaller opening and covering the other one with tape, to avoid accidents.
Categories: howto Tags:

Using delegation to make OpenID more interesting

June 23rd, 2010 Comments off

The basics

If you’ve been paying attention in the last few years, you might have heard of OpenID, which is a de-centralized authentication system. Read the wiki page for the full details, but what it basically means is that you can use an URL from an OpenID provider in order to authenticate into other websites, without having to create new accounts or share passwords or other data with those websites.

Say a friend has a blog at, which supports OpenID (like, and others do). If I want to comment on that blog, I can use my OpenID credentials to do so, and not be forced to create a new identity in that website.

Still not convinced? Take a look at this somewhat old (2007) but still instructive screencast from lifehacker

OpenID providers

Remember Microsoft Passport? Back in the day, if Microsoft had their way, you’d have to have a passport to logon to participating websites, and MS was the only one issuing and authenticating them; that’s called lock-in.

The good news about OpenID is that it is de-centralized from start: you can choose from a variety of providers. Take a peek on this list of the most popular ones or, from the Wikipedia, a more comprehensive list of providers; Any of those will perform the same functions for you. Even Microsoft’s own LiveID is now also an OpenID provider, how cool is that?

I’ve chosen to use yahoo, because I’m already a user there and thrust it; and my OpenID with Yahoo is simply, which I can use to login anywhere OpenID is accepted.

Taking control of your OpenID URL by means of delegation

Perhaps the only thing which is missing is control over the URL. Me using to identify myself is ok now, but suppose a few years from now flickr turns evil and I decide to move on to another provider? I’d have to start using a new ID and any content I created in websites under the older ID would not carry over.

Enters delegation: that’s an excellent feature of the OpenID spec which allows one OpenID URL to delegate the authentication process to another. For instance, say that I want to use as my OpenID (which I do), but I don’t want to go through the hassle of installing and configuring an OpenID provider. That’s ok, I just need to add a little bit of HTML code to the page served from the URL I control delegating to the actual OpenID provider I’m using, and specifying the ID to use. Easier to show than to talk about; all I need to do is add these two pieces of data to the <HEAD> section of my blog’s homepage:

<link rel="openid2.provider" href="">
<link rel="openid2.local_id" href="">

The provider URL you can usually find on your provider’s documentation or, if everything else fails, you should see it in the headers of the page served from your OpenID from that provider (that’s my flickr page in this example.

The second piece of information, the local_id, is just your identification with that provider.

Now, the fun part is: suppose flickr does indeed turn evil eventually? All I need to do is setup myself with another provider, like livejournal, Google, Microsoft, and change the headers in my blog; from that point on, I’ll authenticate with a new provider, but my identity for the external world has not changed.

Just how cool is that?

Categories: howto Tags:

Hidden treasures on the new Windows Task Bar

June 8th, 2010 Comments off

Windows 7 brought forth several UI enhancements; one area of attention was the taskbar, the area (usually) at the bottom of the screen where the start menu is, along with icons for the running applications.

There are several changes which are obvious and hard to miss, like the merging of the quick launch with the taskbar. But others are more subtle, although no less important. Let me recap a few favorites of mine here.

Jump lists

You normally left-click a program’s icon in the taskbar to start it; if you haven’t already, try right-clicking it once. If the program supports the concept of Jump Lists, it will bring you a list of quick tasks and recently opened documents to choose from. For example, here are three distinct jumplists, from Outlook 2010, Internet Explorer 8 and Media Player 12, showing a mixture of tasks and recent files/locations:

Windows 7 Jumplists examples

Aero peek

If you have multiple open instances of an application– or even multiple open documents in a single instance, like tabs in Internet Explorer – the application’s icon on the taskbar will have a differentiated border, indicating plurality. In such case, clicking the icon on the taskbar won’t immediately activate the application, but rather bring-up a preview of all instances, so you can choose which one to switch to. Just hovering over the taskbar icon with the mouse pointer has the same effect. An example of an aero peek preview can be seen here:

Windows 7 Aero peek example

Windows key taskbar shortcuts

50 cent gold coins; Photo by djcodrin on

This is the hidden gem, at least for keyboard shortcut addicts like me; with the taskbar and the quick launch bar combined, it is likely that the first few spots in your the task bar have been permanently assigned to your most frequently used applications, such that they are always on the same spot. To quickly launch any of the first 10 applications in the taskbar, just hit the Windows key and a number from 1 to 0 (0 meaning 10 here); the application will launch or, if already running, be switched to the front.

Win+[1-9]   Start (or switch to) first 9 pinned apps
Win+0       Start (or switch to) 10th pinned app

And just to make it even nicer, if the app is already running and, instead of switching to you want to open a new instance, just hit SHIFT+WIN+Number and a new instance will open-up – this actually works for mouse clicking too: a SHIFT left click means “new instance” in the taskbar. Sweet :-)

Categories: howto Tags:

Convert a webpage to PDF, and make it look nice too

May 6th, 2010 Comments off

If you’re like me, you sometimes need create a PDF out of a webpage, be it for archival purposes, or to read it later on a mobile, iPad Kindle or Nook. Well, if you’re like, the last three don’t really apply …

One of the easiest ways you had to perform this was to use a PDF printer such as Adobe Distiller or a free alternative like the excellent PDFCreator (*) ( The problem is, most browsers do a somewhat lousy job printing webpages, and you end-up with an ugly looking PDF. Enter pdfcrowd:

Just browse to and enter the address of the webpage you want to convert and boom! Instant PDF download, it’s that easy. Look at these images for what a “printed” PDF of this blog looks like, compared to the PDF created by pdfcrowd:

PDF converters' output side-by-side

For webmasters, there’s even a “url_to_pdf” entrypoint which can be used to directly convert a given page to URL. That’s the base for the “Download this page as a PDF” link you see on the navigation bar on the left.

For programmers, there are bindings for several languages as well, although I’m not sure about the terms of use and the cost if you want to host the converter engine yourself, thus insulating you from service outages.

Thanks to El Cohen for this tip!

(*) PDFCreator warrants a post on its own. If you sill print-out transaction receipts or anything else for recordkeeping, you should consider “printing” them to PDF for electronic safekeeping. Granted, it requires that you be organized about your electronic files and have a good backup strategy, but this is much easier for me than jockeying around paper files.

Categories: howto Tags: