Wednesday, June 25, 2014

The Problem With Dynamically Type Programming Languages

Consider the following code in Java:
byte[] key = generateAES();
byte[] encrypted = encryptAES(key, "Hello World");
String b64Key = b64encode(key);
String b64enc = b64encode(encrypted);

Now consider the same code in PHP:

$key = generateAES();
$key = b64encode(key);
$encrypted = encryptAES($key, "Hello World");
$encrypted = b64encode(encrypted)
This is exactly what bit me in the A$$ this week. I kept getting the wrong results and since this was a port from Java to PHP, I kept expecting it to be an interoperability problem.
It's really easy and tempting to reuse the old variable key (which I did) and get the order wrong (which I did). Because you would use the base 64 key when trying to debug the problem, everything would appear to be correct, but now the PHP code is using the base 64 of the key instead of the key itself.
This wouldn't happen in Java or any other statically typed language.

Monday, April 15, 2013

Replacing the headlight on a Renault Clio Mk3

This post is brought to you by www.renaultforums.co.uk

There are two ways to replace a light bulb in a Renault Clio Mk3 - the easy way and the hard way.

The Easy Way

Go to the dealer.

The Hard Way

It all started innocently enough

Just noticed one of my bulbs has blown (dipped bulb). Haven't had chance to look at it yet but does anyone know how easy they are to change, is the access ok? Judging from a quick glance at the engine bay when I bought the car it does look rather snug. 

And went rapidly downhill from there

If you remove the filler neck of screen wash bottle you can just get on the bulbs, only downside the car has eaten half my hand in the process.

make sure you have plenty of time (took about 45 mins), very small hands and ultra bendy fingers.after what seemed like hours, i gave up 

I pray that I never have to replace them soon.
omg! it took me forever to change the bulb and yes the car does eat your hand!! 
I tried to change the bulb the clip ended falling into the housing. Renault told me I have to replace the whole lamp fitting...
Jesus is changing a bulb really as hard as it looks?

Surprisingly, some people take it to the next level

It was quicker to drop the drivers side bumper and remove the headlight unit. Two screws and two bolts, pull it forward and undo the three bolts holding the unit in place, then it's easy. 
the best and easy way is to remove the wheels, and take off the front splash guards...
Using the Haynes manual as 'a guide', ... the bumper was removed in 30 minutes. No need to jack up, just turn the wheels on full lock and the wing inserts can be bent out of the way relatively easily.

And The Winner

I dont know what everyone is going on about the passenger side lights are easy to fix, here is what you need and how to do it the easy way; 
Tools: 10mm Socket, 13mm Socket, extender bar and handle, and finally you!! 
  1. firstly remove the battery covers, ... 
  2. remove the battery connectors, ...
  3. remove the battery venting cable, ... 
  4. remove the catch holding in the battery and remove battery. 
  5. remove the cable from the fuse box on the front of the battery casing ...
  6. unclip the fuse box using the two small holes on the inside of the battery casing, and push slightly out of the way, 
  7. Now you should be able to get into the light fixture and change the bulb. 
  8. Attach everything in the reverse order and et voila !! 
It only took me 20 mins 

Epilogue

I tried changing the headlight before reading the above. I ended up wasting 45 minutes of my life. My right hand is scratched in several places. There is still no light bulb in the socket and the rubber cover fell into an inaccessible part of the engine compartment. I have a date with my dealer on Wednesday...

"I am a woman who is determined to fix drivers side, side light and dipped main light ... First of all how do I know what bulbs to buy? "

Thursday, November 15, 2012

How to Debug Android Devices

If you get the following:
android@Hythloth:~/android-sdk-linux/platform-tools$ ./adb devices
List of devices attached
????????????    no permissions

android@Hythloth:~/android-sdk-linux/platform-tools$

Then you need to define your device in udev. Do the following:
lsusb
android@Hythloth:~/android-sdk-linux/platform-tools$ ./adb devices
List of devices attached
???????????? no permissions

android@Hythloth:~/android-sdk-linux/platform-tools$
you need to add to usb list your device
sudo vim /etc/udev/rules.d/51-android.rules
and put this line (use your own vendor ID)
SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666", GROUP="plugdev"
save it, and then
sudo chmod a+r /etc/udev/rules.d/51-android.rules
sudo service udev reload
and it should work now.
But it didn't!
What did work was:
sudo ./adb kill-server
sudo ./adb start-server
As root.

This was taken from the incredibly useful stackoverflow.com post why-is-eclipses-android-device-chooser-not-showing-my-android-device and is probably based on developer.android.com/tools/device.html

Monday, October 29, 2012

Scrollbars are a good thing

Usability in smart phones has taken a huge step back - in the name of efficiency, elegance and stupidity, we got rid of the scroll bar. Unfortunately, that line to the right has three important uses:
  1. It is a dedicated element for scrolling up and down
  2. It gives us a visual cue to where we are in the screen
  3. It tells us there is more content below!
Because smart phones have small screens, designers (programmers) decided to save on space and let you use the space between widgets to scroll. If you missed and hit a control and sent an inappropriate text message to you mother in law, all the better.

Unfortunately, this potentially hides a considerable part of the application from even the most powerful of users. Consider the following screen on the left. It looks complete. A single dialog box with three volume sliders.
But wait, there are two more sliders hidden below!

If someone (for example Samsung) were to mute your notifications during the last software update (Why???), you would be left without notifications of your incoming text messages, appointments, etc.

A complete FAIL.

I originally solved this by writing an app to monitor incoming text messages and beep. Yes! it was easier to program a workaround then to figure this out. Pathetic