Ted Piotrowski

Code to live. Live to spend time outdoors.

Page 7


Ghosts in the machine

”One of the biggest differences between hobbyists and professional programmers is the difference that grows out of moving from superstition to understanding.”
-Stephen McConnell

In my early days of programming I often fell into the trap of refreshing a broken application multiple times to make sure it was “really broken”. In hindsight this seems silly. A computer does not behave randomly, however, deterministic behavior can lead to some interesting quirks.

function getGreeting() {
  const hour = new Date().getHours();
  const greetings = [
    [22, 'Working late?'],
    [18, 'Good evening'],
    [12, 'Good afternoon'],
    [6, 'Good morning'],
    [4, 'Whoa, early bird!']
  ];
  return greetings.find((greeting) => { hour >= greeting[0] })[1];
}

Do you see the problem? (Hint: This will work flawlessly during office hours but result in a late night support call) Along the same lines...

Continue reading →


Use a professional IDE

At some point in their career programmers stumble upon VIM and find the boost in productivity to be so great that they treat the find like an epiphany handed down from above. I personally love VIM and think everyone should have a go at learning to use it effectively. However, do not stop evaluating other editors that may be better suited for you specific language or project. If you’re getting paid to code, don’t be opposed to the idea of paying for a professional IDE.

Recently I’ve been frustrated by the following argument: “I only use VIM because it’s super fast and lightweight. It feels closest to the bare metal of the machine.” After this statement I watched the developer navigate to find the definition of a class used in another file as follows

  1. gg - two keystrokes to navigate to top of file
  2. look at import statements
  3. :e . - four key strokes to open file navigator
  4. /Libr - five...

Continue reading →


Broken video attachments in Gmail

My sister often emails video attachments of my niece and nephew. Gmail provides a really sleek mechanism for viewing the attached videos without leaving the browser by playing them in an embedded YouTube player. However, at some point the YouTube player started presenting me with the following message: “An error occurred. Please try again later.” Let’s dig in.

blog1.jpg

The cause

Disabling third-party cookies in my browsers was the cause of this issue. Some browsers like Firefox have this disabled by default. To see if you’re video playback is broken for the same reason visit this page. If you see “Third party cookies appear to be disabled”, then read on for the solution.

Background: third-party cookies

When you log in to a website like Gmail you provide your email/password and in the background Gmail’s servers send you back a cookie containing a session ID (for example...

Continue reading →


Designing Slouch Cam

Screen Shot 2017-06-19 at 8.01.02 AM.png

Recently I’ve had some free time to take up another personal project. The idea is that your computer’s web cam watches your head position and alerts you if it gets too close to the screen. My mind has never been able to kick the habit that the closer I bring my face to the screen the better I will understand whatever is written on it. And so we come to my golden rule of side projects:

Build something that benefits your life. This will provide you intrinsic motivation (happiness) while you wait for the extrinsic motivators (money, fame) to kick in.

I’ve seen a lot of people violate this rule by brainstorming business ideas that can make a lot of money but don’t affect the creator personally. My view is these founders will run out of steam long before their project earns them a full time paycheck.

But I digress….

The design

I wanted to follow two design principles:

Limit wordy

...

Continue reading →


Aspiring Flats and Rock of the Ages bivvy

FullSizeRender 31.jpegMeadow at Aspiring Flats

Most people who spend time in Wanaka will drive down the west Matukituki valley and hike to Rob Roy glacier. The less popular East Matukituki valley offers a seldom travelled alternative. In fact, I found the valley devoid of human life the evening I hiked in. Plenty of cows, though. The most accessible destinations of interest are the Aspiring Flats and Rock of the Ages bivvy which are located on a tributary of the East Matuktuki.

FullSizeRender 35.jpegFollow this road, second valley on left in the distance is your destination

The walk begins by crossing an impressive bridge across the West Matutuki. Follow the route markers along the true left bank until you come to private land. You’ll need to remove your shoes for three water crossing before heading north along a road for some time. You will go through a gate. Next follow a long, long fence. There is a worn road running...

Continue reading →


Using a Raspberry PI as an AirPrint server

I’ve had my Brother HL2170W laser printer since January 2010, before AirPrint printers were really a thing. It’s been a solid printer and still has 90% of its second cartridge left. I’ve had an iPhone since around 2010 as well and I was under the mistaken impression that the two devices could never talk to each other. True, the devices are not directly compatible, but it is possible to use a Raspberry Pi as a mediator to have the two work together. Here’s a quick run down of how works in under four minutes:

View →


Running NodeJS, NPM and Git on Windows 10 without Administrator privileges

  1. Download NodeJS zip (http://nodejs.org/dist/latest/), likely the *-win-x64.zip version and unzip inside ~/AppData/Local/Programs/node1
  2. Download git for windows (https://git-for-windows.github.io/)
  3. Run installer
    1. Uncheck all components except Use TrueType font
    2. select Use Git from Git Bash only
    3. You can leave default line ending conversion
    4. Use Windows’ default console window
    5. Check file system caching and Credential Manager
  4. Run git bash shell
  5. vi .bash_profile or use notepad.exe to create it in your user directory

    PATH=$PATH:~/AppData/Local/Programs/node
    PATH=$PATH:/c/Windows/System32/
    
  6. Restart git bash shell or run source .bash_profile

  7. Clone your github repo over HTTPS (no SSH keys required). Credential manager can store your password.

  8. Cd into project and npm install2

  9. Go forth and profit

Bonus: Visual Studio Code

Visual Studio Code is my favorite editor and it’s free.

  1. ...

Continue reading →


Browsing on a Chromebook using a SOCKS proxy

How to watch HBOGO abroad on your Chromebook?

  1. Turn on developer mode on your Chromebook
  2. Press Ctrl+Alt+T to open a shell window and type shell at the prompt
  3. Start a SOCKS proxy server on your laptop that forwards traffic through a server in the USA you can access via SSH
    ssh -D 20001 user@serverintheusa
  4. Configure your Chromebook connection to use the local proxy.

Screenshot 2016-07-05 at 5.42.52 PM.png

4a. Click on your active Wifi connection to bring up the proxy configuration. Fill in the appropriate SOCKS host and port.

Screenshot 2016-07-05 at 5.42.30 PM.png

4b. You should now be able to access HBOGO

Screenshot 2016-07-05 at 5.43.56 PM.png

What is a proxy?

A proxy acts as a middle-man for your internet traffic. If you want to read cnn.com, instead of issuing a request for that page directly from your browser, you would first issue this request to a proxy server. The proxy would then request the contents of cnn.com and once it received the response, it would return the requested data back...

Continue reading →


Ford Focus heat shield fix

I recently noticed some tin-can rattling coming from the underside of my mom’s car. Google'ing pointed me towards the rear heat shield coming loose. I used some aluminum flashing and oversized washers to fasten it back in place.

Tools:

  1. Scissors
  2. 10mm socket wrench
  3. WD-40
  4. Framing nail + hammer

Parts:

  1. 10-24 nylon lock nuts
  2. 3/16" x 1 ¼" washers
  3. aluminum flashing

View →


Debugging load cells and HX711

I’m working on a system to determine how long it takes to air dry laundry. As the fabric dries, it becomes lighter. The idea is to measure the weight of drying laundry and when it stops decreasing you know it is dry.

Enter: the load cell. Load cells convert force measurements (such as weight) into electrical signals. They’re found in most digital kitchen scales. If we can hang a piece of laundry from the load cell and feed the reading to a computer, we’ll be able to get the data we’re after.

Load Cell Cantilever.jpg

Image from http://2.bp.blogspot.com/

I decided to use a strain gauge load cell because it can measure hanging force easily, and it’s cheap and plentiful on Amazon.com. Grab a volt meter and a variable power supply and lets demonstrate how a load cell works.

Screenshot 2016-06-13 at 1.33.37 PM.png

Reading a load cell

A load cell comes with four wires. Red and black wires for voltage in and ground (5-10V). Two additional wires...

Continue reading →