without understanding there is no reason

Expandmenu Shrunk

  • Replace those stupid ‘smart’ quotes

    Posted on by Mark
    var quoteparse = function() { var elemin = document.getElementById(“quotes_in”); elemin.value = elemin.value.replace(/[\u2018\u2019]/g, “‘”).replace(/[\u201C\u201D]/g, ‘”‘); }
    If you do anything that requires text, you will have come across those damn ‘smart’ quotes or curly quotes…
    I’m not sure in what universe they help anyone, but I’m sure someone thinks they look nice or some crap like that. They are annoying! Here we can get rid of them from your text and return it to santity:
    Click to correct: Fix
    oh, right, here’s some stupid quote examples:
    “That’s a ‘magic’ blackeye.”
    “You’ve wasted ‘my’ time.”

  • Arduino Parking Assistant (version 0.1)

    I wanted to create a device so that I would have assistance in identifying where my car should be parked in my ever-changing space in my car-park. There are 2 constants:
    1. The walls, and
    2. the car.
    I also had an Arduino sitting around doing nothing. I figured this would be a perfect little job for it and a sensor or two. I also figured it would be pretty simple device and a good way to learn about how to make something useful. It took much longer than I thought it would. I think it was mostly because I wasn’t sure what I wanted until I considered the simplest idea for this. My requirements:
    1. I don’t want to have wires running all over the garage.
    2. I don’t want to use batteries
    3. I want to use minimal sensors
    4. I want to be simply informed when I’m in the right spot within a certain tunable range
    5. It should be cheap to build (well mostly)
    So, to address each of these:
    1. The sensor is a single distance sensor at the front of the parking area. LED lights can be close by.
    2. My outlets are at the front of the parking area, so I can use a power supply transformer.
    3. I found this: Sharp range sensor, so a single sensor could do it.
    4. 3 LEDs would do… too close (go back), just right (stop), too far (keep going).
    5. 3 LEDs, 1 Sharp range sensor, 1 220 ohm resistor, 1 5v transformer, 1 arduino (uno) => <$50
    So my simple design is 3 LEDs arranged from top to bottom:
    • yellow, too close, pin 2
    • red, stop, pin 6
    • green, keep going, pin 10
    I only need 1 220 ohm resistor for the set of LEDs since only one will be on at a time anyway, and can be shared, and thus connected to the GND pin on the digitial input/output side of the Arduino. I soldered the 220 ohm resistor on the end of a stiff wire. Next to that, about 1 cm along, the short lead (negative) of the yellow LED, then 1 cm further, the short lead of the red LED, and then about 1 cm further, the short lead of the green LED. These lined up approximately with the pins mentioned above… close enough. On the other side of the Arduino is the analogue input/outputs where the distance sensor is wired directly. Since I didn’t get a jtag wire set with the sensor (stupidly) I soldered wires directly to the board. Not very elegant, but certainly cheap. There is a 5v power input wire, a GND wire, and a voltage out going to A0. Pinouts can be seen here: datasheet.pdf A close-up photo: parking assistant The functioning system in a video:
    and now the code:
       Parking Assistant Using Range Sensor
       Created by Mark Slemko - October 5, 2013

       Parts taken from: http://arduino.cc/en/Tutorial/AnalogInput

    #include <math.h>

    int sensorPin = A0;    // select the input pin for the potentiometer
    int ledPin = 13;      // select the pin for the LED
    int ledStopPin = 6;      // select the pin for the stop LED
    int ledClosePin = 10;
    int ledFarPin = 2;

    int settleTime = 20000; // when same value is reached for this time, stop checking as often
    int recheckTime = 0;
    int timer = 0;
    double settleDistance = 0.0;
    double variance = 2.0;

    #define STOP_DISTANCE     50.0
    #define STOP_BRACKET      5.0
    #define MAX_RECHECK_TIME  3000

    #define SENSOR_ACTIVE     160.0
    #define SENSOR_TOO_CLOSE  25.0

    void setup() {
      // declare the ledPin as an OUTPUT:
      pinMode(ledPin, OUTPUT);  
      pinMode(ledStopPin, OUTPUT);  
      pinMode(ledClosePin, OUTPUT);  
      pinMode(ledFarPin, OUTPUT);  

    void loop() {
      // read the value from the sensor:
      double distance = 92.0 * pow((averageVoltage() + 0.30221), -1.5281);

      // turn the ledPin on
      digitalWrite(ledPin, HIGH);  
      // stop the program for <sensorValue> milliseconds:
      // turn the ledPin off:        
      digitalWrite(ledPin, LOW);  
      // stop the program for for <sensorValue> milliseconds:
      Serial.print(" wait ");

      timer += (int)distance + 50;

      // check if settle time reached
      if (checkSettleTimeReached(distance)) {
        digitalWrite(ledStopPin, LOW); // turn off stop LED
        Serial.print(" delay recheck ");
        delay(recheckTime); // wait for next check
        if (recheckTime < settleTime) {
          recheckTime = recheckTime * 2;
          if (recheckTime > MAX_RECHECK_TIME) {
            recheckTime = MAX_RECHECK_TIME;
        timer = settleTime; // no overflow ...
        // ensure low pins
        digitalWrite(ledStopPin, LOW);
        digitalWrite(ledClosePin, LOW);
        digitalWrite(ledFarPin, LOW);
      } else {
        recheckTime = settleTime / 5;
        digitalWrite(ledStopPin, LOW);
        digitalWrite(ledClosePin, LOW);
        digitalWrite(ledFarPin, LOW);
        if (shouldShowStopLED(distance)) {
          if (distance < (STOP_DISTANCE - STOP_BRACKET)) {
            // too close        
            digitalWrite(ledClosePin, HIGH);      
          } else if (distance > (STOP_DISTANCE + STOP_BRACKET)) {
            // too far
            digitalWrite(ledFarPin, HIGH);
          } else  {
            // perfect
            digitalWrite(ledStopPin, HIGH);

    boolean shouldShowStopLED(double distance) {
       //abs(distance - STOP_DISTANCE) < (variance * (1.0 + distance / 50.0)) + (STOP_BRACKET * 2)) {
      if ( abs(distance) < SENSOR_ACTIVE && abs(distance) > SENSOR_TOO_CLOSE) {
        return true;
      return false;

    boolean checkSettleTimeReached(double distance) {
      boolean delta = abs(settleDistance - distance) > (variance * (1.0 +  distance / 100.0));
      if (delta) {
        timer = 0;
      if (timer < settleTime) {
        settleDistance = distance;
        return false;
      } else {
        return true;

    // return a voltage between 0.0 and 5.0 v
    double averageVoltage() {
      int sensorValue = 0;
      int averaging = 10;
      for (int i=0; i < averaging; i++) {
        sensorValue += analogRead(sensorPin);
      return sensorValue / 1024.0 / (averaging/5.0); // 5 reads at 5 volts

    • The power supplied via the USB cable connected to a computer changes the result of the output coming from the sensor.
    • The formula for determining the distance is fairly accurate using the USB power, however, the values are 'stretched' using the power supply through the 5v transformer.
    • The LEDs suck quite a bit of power, and without the current limiting resistor, the LEDs draw more than the power supply can provide and keep the arduino powered
    • The LEDs when they turn on changes the power supply's voltage/current levels affecting the measurement of distance
    • A 5v transformer is not enough power for the arduino, and need to use a bigger one. A 12v one is used and restores the distance measurements to be far more accurate and stablizes the circuit.
    • The sensor reading is quite variable as the distance grows, and I'm not sure how to reduce the variability. Is it related to the power supply ripple? Or it's own circuit power draw?
    Update - Feb 1:
    I got an Arduino Pro Mini, which is sufficient for this purpose (and quite a bit cheaper), to test the idea that the issues with the distance variability is related to loose wiring or power supply ripple. I've discovered a couple of things during my minor update:
    1. Soldering the wiring did improve the stability a little.
    2. The measurements using the IR Distance Sensor variability was minimal in my work area.
    3. Aiming the IR Distance Sensor at the headlights produced horrible distance measurements
    4. By chance I aimed the IR Distance Sensor at the license plate with similarly horrible distance measurements. So I re-aimed the Sensor at the hood as before, which improved things immensely
    5. I washed my car and to my surprise, the IR Distance Sensor produced quite variable distance measurements.
    6. When the sun is in direct line of the IR Distance Sensor, it cannot get a proper reading at all. Much like the sun shining in your eyes... hopelessly unable to 'see'.
    I found that all of the specular issues for the IR Distance Sensor quite amusing. I didn't expect that the effect would be so dramatic with regard to the material, or rather the paint job. It was kind of funny that my dirty car reduces the problem slowly over time encouraging me to not wash it. So, I'm looking for a different, and perhaps better sensor for this purpose. I was really hoping that the IR Sensor would work because it is kind of cool, but I could repurpose it for something else I'm sure.

  • 2013 Summer Of Day Hikes – October

    I had the unbelievable opportunity of climbing the Gros Piton in St. Lucia — and it is a wonderful addition to the summer of Day hikes! Ratings 1) trail presence (TP) (hard to follow to paved with black gold – 5 star rating) 2) difficulty (D) (1 – easy to 10 – climbing gear needed) 3) pay-off (PO) (5 star rating)

    Gros Piton, St. Lucia (October 11)

    Note: this is a guided hike. Thanks goes out to Bani! http://www.rainforestadventure.com/st_lucia_tours_excursions/other_tourist_attractions/the_pitons/ TP: D: 6/10 PO: Climb: 610 m. From the bottom looking up: IMG_0301 The view of St Lucia IMG_0298 The Pitons Petite and Gros Piton

  • JSON validator

    validate json good examples:
    { "a": 1, "b":2 }
    { "a": 1, "b":2 }
    { "a": 1, "b": [ 1,2,3 ] }
    { "a": 1, "b": [ 1,2,3 ] }
    bad examples:
    { "a": 1, "b:2 }
    { "a": 1, "b:2 }
    { "a": 1, "b": [ 1,2,3 }
    { "a": 1, "b": [ 1,2,3 }
    JSON Parse: Validate

  • 2013 Summer Of Day Hikes – September

    Starting in July, we decided to do a hike, preferably to the top of a mountain, each weekend… This is them (continued…): Ratings 1) trail presence (TP) (hard to follow to paved with black gold – 5 star rating) 2) difficulty (D) (1 – easy to 10 – climbing gear needed) 3) pay-off (PO) (5 star rating)

    Eagle Bluffs (September 2)

    http://www.vancouvertrails.com/trails/eagle-bluffs/ TP: D: 5/10 PO: IMG_0623

    Upper Shannon Falls (September 8)

    http://www.vancouvertrails.com/trails/upper-shannon-falls/ TP: D: 6/10 PO: IMG_0631 at the bottom: IMG_0633

    Two Canyon Loop (September 15)

    http://www.vancouvertrails.com/trails/two-canyon-loop/ TP: D: 2/10 PO: IMG_0634

  • 2013 Summer Of Day Hikes – August

    Starting in July, we decided to do a hike, preferably to the top of a mountain, each weekend… This is them (continued…): Ratings 1) trail presence (TP) (hard to follow to paved with black gold – 5 star rating) 2) difficulty (D) (1 – easy to 10 – climbing gear needed) 3) pay-off (PO) (5 star rating)

    Bertha Lake (August 5)

    http://www.watertonpark.com/activities/hiking_trail.htm TP: D: 5/10 PO: IMG_0601 mid-way: IMG_0600

    St. Mark’s Summit (August 10)

    http://www.vancouvertrails.com/trails/st-mark%27s-summit/ TP: D: 5/10 PO: IMG_0176

    Buntzen Lake (August 17?)

    http://www.vancouvertrails.com/trails/buntzen-lake/ TP: D: 2/10 PO: … photo coming …

    Grouse Grind (August 24)

    http://www.vancouvertrails.com/trails/grouse-grind/ TP: D:7/10 PO: IMG_3019

  • 2013 Summer Of Day Hikes – July

    Starting in July, we decided to do a hike, preferably to the top of a mountain, each weekend… This is them: I’m going to rank these on 3 scales 1) trail presence (TP) (hard to follow to paved with black gold – 5 star rating) 2) difficulty (D) (1 – easy to 10 – climbing gear needed) 3) pay-off (PO) (5 star rating) I should say, we look for intermediate level trails. I’ve injured my arm, so climbing is not wise for me. We are not looking for a walk in the park either, but those can be nice. Also, We have to be able to get there and back within one day.

    Mount Gardner (July 13):

    http://www.vancouvertrails.com/trails/mount-gardner/ TP: D: 5/10 PO: mount gardner

    Quarry Rock (July 20):

    http://www.vancouvertrails.com/trails/quarry-rock/ TP: D: 4/10 PO: IMG_0142

    Garibaldi Lake (July 28):

    http://www.vancouvertrails.com/trails/garibaldi-lake/ TP: D: 6/10 PO: IMG_0590

  • Population Counter

    Estimated total:
    While here the Earth’s population has increased by… 0 people.
    An estimated failing point at 9 billion, we have: left to go!

  • Converting audio files into ringtones for iphone on Linux

    These are baically notes for me, but it might help someone else.

    Needless to say, you can’t connect an iphone to Linux yet without jail-breaking your phone, or buying another computer with a ‘supported’ OS like mac or windows.


    Update: using Fedora 15 or later, the iPhone does connect under Linux and you can browse it! Wooh!

    Nevertheless, the tools on Linux are fantastic to edit sound and do gobs of other stuff…

    1) ring tones have to be less than 30 seconds in length… so use Audacity to edit your favourite audio file to a nice <30 second clip.

    2) Save that selection as a .wav (16 bit stereo PCM) file.

    3) in a command prompt type something like this:
    faac -b 128 -c 44100 -w --title TITLE mysound.wav
    and it will produce something like mysound.m4a

    4) rename it to be mysound.m4r (because ringtones are aac with the .m4r extension — whatever)

    5) transfer that on your iTunes 'supported' OS (bah – ridiculous) that you can connect your iPhone to and transfer the file into the ringtones folder.

    6) sync the iphone.


  • Scooting Coco

    scooting coco