Wednesday, September 9, 2015

Is Amazon Delaying Shipments?

I have been ordering things from Amazon for many years, but within the last year I've noticed a change.  I firmly believe that Amazon is intentionally delaying shipment of goods.

As I said I buy a lot of things from Amazon, but I've never had an Amazon Prime account.  Honestly I'm too cheap to pay the $100 a year for Prime when there are such easy ways around it.  Whenever there is something I want to buy I add it to my Amazon cart.  Then when my cart reaches the minimum amount for free shipping (currently $35) I place the order.  This works out nicely and it averages out to probably 12 or 15 Amazon orders per year, so I don't have to wait that long for my cart to fill up.  But I save on that $100 a year.

But as I said, within the last year something has changed.  It used to be items shipped for free arrived to my house in 3 or 4 days.  But lately Amazon orders have been arriving in about 12 days.  That's a significant change!  What's more, after I place an order I don't get the email from Amazon saying it has shipped for about a week.

I think the problem is Amazon's free shipping was too good.  If you can get free shipping that will arrive in 3 - 4 days, why would you pay a lot of money for 2-day shipping?  So it makes sense that Amazon would want to slow down the free option in an effort to encourage people to spend more for faster shipping.

However; if this is true then Amazon's plan may backfire on them.  Now anytime I order something online I check competitors like newegg.com, target.com, bestbuy.com, etc.  All of these retailers offer free shipping or free shipping to retail stores.  If I find the same item for the same or even slightly higher in price, I won't order from Amazon.  Why buy from Amazon when they won't get it to me for 2 weeks what I can order elsewhere for the same price and have it in a few days?

So Amazon, if you listening, you are losing business because you're trying to encourage people to pay for faster shipping and/or buy Amazon Prime.

Monday, August 10, 2015

Raspberry Pi as a Seafile server

My latest Raspberry Pi project is to create a personal Seafile server.  If you've never heard of Seafile before you're probably not alone.  There are a lot of "cloud" based file backup and synchronization services like Dropbox, Google Drive, and Microsoft OneDrive.  These services are great and have many uses, but they have drawbacks as well.  They all offer free accounts so long as you stay under a certain size (usually around 5GB).  There's also the issue of security.  My data is being sent from my computer over the Internet to their servers, and then back.  But how secure is this?  Is the communication between my computer and their servers secure?  Once my data is on their servers, how secure is it?  If someone hacks in can they access my data?  Can the company hosting my data access it?  And what about government agencies, do they have a backdoor into these companies servers?

There are two free open-source alternatives; Seafile and Owncloud.  Owncloud is more well-known than Seafile, but every review I read online says that Owncloud is buggy whereas Seafile is rock solid.  I also really like Seafile's security model.  My data is encrypted on my computer using a password of my choosing and strong AES-256 encryption before the data is transmitted to Seafile.  What's more, the data is only decrypted on my device after downloading from Seafile.  In otherwords my password is never transmitted to Seafile which means hackers, Seafile themselves, and the NSA cannot access my data.

Because of this, years ago I signed up for a free Seafile account and I have grown to love it!  Unfortunately Seafile has a very low limit, only 1 GB at the time I signed up.  This isn't enough to effectively backup to, but I have used it for years as a sync point.  I have two computers at home and one at work and this makes a great place to put documents and files I want synchronized across all machines.  But I wanted more storage so I decided to create my own Seafile server at home.

Before I start my guide a few points:
  • I will be setting up a Seafile server with nginx as the web server, HTTPS for the communications, and SQLite as the back-end database.  This arrangement is a great combo for a single user or a small number of users.
  • There are a number of existing guides on how to do this.  Here's a great guide, this one is in German, and the official Seafile manual has generic Linux instructions.  But I found problems with each of these guides, things like missing steps.  So I combined all these into a single end-to-end guide to get this working.
  • I assume you know at least some Linux.  I'm not going to explain how to use tools like nano.  If you've never used Linux before then this entire process is probably over your head.  But if you know at least a little bit about Linux you should be good to go.
  • You should know how to SSH into a Linux system.  Most of the following is done while connected to the Raspberry Pi via an SSH connection.
  • I will be setting up my Seafile server for access both inside and outside my home network.  For this to work you'll need a DDNS account.  There are a number of both free and paid DDNS services.



Hardware:
For this project obviously you'll need a Raspberry Pi.  I used a Raspberry Pi B+.  But this would work with any Raspberry Pi.  In fact, this would be a perfect use for a model A since you won't need a lot of USB and the extra power savings means less electricty.  For the power supply I went with this one which I've used on previous Pi projects.  The 2amp supply will be overkill for this project, but it's a known good supply.  I decided to try a new case and went with this one.  I got the Edimax EW-7811Un wifi dongle.  I would have preferred to hard wire it, but my wireless router is out of empty ports so I went wireless.  And since this will be low-bandwidth it won't matter.  To complete the hardware I went with a 32GB Samsung EVO micro SD card.  This card will hold both the OS and the Seafile data.



Software:
On the software side of things I used Raspbian (version 2015-05-05).  You will also need Seafile itself.  I used version 4.2.3 which was the latest version at the time I did this.  You'll need a DDNS service, which I use the free service offered by my Synology NAS.


Guide:
Buckle in and get ready, this is going to be a long bumpy ride.

1.  Download Raspbian and use Win32 Disk Imager to copy into the SD card.
2.  Boot the Pi for the first time.  When the Raspbian config screen comes up, make the following changes:

  2a.  Select "Internationalization Options" and then "Change locale."  Place a check by "en_US.UTF-8 UTF-8."
  2b.  Select "Internationalization Options" and then "Change time zone."  Linux handles time zones differently than Windows.  Instead of selecting your time zone by name or UTC offset, you instead select a region and a city near you.  So for me I select Americas and Los Angeles.
  2c.  Select "Internationalization Options" and then "Change keyboard layout."  For me I selected "Generic 104 key" and "English US."  This step is important as the default keyboard layout is English UK with things like the pound sterling symbol.
  2d.  Select "Advanced Options" and then "Overscan."  Set this option to disabled.  Older analog TVs have overscan where the image is smaller than what the TV can display.  If I do not disable overscan then on my computer monitor I have half an inch of black all the way around the outside edge.  Disabling overscan corrects this.

  2e.  Select the option to resize the image then let the Pi reboot and resize.

The next step is to configure WiFi.  There is no doubt a terminal way to do this.  But I'm lazy and don't know how to do that in Linux, so I use the GUI to make it easy.



3.  Run "startx" then bring up a Terminal window from the start menu.  Run "wpa_gui" and connect to your wifi.

Now let's update the system and install Samba which makes networking much easier:

4.  sudo apt-get update
5.  sudo apt-get dist-upgrade
6.  sudo apt-get install samba samba-common-bin

Now let's change the computer's name.  I choose "seafilepi" as my computer name.

7.  Run "sudo nano /etc/hosts" and change raspberrypi to your new computer name.
8.  Run "sudo nano /etc/hostname" and change raspberrypi to your new computer name.
9.  Shut the system down with the command "sudo shutdown -h now"

The Raspberry Pi doesn't have much memory to begin with.  Since this is a headless unit let's make some changes to maximize memory usage.

10.  Put the SD card back into a Windows PC and edit the file config.txt.  Add the line "gpu_mem_512=16"  Note: this setting will disable the HDMI output.  If you still want HDMI then user 32 as the memory setting.
11.  Put the SD card back into the Pi and boot up.  Run "sudo nano /etc/inittab" then scroll down and use a '#' to comment out all "getty" lines.

Again, this will be a headless unit, so let's remove the unnecessary bits of Linux, like the graphical desktop X.  There's probably a better way to do this but this is what worked for me.  Note the first line actually removes too much, the second line adds some modules back in without which the Raspberry Pi would not have network access.

12.  sudo apt-get autoremove --purge libx11-.* fonts-.* desktop-.* lxde-.* epiphany-.* lightdm-.* alsa-.* gnome-.* raspberrypi-artwork xkb-data omxplayer penguinspuzzle sgml-base xml-core minecraft-pi sonic-pi wolfram-engine
13.  sudo apt-get install raspberrypi-net-mods
14.  sudo apt-get install deborphan
15.  sudo apt-get autoremove --purge $(deborphan)
16.  sudo apt-get autoremove --purge deborphan dialog
17.  sudo apt-get autoremove --purge
18.  sudo apt-get autoclean

When all is said and done this will take away about 1 - 1.5 GB of files.  So that 32GB SD card will have about 30 -31 GB of free space for Seafile.

Now we're ready to install Seafile itself.  First create a new user account under which Seafile will run.

19.  Run "sudo adduser seafile --disabled-password"  Enter the name as "seafile" and all other fields blank.

20.  sudo apt-get install python2.7 python-setuptools python-imaging sqlite3
21.  sudo su seafile
22.  cd ~
23.  mkdir cloud
24.  cd cloud
25.  wget https://github.com/haiwen/seafile-rpi/releases/download/v4.2.3/seafile-server_4.2.3_pi.tar.gz
26.  tar -xvzf seafile-server_4.2.3_x86-64.tar.gz
27.  mkdir installed
28.  mv seafile-server_* installed

The following commands will configure Seafile.  For the name choose the name of this server, something short like your name.  For IP address enter the computer name from steps 7 and 8.  All other fields use the default values.

29.  cd seafile-server_4.2.3
30.  ./setup-seafile.sh

We're now ready to start Seafile for the first time.  When you start the Seahub you'll be prompted for the administrator username and password.

31.  ./seafile.sh start
32.  ./seahub.sh start

33.  exit

At this point if you open a web browser and navigate to "http://seafilepi:8000" you should see the Seafile login screen.  If not you did something wrong so double-check your work to this point.  You could stop at this point and use Seafile.  But I want to go further and configure HTTPS for greater security, which requires nginx.

34.  sudo apt-get install nginx python-flup

nginx is not designed for the low resources found on the Pi, so let's make some changes to improve things.

35.  sudo nano /etc/nginx/nginx.conf


Change "worker_processes" from 4 to 1 (or 2 for Pi model 2).  Also change "worker_connections" from 768 to 128.  Save the changes and exit.

36.  sudo /etc/init.d/nginx start

37.  sudo su seafile
38.  cd ~/cloud
39.  Run "nano ccnet/ccnet.conf"  Change it to read SERVICE_URL = https://seafilepi:8001

40.  Run "nano seahub_settings.py"  Append the line  FILE_SERVER_ROOT = 'https://seafilepi:8001/seafhttp'

Let's stop and restart Seafile.

41.  cd seafile-server-latest
42.  ./seahub.sh stop
43.  ./seafile.sh stop
44.  ./seafile.sh start
45.  ./seahub.sh start-fastcgi
46.  exit

Now we need to create a self-signed digital certificate for nginx.  The second to the last command will prompt for a country code ("US" for United States), and your state.  For organization enter "None" and all other fields can be left blank.

47.  sudo mkdir /etc/nginx/ssl
48.  cd /etc/nginx/ssl

49.  sudo openssl genrsa -out seahub.key 4096
50.  sudo openssl req -new -key seahub.key -out seahub.csr

51.  sudo openssl x509 -req -days 3650 -in seahub.csr -signkey seahub.key -out seahub.crt
  Enter the following into the file /etc/nginx/sites-available/seahub and save it.

52.  sudo nano /etc/nginx/sites-available/seahub
server {
    listen 8001;
    ssl on;
    ssl_certificate /etc/nginx/ssl/seahub.crt;
    ssl_certificate_key /etc/nginx/ssl/seahub.key;
    server_name seafilepi;
    error_page 497 https://$host:$server_port$request_uri;

    client_max_body_size 0;

    location / {
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param HTTPS on;
        fastcgi_param HTTP_SCHEME https;

        access_log /var/log/nginx/seahub.access.log;
        error_log /var/log/nginx/seahub.error.log;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
    }

    location /media {
        root /home/seafile/cloud/seafile-server-latest/seahub;
        # include /etc/nginx/mime.types; # <--- UNCOMMENT THIS IF CSS FILES AREN'T LOADED
    }
}
53.  sudo ln -s /etc/nginx/sites-available/seahub /etc/nginx/sites-enabled/seahub
Now we can configure Seafile to autostart every time the Raspberry Pi is booted.  Enter the following into the file /etc/init.d/seafile-server and save it.

54.  sudo nano /etc/init.d/seafile-server
#!/bin/sh

### BEGIN INIT INFO
# Provides:          seafile-server
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts Seafile Server
# Description:       starts Seafile Server
### END INIT INFO

# Change the value of "user" to your linux user name
user=seafile

# Change the value of "script_path" to your path of seafile installation
seafile_dir=/home/seafile/cloud
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log

# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=true

# Write a log message with date and time
echo -e "About to perform $1 for seafile at `date -Iseconds`" >> ${seafile_init_log}
echo -e "About to perform $1 for seahub at `date -Iseconds`" >> ${seahub_init_log}

case "$1" in
    start)
        sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
        if [ $fastcgi = true ];
        then
            sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi >> ${seahub_init_log}
        else
            sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
        fi
    ;;
    restart)
        sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
        if [ $fastcgi = true ];
        then
            sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi >> ${seahub_init_log}
        else
            sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
        fi
    ;;
    stop)
        sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
        sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
    ;;
    *)
        echo "Usage: /etc/init.d/seafile-server {start|stop|restart}"
        exit 1
    ;;
esac

55.  sudo chmod +x /etc/init.d/seafile-server
56.  sudo update-rc.d seafile-server defaults
57.  sudo reboot

If you've done everything correctly, when the Rapberry Pi reboots you should be able to login using the URL https://seafilepi:8001  You'll get a warning about an untrusted certificate.  You can ignore this, it's because you used a self-signed certificate which is unknown to your web browser.

Next download and install the Seafile client for your device(s).  When you run Seafile you'll be prompted for a server address.  If the device will ever only access Seafile from inside your home network, you can enter the address of "https://seafilepi:8001"  However, if the device will access Seafile from outside your home network, then enter the address of "https://myddns.com:8001" where "myddns.com" is the DDNS for your home network.

As this point you're almost done.  The last step is to connect to your wireless router and enable port forwarding.  You must forward TCP port 8001 to the Raspberry Pi.  I can't tell you how to do this because every router is different.  But once you complete these step you should be able to sync to/from your personal Seafile server both inside and outside your home network.  Enjoy and good luck!

Wednesday, August 5, 2015

Water saving - the results

I recently posted about California's latest drought and water usage.  In that series I mentioned two simple changes I made at home to save water, I installed High Sierra low-flow shower heads and the HydroRight dual-flush toilet conversion kit.  It has been several months since I installed those products so I wanted to report back on how much water we are saving.

  • In the 6 months before installing these products, my family used an average of 173 gallons of water per day.
  • In the 3 months after installing these products, my family used an average of 115 gallons of water per day.
  • That's an average savings of 58 gallons of water per day.

Saving 58 gallons of water per day may not sound like a lot, but it adds up quickly.  Over a year we'll save approximately 21,000 gallons of water.  That's more water than an average-sized backyard swimming pool.

Here is a graph showing our water usage over the past 9 months.  As you can see the first 6 months are clearly higher than the last 3 months.

As far as cost savings, we saved an average of $11.85 on our monthly water bill.  The new shower heads and toilet products cost about $160 to install them in my house.  At that rate it will take 13 months to break even, and after that we'll save about $140 a year.


There were a couple of details about my water bill and usage that are worth mentioning.  Anyone who knows about water usage knows that 115 gallons of water per day for 4 people is extremely low.  That's an average of less than 30 gallons per person per day, but most places use between 100 and 200 gallons of water per person per day.  So how is ours so low?  There are two reasons.
  1. The biggest reason is the fact we don't have to water our landscaping which is the single largest use of water for a typical home.  In our neighborhood our landscaping and yards are watered by the HOA, so that watering goes on their water meter and not mine.  On the plus side, our neighborhood uses reclaimed water for landscaping so we're not wasting good water just to have a green lawn.
  2. My family has always been good about saving water, even before installing these products.  For example, we never took long showers and we didn't always flush the toilet for just liquids (as the saying goes - "If it's yellow, let it mellow. If it's brown, flush it down").

When I started this endeavor I wasn't sure how much water we would save.  I knew we were frugal with our water to begin with so I wasn't expecting much.  But to save almost 60 gallons of water per day definitely exceeded my expectations.  I hope that seeing our results has encouraged you to try water saving in your house.

Thursday, July 23, 2015

Costco and Pepsi

I'm doing my happy dance right now!  I just got back from the Costco food court and they now serve Pepsi!  I can't tell you how pleased I am.  Literally there is no Coke product I like.  I can tolerate Sprite, but that's it.  But Pepsi, I like most every Pepsi product.

As a life-long Pepsi fan, it's nice to see a large establishment serving Pepsi.  Most stadiums, events, restaurants, etc. all serve Coke.  So this is a win for Pepsi, which is a win for me too.

Reading online, I guess this is a change that has been in the works for years.  Going back to 2013 Costco signed a new deal with Pepsi, ending a 27 year agreement with Coke.  But it was a gradual phase-out taking several years.  My local Costco made the switch recently.

Monday, July 20, 2015

Emulating a Raspberry Pi using Qemu on Windows

The Raspberry Pi is a fun little computer great for small projects or just tinkering.  Sometimes you might want to try something "virtually" before doing it on a real Raspberry Pi.  That's where Qemu comes in.  Qemu is a small, free, and open-source emulator that can run Raspberry Pi software such as Raspbian.  There are multiple guides on the Internet on how to do this (e.g. here and here), but unfortunately I had a lot of problems getting these to work.  I was getting a lot of errors following these guides.  But with a lot of trial and error I was able to figure out the exact steps necessary to successfully emulate a Raspberry Pi. using Qemu running on Windows.  This guide should work on pretty much any version of Windows.  Also, this guide assumes you have at least some Linux knowledge.  For example, I'm going to assume you know how to run the Linux utility 'nano.'

First step is to download the necessary files.
  • Download the 64-bit version of Qemu for Windows, or the 32-bit version of Qemu for Windows.  Please note, and this is very important, I'm using Qemu version 2.3.0 dated April 24th 2015.  There are newer versions of Qemu available; however, in my experience the newer versions don't work because they are missing necessary files.  The version I'm using is known to work, try a newer version at your own risk.
  • Download the latest version of the Raspbian image.  At the time of writing this the latest version is May 5th 2015.  Newer versions (once released) should work the same.
  • Download the Qemu Raspberry Pi kernel.

Next, install Qemu on your system (or use a tool like 7Zip to "extract" the EXE contents into a folder of your choosing).  Unzip the Raspbian image into the same folder as Qemu.  I renamed the file from "2015-05-05-raspbian-wheezy.img" to just "raspbian.img."  From the Raspberry Pi kernel unzip "kernel-qemu" and place it into the Qemu folder.

Now you're ready to run Qemu for the first time.  Unfortunately getting the Raspberry Pi emulation to work properly is a process that requires multiple initial reboots and configuring.  But once you complete this process, the emulation works correctly from then on.

Begin the emulation with the command:
qemu-system-arm.exe -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda raspbian.img
This will start in a maintenance mode.  We need to make some changes to the image before we can start it up normally.
nano /etc/ld.so.preload
There's a single line in the file, comment it out by placing a '#' at the beginning.  Save the file, then create a new file as follows:
nano /etc/udev/rules.d/90-qemu.rules
Type the following into this file:
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"

Save the file and exit nano.  Then type "exit" to end the emulation.

Now is a good time to expand the Raspbian image.  By default the image is 3GB in size.  In this tutorial we'll expand it by adding 5GB for a total size of 8GB.
qemu-img.exe resize raspbian.img +5G

This command will generate some ominous warnings, but as long as the command ends with "Image resized" then it was successful.  Now it's time to start Raspbian normally.
qemu-system-arm.exe -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda raspbian.img

During the boot, fsck will generate an error and the boot process will stop at a terminal prompt.  Here's the key step which I found missing from all other online tutorials, you need to rerun the above 90-qemu.rules step.
nano /etc/udev/rules.d/90-qemu.rules
Type the following into this file:
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"

Note that during this part the keyboard is in English UK configuration.  If you try and type doublequotes (") it won't work.  To type doublequotes press shift+2.

Save the file and exit nano.  Then type "exit" and the boot process will resume.  When the Raspbian configuration screen comes up, select Finish to exit.  Type "sudo reboot" to restart Raspbian.  Note that Qemu does not support rebooting a VM, instead it just powers down.  So after Qemu closes, use the above command to rerun Raspbian.


Login using the standard pi / raspberry as the username and password.  Then run:
sudo ln -snf mmcblk0p2 /dev/root

Now we can run the Raspbian configuration utility. by running "sudo raspi-config"  Select "Internationalization Options" and then "Change locale."  Place a check by "en_US.UTF-8 UTF-8."  Again, select "Internationalization Options" and then "Change time zone."  Linux handles time zones differently than Windows.  Instead of selecting your time zone by name or UTC offset, you instead select a region and a city near you.  So for me I select Americas and Los Angeles.  Finally select "Internationalization Options" one more time and then "Change keyboard layout."  For me I selected "Generic 104 key" and "English US."  This step is important as the default keyboard layout is English UK with things like the pound sterling symbol.  Lastly, select "Expand Filesystem."  Reboot to expand

After this Raspbian will be configured and ready to go.  It's a good idea to run "sudo apt-get update" and "sudo apt-get dist-upgrade" to update your image.  From my experience X (the graphical desktop) is very slow and hard to use.  But if all you want to do is terminal stuff this is a great way to emulate a Raspberry Pi.  Also, don't expect to be blown away by speed, even on a fast desktop computer.  The emulator runs about the same speed as a real Raspberry Pi, maybe even a little slower than.

As I said, I figured all this out through a lot of trial and error.  So hopefully someone else finds this useful.  Enjoy, and happy emulating!

Friday, June 26, 2015

Product Review - HydroRight Dual-Flush Toilet Conversion Kit

As a part of my recent interest in conserving water in the midst of California's worse drought ever, I decided to install dual-flush conversion kits on our toilets.  There are at least 4 different brands of dual-flush conversion kits on the market, but I went with the MJSI HydroRight HYR460.  This kit is actually two products in one, the HydroRight HYR271 dual-flush converter and HydroClean HC660 toilet fill valve.  In addition to being sold on Amazon, you can buy these kits locally at Home Depot and Lowes.  There are at least 3 versions of these kits, the difference being the flush actuator.  One has push buttons, the second has a a hanging flush level, and the third has a standard looking flush lever.

These dual-flush conversion kits are a class of products that I had no idea existed.  I assumed if you wanted a dual-flush toilet that you would have to buy an entirely new toilet.  In a typical home the toilet is the single largest use of water, so making your toilet more efficient goes a long way to saving water.  This kit saves water in 3 ways.
  1. On average 4 out of 5 flushes are liquid/paper only - solids only account for 1 in 5 flushes.  The toilet does not require as much water to flush liquids, but with a standard toilet there is no way to account for this.  With this kit you can select small flushes for liquids and paper, and a large flush for solids.  The water savings here are obvious.  You can expect to save between 1 and 2 gallons of water each time you use a small flush in place of a large flush.
  2. The second water savings is harder to explain.  Inside you toilet tank is a fill valve (a tall tower with a float attached to it).  The fill valve has two jobs; it refills the tank when the toilet is flushed, but it also refills the toilet bowl.  Think of it this way, when you flush the toilet all the water in the bowl goes down the drain, yet the next time you use the toilet there is already water in the bowl before you sit down.  That water got there because of the toilet fill valve.  The problem with standard fill valves is the tank takes a lot longer to fill with water than does the bowl.  Once the bowl is full, water keeps flowing into the bowl until the tank is completely full.  But the bowl can only hold so much water, so all the excess water literally flows over the trap and down the drain.  Because you can't see this water going down the drain, very few people know this even happens.  And we're not talking about a small amount of water either.  I recently measured a real toilet and it was wasting just shy of half a gallon of water per flush.
  3. The final way this kit helps to save water is by fixing leaks.  On average leaks account for 15% of all water use inside a home, and the toilet is going to be the single largest source of these leaks.  This kit replaces all the parts inside a toilet that typically leak so it should prevent further leaking.

In case you can't tell, I'm a big fan of this dual-flush kit.  The water-saving potential is very high.  I wish I could recommend everyone install these on their toilets... but I can't.  There are just some issues that keep me from blindly recommending it for everyone.  Allow me to explain.

First, you need to know this kit won't fit all toilets.  If your toilet tank has a 3" opening into the toilet bowl this won't work.  Also, if you're existing overflow tube inside the tank is shorter than 6", it won't work.  Now the good news is 99% of all toilets do meet these requirements.

Beyond that, there are issues with the installation.  Here is a picture of the kit installed on one of my toilets.  This single picture shows most of the issues with this kit.
  1. The first issue is space.  I have 1.6 gallon low-flow toilets, which means the tank is smaller.  As you can see the blue fill tower (left) is very close to the actuator button and not far from the overflow tube (middle).  This makes putting your hands down into the tank for installation difficult.
  2. The flush button is blocked by the toilet lid when the lid is raised.  So if you're sitting on the toilet and need to flush then you must lean forward to move the lid to be able to flush.  Again this is because our toilet tank is a smaller low-flow tank.
  3. When raised the toilet lid comes to rest on the flush button and not the porcelain of the tank itself.  Since the button is plastic my prediction is in a few years of kids raising the toilet lid that the button will break.  Fortunately you can buy just a replacement button, but still.  Again, this is because we have a low-flow tank that causes this.
  4. It's hard to see in the picture, but the water level is at the very top of the overflow tub (middle).  I had to adjust the water level as high as it would go, plus adjust the small flush as large is it would go just to get liquid-only flushes to work.  And even then, sometimes liquid flushes don't properly flush.  Solid flush always works, but sometimes the liquid flush doesn't properly swirl the water and go down.  Yet again, this is caused by the smaller size of our low-flow tanks.  [Update: I eventually got the small flush to work 100% of the time, but I had to buy a new taller overflow tube at the hardware store, installation of which required the toilet tank to be removed.]
  5. Adjusting the kit is not a simple process.  There are 5 separate adjustments that need to be made to the kit during installation; 1) the height of the fill valve, 2) the float level height, 3) the small flush size adjustment, 4) the full flush size adjustment, and 5) the amount of water send to the bowl from the fill valve.

Because of these issues, I cannot recommend this kit for everyone.  Here's what I would suggest.  If you currently have a low-flow toilet, buy just the HC660 toilet fill valve - that is unless you're determined to make the full kit work (I was and once it's working properly it's great).  If however you currently have non-low-flow toilets then buy the full kit.  Many of the problems I ran into were because I installed this kit onto low-flow toilets, so if you don't have low-flow toilets then you should definitely install the full kit.

You might be asking, how do I know if I have a low-flow toilet of not?  There are several easy ways to tell.  First, just look at the toilet.  If the tank is about the same width as the toilet seat then chances are it's a low-flow toilet.  If the tank is noticeably wider than the seat, then most likely you have an older non-low-flow toilet.  You can also look inside the toilet tank.  There's a good chance the size of the toilet is stamped in the porcelain inside.  If it says something like "1.6gallon" then that's a low-flow toilet.  Lastly, look for a date stamped in the porcelain inside the toilet tank.  If your toilet is dated 1994 or newer then it must be a low-flow, but if it's older than 1994 then chances are it's not a low-flow.

Finally I wanted to give a few tips on the installation of this kit should you decide to install it.
  1. The dual-flush base is held in place with a zip-tie.  I read a review online that said his zip-tie broke after several months.  And I can see why, the included zip-tie is thin and flimsy.  Before installing this kit do what I did, cut this zip-tie off and replace it with a new larger zip-tie.  I used the largest zip-tie I could find that fit through the holes.
  2. The aforementioned dual-flush base is installed by pushing it down onto the overflow tube.  When tightening the zip-tie, push down on the base harder than you think would be necessary.  The first time I installed this kit that seal was leaking so I had to remove everything and start over.
  3. The dual-flush unit has two adjustment levers, blue for the liquid flush and green for the solid flush.  If your toilet is a low-flow toilet then push both of these adjustment levers all the way down before installing the unit.  If your toilet is not a low-flow toilet, then push both adjustment levers to the top or near the top.  After installing the entire kit you'll need to adjust these some more to fine tune the kit for your specific toilet.  But these are good starting points depending on what type of toilet you have.

Although this dual-flush kit is not perfect, once the kit is installed and properly configured it's great!  Not only are we saving a ton of water, but toilets are actually flushing better than before.  Before installing the kit our toilets would clog on average 3 or 4 times a month.  In the 2 months since installation our toilets have not clogged once.  I think this is because of how the dual-flush kit works.  How well a toilet flushes is dictated by two main factors; the amount of water and how fast that water is delivered.  This kit delivers the same or less water as before, but I believe the design delivers the water quicker.  Older flappers are hinged so when they raise up water can rush into the opening from 3 of the 4 sides.  But the dual-flush kit uses a valve that raises straight up which means when the toilet is flushed water can rush in from 360 degrees around the opening.  It's this faster delivery of water is why I believe our toilets flush better.

Well there you go.  My review of the HydroRight dual-flush toilet conversion kit.  A great product that saves a lot of water and money, but may require patience when installing and adjusting.

Thursday, June 18, 2015

Product Review - High Sierra Shower Head

As a part of my recent interest in conserving water in the midst of California's worse drought ever, I decided to install low-flow shower heads.  I think when a lot of people hear the phrase "low-flow shower head" they cringe.  But they shouldn't technology has come a long way.  First, a little history.

In 1992 the US government mandated that all new shower heads can release at most 2.5 gallons per minute (GPM) of water.  Before that, shower heads might release as much as 5 GPM.  Since then, 99% of all shower heads sold in the US are 2.5 GPM shower heads.  Anything less than 2.5 GPM (even 2.4 GPM) is considered to be a low-flow shower head.  As a result the term "low-flow" when applied to shower heads can be very ambiguous.  Unless you specifically bought a low-flow shower head, your current shower head is most likely a 2.5 GPM design.

But there is a reason why people hate low-flow shower heads - prior bad experiences.  In the mid 90s many shower head manufacturers started releasing low-flow shower heads in the 1 - 2 GPM range.  But all they did was take their existing 2.5 GPM shower head designs and put a flow restrictor in them to reduce the amount of water.  The problem is, a shower head designed for a certain flow and pressure does not operate well at lower flow and pressure.  So people who tried these shower heads got turned off to low-flow shower heads.  The good news is, shower head technology has come a long way since them.  Most manufacturers have gone back to the drawing boards and created new shower heads designed to operate at lower flow rates.  After reading online reviews of many of these shower heads I decided to purchase a High Sierra 1.5 GPM shower head.  This is my review of that shower head.



In short, this shower head is awesome and everyone should consider installing them today!  Yes, this shower head is no looker, but what it lacks in style it more than makes up for in performance and quality!  When I first installed 2 of these shower heads in our house, we were amazed because it was giving us a better shower than our previous 2.5 GPM shower heads.  The water pressure felt higher and it was an overall better shower.  I actually had to check water flow to make sure, our previous shower head was delivering 2.3 GPM and the new shower head was delivering 1.5 GPM.  [Side note: there are two reasons the old shower head was slightly below the rated 2.5 GPM; 1) many of the shower head holes were plugged and 2) when I removed the old shower head there was a piece of plastic in the shower head arm that was partially blocking the flow.]  So the High Sierra shower head saves 1 gallon of water per minute and still delivers a great shower.  This makes the math easy.  If you take a 10 minute shower then you'll save 10 gallons of water.  Multiply that by 365 days in a year and the number of people in your house and you can see the savings quickly add up to some huge numbers!



There are dozens of low-flow shower heads out there, but the High Sierra shower head is different than all of them, and it's those differences are what make this shower head shine.  Most shower heads deliver a shower of water by having dozens or hundreds of small holes through which the water is forced.  But these tiny holes become plugged with debris, mineral deposits, and mold.  The High Sierra shower head is different, it has a single large opening which can't plug, but still spays out the water in a very satisfying spray.  Another great benefit is the construction.  Most shower heads are plastic or thin stamped metal, some even contain moving parts.  The High Sierra shower head on the other hand is machined out of a single block of metal.  Even though it's small in size it is heavier than most shower heads.  You can tell this shower head is quality and will last a long time.

Did you know that all shower heads sold in the US are made in China or Taiwan?  All except the High Sierra shower head.  This product is machined and assembled completely in California - in fact as the name implies it's from the foothills of the Sierra-Nevada mountain range.

Installing a new shower head is so easy that anyone can do it - it's literally a 3 step process.
  1. Unscrew the old shower head.  You might need to use pliers if it's tight.  Clean the shower head arm threads to remove any debris that might be on them.
  2. Add about 6 wraps of teflon tape around the shower head arm threads in a clockwise direction.  This step is optional, but recommended as it helps to ensure no leaks.  Teflon tape is cheap, about $1 at any hardware store.
  3. Hand screw the new shower head into place.  You don't need to use pliers to attach the new shower head, hand-tight is sufficient.


Even though I love this product, there are two things that keep it from being an absolutely perfect product.  The shower head is slightly louder than our previous shower head.  I would by no means describe the shower head as "noisy."  Just that it makes a little more noise than our previous shower head.  The second issue is if you install the shower head onto a tub/shower combo, depending on how your tub faucet and shower head are plumbed the shower head might make a slight whistling noise when filling the bath tub.  As the water passes through the tub faucet it pulls air through the shower head pipe which causes a whistling noise in the shower head.  This process would affect all shower heads, but given the single-orifice design of the High Sierra is what causes it to whistle.  The noise is slight, and it only happens during bath tub filling.


If you consider purchasing a High Sierra shower head, they make two flow levels; 1.5 GPM and 1.8 GPM.  Some people might be tempted to get the 1.8 GPM since it's closer to the 2.5 GPM they currently have.  But I would discourage this.  My parents installed a 1.8 GPM in their house and the difference between the two is almost unnoticeable, in fact if anything the 1.8 GPM delivers too much water and the pressure might be too high (causing a slight pins and needles feeling).  I would only recommend the 1.8 GPM in two circumstances.  First if your house has very low water pressure (45 PSI or lower) or if your shower head is really high up, like beyond your reach high, like 8' - 10' in the air high.

If you decide to buy a High Sierra shower head and you order directly from the manufacturer, try the coupon code "WATER"  This code allowed me to save 10%.  Of course I can't guaranty this code will still work in the future, but it's worth a try.

Monday, June 1, 2015

California's Water - Detecting and fixing leaks

In this ongoing series on water use and the drought in California, I wanted to next talk about detecting and fixing water leaks inside your home.  Last time I talked about water usage inside the home and how leaks are one of the largest "uses" of water in a typical home.  Now this is a typical or average home.  Many homes won't have any leaks, some will leak a lot - but an average home approximately 15% of all water use inside the house is wasted through leaks.  In this post I want to show how easy it is to locate and detect these leaks as well as fix them.

First step to detecting and fixing leaks is very easy and very obvious.  Simply walk around your house (inside and out) and look at every faucet, shower head, water fixture, etc. looking for a leak.  If it's leaking, make sure the knob was in the off position.  If the leak does not stop, if you have to tighten the knob with a lot of force to get it to stop, or if the leak resumes later on then chances are you need to replace the seals.  Almost all faucets and fixtures in the house use rubber seals, O-rings, and gaskets to create a water-tight seal.  But these rubber pieces don't last forever.  In time they crack and become brittle and hard causing them to not seal completely.  There is great news however.  You can buy new replacement rubber parts for cheap and easily install them.  Most major hardware stores have a section dedicated to rubber parts like these, and they usually only cost a few bucks.  Here's how to repair simple leaks like this:
  1. Turn off the nearest water supply valve.  If the bathroom sink is leaking, under the sink are two shutoff valves (hot and cold).  If there is no shutoff valve, or if the shutdown valve itself is the part that is leaking, you'll have to shutoff water to the entire house.  This can be done outside where the water comes into your house.
  2. Use tools (usually a wrench and/or screw driver) to disassemble the leaking part.  Fixtures are designed to be taken apart and have their rubber parts serviced, so if this step seems difficult then stop and use Google and/or youtube to search for your particular job.
  3. Once you've removed the old rubber parts, take them to your local hardware store and find the identical replacement part.
  4. Install the new, turn on the water and check for leaks.
Most hardware stores also sell large packages with dozens or hundreds of random sized rubber seals.  You can always buy a package like this (again, only a few bucks) and most likely have the part on hand thus saving you a trip to the hardware store while water is turned off.

After checking all the easy fixtures like faucets and shower heads, time to check the toilets.  Toilets are probably the largest source of leaks in the house, and therefore important to check them for leaks.  They leak so much water for several reasons.  First, if a leak develops people rarely realize because the leaked water is not visible.  If does not end up on the floor, or seen dripping from a faucet.  Instead it silently leaks into the sewer line.  Secondly, toilets are considered "gross" by most people, they don't want to touch them, so unless there is an obvious problem they will leave them alone.  Finally, a lot of people don't really know how a toilet works so they don't even know how to check a toilet for leaks.

Checking a toilet for leaks is fairly simple.  Only check a toilet that hasn't been flushed in hours, that way you don't misdiagnose a leak.  Start off by using a flashlight and shining a light on the water in the toilet bowl.  Get down on your hands and knees to look closely at the water.  If the water is perfectly smooth that's good, but if you see ripples on the water, especially at the edge where the water meets the porcelain then you probably have a leak.  The next check involves lifting the lid on the toilet tank.  Don't bother looking inside the toilet for leaks, often times the air in the top of the tank is so moist that water condenses and forms drops that may appear to be a leak.  Instead, get your ear close to the water fill tower (usually on the left-side of the tank) and carefully listen for water.  If you hear water then you most likely have a leak.  But probably the easiest check is to put dye tablets (or food coloring) into the toilet tank.  Check the toilet several hours later and see if the color appeared down in the bowl.  Fixing a toilet leak is as easy as a faucet.  Turn off the water, remove the rubber parts that are leaking, and replace with new parts from the hardware store.  Or better yet, buy the dual-flush conversion kit and replace all the rubber seals at the same time.

But what if you have a leak elsewhere?  What about pipes underground or in the walls, leaks in your appliances like dish washer, or irrigation system.  How do you check these for leaks?  Turns out there's a simple way to check for leaks - use your water meter.  This method will tell you if there is a leak anywhere in your house and give you an indication how large the leak is, but it won't tell you what is leaking.  So it will either give you piece of mind, or let you know you need to keep looking.

First, locate your house water meter.  Usually the water meter is located out front your house where your property connects to the municipal water supply, but it can be closer where the water enters the house, or even inside your garage or basement.  Here is a picture of my actual water meter.

Every water meter will be different, but most meters have 3 parts to them.  The first is a small triangle or star (I've highlighted mine in green), which is the low-flow or trickle indicator.  The second part is the needle which sweeps the entire gauge.  Lastly is the "odometer" reading in numbers.  The way a water meters works is the flow of water turns the low-flow triangle.  After X number of turns of the low-flow indicator, the needle will make one complete revolution around the dial.  For each revolution the odometer reading will advance a single digit.  My water meter measure cubic feet of water, but yours could measures gallons, or even something else like liters.

The important part here is the low-flow indicator, the rest you can ignore.  The low-flow indicator, as the name implies, is very sensitive to even small amounts of water flow.  Try it, watch your meter and turn on the garden hose.  That triangle will spin pretty fast.  To check for leaks using the low-flow indicator, first make sure no one in the house is using water.  Make sure no one will turn on the sink, flush a toilet, etc.  Also, make sure there's no laundry going, the ice maker won't turn on, etc.  Basically, all water use needs to stop during the duration of the test.  Look at the position of the triangle, then wait 5, 10, 20 minutes - the longer you wait the better.  After waiting look at the triangle again.  If the triangle moved then you have a leak.  How much it moves is also an indicator of the size of the leak.

Tuesday, May 5, 2015

California's Water - Inside the home

Last time I talked about water use outside the home.  This time I wanted to talk about water use inside the home.  Fortunately, this has been studied a lot of the years.  There have been a number of studies on the subject of water use inside the average American home, and they all show the same breakdown.

The exact percentages don't matter as every home will be slightly different.  What's important is the relative sizes of each.


Toilet
Did you know the toilet is the single largest use of water in your house?  I sure didn't.  But this means anything you can do to make your toilet more efficient will go a long way to saving water.  I recently found and installed two products in my toilets that will greatly reduce the amount of water used.

1) New fill tower
The fill tower is what adds water to the tank after each flush, but it also adds water to the toilet bowl so the bowl has water waiting for your next "deposit."  But the design of most fill towers wastes water, as much as half a gallon per flush.  The part that fills the bowl, it can't shut off until the tank is full.  But once the bowl is full the extra water flows over the trap and into the sewer.  So with each flush you're wasting water and you don't even know it.  This new fill tower has an adjustment that allows you to fill just the right amount of water for your specific toilet.  And it only costs $10, a real deal.

2) Dual flush conversion
The say 4 our of 5 flushes is for liquids.  Obviously "solids" need more water to flush down, but liquids could use much less.  Wouldn't it be nice if you could tell the toilet a small flush or a large flush?  Well with this product you can.  This conversion kit has two buttons, one for liquids and one for solids.  So you can select the right size flush and save tons of water.  This kit only costs $35 and includes the above fill tower.

I believe in this product so much that I plan on writing a followup post to talk about this product, installation, etc.


Shower
After the toilet the shower is the next largest use of water in a typical home.  Well over 95% of all shower heads sold in the US deliver 2.5 gallons of water per minute (the federally mandated maximum).  A new low flow shower head will easily cut water usage.  For example, a 1.5 GPM shower head will save a gallon of water per minute.  So a 10 minute shower per day saves 10 gallons of water per day.

I think a lot of people are afraid of the words "low flow shower head."  But they shouldn't be, the technology has gotten much better!  I recently installed a High Sierra shower head (1.5 GPM) and it's a better shower than we got with out old 2.5 GPM shower head.

As with the toilet products, I'll do a follow up post and review of this shower head.


Laundry
Washing clothes is another large use of water in the home.  But here's a place where it's not as easy to save water.  Obviously you can do things like only was full loads.  Beyond that the only way to save water is to buy a new high-efficiency front-load washing machine.  Not everyone is willing or able to spend money on a new washing machine, which makes other simple changes like toilet products and low flow shower heads more important.


Faucet
The faucets in your house use about as much water as the shower and laundry.  There are two simple ways to save water at the faucet.  First, turn off the water when not in use.  This sounds obvious, but it's not always so.  If you're brushing your teeth, turn off the water while you brush.  If you're washing dishes, turn off the water while you wash.

The second tip is to install new faucet aerators.  These are inexpensive cartridges that screw into most faucets.  Most likely your faucets currently have them, you can replace them with lower flow models.  A standard aerator delivers 2.2 GPM, so if you install 1.5 GPM you'll save 3 quarts of water per minute.  Aerators are cheap and easy to install.  Best of all new aerators will probably perform better than your current ones because these get corroded and crusty over time.


Leaks
Leaks in a typical house account for significant water use.  I'll cover detecting and fixing leaks in a separate post.


Dishwasher
The dishwasher is one of those appliances that people think use a lot of water, but in reality uses very little.  In other words they are very efficient.  A regular dishwasher uses only 6 gallons of water per wash cycle.  A high-efficiency model uses about 4 gallons per wash cycle.  So buying a new dishwasher is probably not cost effective to try and save water.  But there are several tips that can help.  First, only hand wash items that can't go in the dishwasher.  Because the dishwasher is so efficient you'll most likely use more water (and soap) hand washing dish.  Second, run the dishwasher when it's full, don't run partial loads if possible.

Tuesday, April 28, 2015

California's Water - Residential

In this series on California's water crisis I've talked about both environmental and agricultural uses of water.  This time I want to talk about water use in the home, after all this is where you and I can save water and make a real difference.

Before I can detail some ways to save water around the house, it's important to understand where water goes in a typical home.  From a high level standpoint we can make two distinctions, outdoor and indoor water use.  Studies of water use of a lot of different homes have found that in a typical American home 75% of all water use is outdoors - the bulk of which goes to landscaping.  So if you want to save the most water start on the outside of your house.

Below is a list of a lot of great tips to save water.  Some of these are easy and cheap to do and others are expensive and/or hard to do. It's up to you to do what you can to save water - so even if you pick the easy ones you're still helping the overall crisis.
  • Reduce the amount of watering done on your landscaping.  Water for shorter periods of time, water every X number of days, etc.
  • Water at the optimal time of day, usually early in the morning before the heat and wind of the afternoon.  This minimizes loss due to evaporation.
  • Use drip irrigation lines where possible.
  • Install and use timers on your sprinklers.  This eliminates the hassle of having to remember to turn it off and on, allows you to control exactly how much water is being used, and helps you to control what days and times watering occurs.  In other words, it's a win all around.
  • Use a soil moisture meter and only water when the ground needs it.
  • Consider installing drought tolerant landscaping.  After all, the grasses, bushes, and trees most of us have in our yards are not native to California and require EXTENSIVE amounts of water to keep it alive.
  • If you use a hose to wash off the exterior of your house, sidewalks, and/or driveways then use other methods such as a cobweb duster and broom.

Another great tip is to avoid washing your car at home and instead use an automated car wash.  But beware, not all car washes are created equal.  Those small units attached to gas stations can use as much, or more, water compared to a typical home car wash.  The key is to find a place that exclusively does car washes and uses water saving practices.  Such a place will recycle water between washing, as well as filtering out oil, dirt, and detergent to keep them out of the sewer and storm drains.  Unfortunately there really isn't a way to tell if a car wash does all this or is actually using more water than washing at home.  You can always ask or check their website - but they may not say.  Barring that I would suggest using the newest dedicated car wash you can find.  Newer facilities will have to comply with newer ordinances about water use so you're more likely to find a place that will save water.  Another tip, "touchless" car wash machines use more water than a conventional car wash.  So don't be afraid of a conventional car wash machine - after all if you wash at home don't you touch your car?


In the next post I'll cover water use inside the home.

Thursday, April 16, 2015

California's Water - Agriculture

Last time, in this series on California's drought, I talked about the distribution of California's water and how "environmental" uses get 50% of all the water.  This time I'll talk about the next largest allocation of water in California which is agriculture.  Agriculture uses 40% of California's water leaving only 10% for urban use.

[Note: Sometimes this statistic is reported as 80%.  When this happens they choose to ignore the 50% of California's water that is not diverted for man's use.  Whether it's 40% agriculture / 10% urban or 80% agriculture / 20% urban the statistic is the same, a 4:1 ratio.]

Some people, especially people in California who are required to conserve water, will get annoyed that agriculture gets so much water.  If only farmers would use less water then there would be plenty for the rest of us.  It's my hope to defend the farmer and enlighten the average person on this situation.

Obviously those farmers are not just wasting the water, they are using it to grow food.  The same food you and I eat in the grocery store.  And when I say "we" I'm talking about everyone in the US and a large number of people in the world.  Whereas the midwest grows tons of corn and grain, the vast majority of fruits, vegetables, and nuts are grown in California.  Here is a very small partial list of the largest crops grown in California.
  • Peaches
  • Plums (and prunes)
  • Grapes (and raisins)
  • Figs
  • Apricots
  • Strawberries
  • Apples
  • Oranges
  • Nectarines
  • Dates
  • Kiwi
  • Lemons
  • Melons
  • Tomatoes
  • Broccoli
  • Cauliflower
  • Carrots
  • Onions
  • Garlic 
  • Celery
  • Mushrooms
  • Lettuce
  • Artichokes
  • Peppers
  • Avocados
  • Olives
  • Asparagus
  • Almonds
  • Walnuts
  • Pistachios
If you live in the US and you eat these foods, chances are it came from California.  Many of these items are grown almost exclusively in California.

In addition to the above, California is the second largest grower of cotton.  Also, California produces 90% of all the wine made in the US.

Oh, and let's not forget things like milk, beef, chicken, eggs, sheep (and wool), pork, and turkey.  Yep, you guessed it, California produces the majority of that as well.


In these lists, did you see anything you enjoy eating?  Chances are the majority of the food you eat, regardless of where you live in the US, comes from California.  So hopefully you see the importance of the agriculture sector and giving water to farmers.  Without water for California farmers everyone's food would be significantly more expensive!


Ok, so farmers are important - but do they have to use so much water to grow our food?  Well believe me when I say that farmers have long been doing EVERYTHING they can to cut water use.  When growing food is your job, and water is scarce and expensive, you do everything possible to make the most of it.  If you think your water bill is high, image the water bill for a farmer!  They buy their water by the acre-foot.  Several decades ago 1 acre-foot of water might have cost $50.  Now that same acre-foot of water might cost $300, $500, even as high as $1000.  This is why, long ago, farmers switched to drip-irrigation systems, smarter watering practices, changing crops to those that require less water, using reclaimed water, etc.

So it is true that agriculture uses 4 times as much water as urban uses here in California, but hopefully you understand the importance of that water and believe that farmers are doing everything they can to make every last drop count.

Next time I'll finally talk about water use in the home.

Friday, April 10, 2015

California's Water - Distribution

In this second post on the subject, I wanted to talk about how Califnoria's water is distributed.  One thing you can definitely say about California, because water is such a precious commodity water is heavily studied, tracked, and reported on.  Knowing where water is going and how it's being used are the first steps in conserving it.  Below is a graph showing the breakdown of all water that falls in California in the form of rain and snow.


The first thing you'll notice is the largest piece, a full half of the water supply, is "environmental."  What exactly is that?  Environmental is my blanket term for what all the surveys break down into smaller categories.  This is basically water that is NOT captured or used directly by man.  This is water that is allowed to remain in streams, pass through dams, flow into lakes, estuaries, wetlands, and the ocean.

At this point you're probably asking yourself, if there is a water crisis why isn't California capturing and using this half of the available water?  The answer to that is more political.  Because of federal, state, and local regulations this water must be allowed to flow free - whether that's to preserve native habitat, help with an endangered species, etc.  Some people get very emotional on this issue - after all is a fish really worth preserving when we're running out of water?  I don't want to get into a political issue here and take sides either for or against these environmental regulations.  But I will say that the issue is far more complex and, like many things in life, the answer is a balance.

We cannot simply take all of the water for our use and the environment be dammed (no pun intended).  We need the environment more than people realize.  Wetlands filter pollutants and debris out of water.  Trees and forests clean the air.  And this is to say nothing about the recreation from going to the forest, lakes, rivers, etc.

Even though this "environmental" piece accounts for half of the available water in California, consider this water off the table when it comes to conservation and California's water issue.  In the next post I'll look at the next biggest piece of the pie - agriculture.

Wednesday, April 8, 2015

California's drought and water issues

Anyone who has watched the news lately knows that California is in the middle of a severe drought.  Now before you say to yourself "I don't live in California, this doesn't affect me" - I implore you to continue reading as this does affect you.  Anyway, I was born and raised in California, so drought is nothing new to me.  Over my lifetime California has always been in and out of drought.  That said, this one is by far the worst I've seen.  I don't know if it's the scope, the severity, or the longevity of this drought, but over the last 2 years I have seen reservoirs drying up that have never dried up during previous droughts.  Put simply, our available water is disappearing!  That should alarm you.

Because of this, I am taking this matter very seriously.  Everyone, especially us in California, needs to conserve water, and I fear most other people aren't taking it as seriously as they should.  Either that or they don't know what or how to act.  After all, Governor Jerry Brown mandates the state consume 25% less water, but I haven't seen a single tip, guideline, or rule on how to consume less water.  So I wanted to blog a whole series about water usage and, more importantly, how to conserve water.

In this first post I wanted to talk about how and why this affects you, even if you don't live in California.  Hopefully this will encourage you to save water where ever you are.  I can think of 4 great reasons why everyone should conserve water.

1.  Water is a resource, just like electricity, food, and oil.  There is a finite amount of it, so anytime we frivolously waste it we're only hurting ourselves.  Clean fresh water may be plentiful where you live today, but that may not always be the case.  Large swaths of the USA are prone to droughts, so adopting water conservation now is in your best interest.

2.  Cost - pure and simple.  Clean fresh water costs money, usually in the form of a monthly water bill.  But it could come in the form of an electric bill to operate a well, in which case there is also the hidden cost of digging deeper wells when the water table drops.  If you conserve water you will save money, period.

3.  California's drought affects everyone when you buy groceries.  As someone who grew up in California's central valley, I know why the state is referred to as "the nation's bread basket."  The vast majority of vegetables, fruits, and nuts are grown in California.  Take for example almonds - California grows 99% of the almonds in the USA, and over 92% of the almonds in the whole world.  The plains of the midwest primarily grow grains like wheat, corn, and barley.  But everything else primarily comes from California.  So a drought here very much will affect your food prices regardless of where you live.

4.  Most people who live west of the Rocky Mountains share the same water supply with California.  California's water does not just come from California.  Some water flows down from Oregon.  But thanks to the Colorado river, rain/snow that falls as far away as Wyoming, Colorado, and New Mexico can end up in California.  So the more we all conserve the more we all benefit.

Hopefully this first post at least encourages you to take this drought seriously.  In the coming days and weeks I'll post more on what you can actually do to help conserve water.

Read the next post about water distribution.

Wednesday, March 4, 2015

C++ virtual destructors

Several times recently in other people's code I have run into a problem with virtual destructors - specifically the destructors are not "virtual."  Now to be fair, this is a mistake I have made myself in the past, so I am not just being overly critical of other people's code.

I think a lot of C++ developers do not understand when or why to use virtual destructors.  And admittedly virtual class functions are one of the more difficult parts of C++ to understand.  So let me simplify it and make it easy.  ALWAYS MAKE YOUR DESTRUCTORS VIRTUAL!  Unless you truly understand what you are doing it is hard to think of a scenario where you would want a non-virtual destructor.  Having virtual destructors will not hurt, but non-virtual destructors will cause problems, usually in the form of resource leaks.  Let us look at an example:
class CBase
{
public:
    CBase() {}
    virtual ~CBase() {printf("Base class");}
};

class CDerived : public CBase
{
public:
    CDerived() {}
    virtual ~CDerived() {printf("Derived class");}
};

This is the simplest possible base and derived class you can have.  Now let us look at 3 different ways of using these classes:
CBase *p1 = new CBase;
delete p1;

CBase *p2 = new CDerived;
delete p2;

CDerived *p3 = new CDerived;
delete p3;

So what happens in this code depending on if CBase and/or CDerived have virtual destructors?

Scenario 1: No virtual destructors
In the first delete the CBase destructor is called, which is correct.  In the second delete only the destructor for CBase is called, which means cleanup for CDerived did not happen (resource leaks).  In the third delete both destructors were called, which is correct.

Scenario 2: CBase has a virtual destructor but not CDerived
In the first delete the CBase destructor is called, which is correct.  In the second and third deletes both destructors were called, which is correct.

Scenario 3: CDerived has a virtual destructor but not CBase
In the first delete the CBase destructor is called, which is correct.  In the second delete it actually results in a heap corruption.  Most of the time this heap corruption will not result in a crash, which is actually worse.  It will lead to random sporadic bugs that are hard to track down.  In the third delete both destructors were called, which is correct.

Scenario 4: Both classes have virtual destructors
In the first delete the CBase destructor is called, which is correct.  In the second and third deletes both destructors were called, which is correct.


Both scenario 2 and 4 work without issue, but 2 is potentially dangerous because another class may derive from CDerived in which case problems will not occur.



Similarly, say you are writing code that extends the functionality of another class outside of your control.  For example, you wish to extend a class from an SDK.  Only derive from a class that has virtual destructors.  I often times forget to check this, which is where I got bit in the past.  Older versions of Microsoft's STL implementation had non-virtual destructors.  But what do you do if you have an SDK class that does not have a virtual destructor?  Simple, instead of deriving your class from that class, make what would be the base class into a class member variable.  For example, instead of doing this:

class CDerived : public CBase
{
public:
    CDerived();
    virtual ~CDerived();

protected:
};

You would do this:
class CDerived
{
public:
    CDerived();
    virtual ~CDerived();

protected: 
    CBase m_base;
};

This is effectively the same thing, but avoids the problems caused by non-virtual destructors.




So to sum up, always make your destructors virtual!  Also, always make sure the classes you derive from have virtual destructors and if not then do not derive from them.  Some compilers will warn you about these conditions, but not all.  I wish more compilers warned about this condition.

Hopefully this helps C++ developers of all skill levels out there.

Thursday, January 22, 2015

How to secure your home WiFi

These days most people have a home wifi network, yet it's my experience that very few people (even technically minded people) know how to properly and completely secure their wifi network.  So here is my guide to securing your home wifi network.

First, I'll briefly cover why you should secure your home wifi.  There are multiple reasons, all of which revolve around protecting you and your privacy.
  1. Keep others (like your neighbors) from freeloading off your Internet which you pay for.
  2. Keep the data on your network from prying eyes.  Even if an attacker doesn't use your network to access the Internet they can still monitor your network in hopes of grabbing things like credit card numbers.
  3. Protects you from possible lawsuit.  Suppose someone uses your wifi and downloads illegal material.  Since they did it using your network you could be held liable for their actions, even though you didn't know it was happening.
  4. Keeps you safer from viruses, malware, trojans, etc.  Suppose your neighbor is stealing your wifi and they get a virus - since they're on your network now you're more vulnerable to getting infected.

So here are my top 17 recommendations of things to do to protect yourself and securing your wifi network.  Since every router is different I can't tell you exactly how to implement the following, you'll need to research your specific model.
  1. Buy your own wifi router.  Many times the ISP (e.g. ATT, Charter, or Comcast) will give customers a free wifi router.  These are almost garbage and should not be used.  First off their router is likely to have security holes in it, and the manufacturer is not likely to publish an updated firmware fixing the problem.  Also, some ISPs have a feature whereby they turn your home wifi router into a "wifi hotspot" for anyone else who's a customer.  So other people might be sharing your connection with your ISPs permission, and there's nothing you can do to disable it (yes it's an isolated network so in theory they can't access your files, but it still uses your bandwidth and electricity).  So I recommend ditching their free wifi router and buying your own.  If their wifi router is integrated with the modem (a.k.a. a gateway) then look in the settings for a way to disable the wifi access point and add your own router.
  2. Update the firmware of your router.  Good router manufactures release updated firmwares from time to time that add new features and (most importantly) fix security issues.  So check for an update and install it if available.
  3. When buying a router, use a well-known and trusted manufacturer.  If a manufacturer makes a lot of routers, chances are they have worked out the security flaws in the operating system of the router whereas that no-name manufacturer may have lots of issues.  Probably the biggest router manufacturers are Asus, Belkin, Cisco, D-Link, Linksys, and Netgear.  Of these, I personally prefer Netgear, Asus, and D-Link.
  4. Enable the strongest wifi security available to you.  WEP is awful, don't use it.  WPA is good, but WPS2 is better.  TKIP is okay, but AES is stronger.
  5. Disable WPS (Wi-Fi Protected Setup).  This feature (which might go by other names) is a convenience feature where you press a button on the outside of your router then you can connect a device without having to input your wifi password.  It can be convenient, but there is a well-known security flaw in the design that allows an attacker to gain access to your network in a few short hours.  So disable it!
  6. Disable access levels and points you're not using.  If all your devices are 5GHz then disable the 2.4GHz band. If all your devices are wireless-N, then disable wireless-A/B/G.  The idea is to minimize the ways in which someone could try and access your network.
  7. Disable remote administration.  Most routers allow you to remotely login to them via the Internet.  Chances are you don't need this feature, so disable it.
  8. Consider disabling wifi administration.  Most routers allow you to enable/disable the ability to login to and mange the router from a wireless device.  Assuming you have at least one wired computer connected to the router, then disable this feature.  Anytime you need to manage your router, do it from a wired connection.  In the event someone hacks into your network, this at least keeps them from gaining access to the router itself.
  9. Enable HTTPS login for the router management and disable HTTP.  Many routers allow you to login to the router management via HTTP and/or HTTPS.  Don't use unsecure HTTP and always use HTTPS (the S stands for Secure - literally!).
  10. Check port forwarding and DMZ, and disable unless necessary.  All routers offer features like port forwarding and DMZs.  Close any you're not using as each of these is one more security risk.
  11. Use firewalls on all computers and devices within your network.  This helps protect your computers in the event your network is compromised.
  12. Use long complex passwords everywhere.  This includes your router login, the wifi network password, and the DSL login (where applicable).  The longer the better, the more random the better.  Use a password generator if necessary.  The password "myDSLaccount" is easy to crack whereas "zcXZadF0SmIZCspqw9vG9CUf1aj6NYOa" is hard to crack.
  13. Change passwords from time to time.  Maybe once a month.  If someone hacks in, if you change the password you'll lock them back out.
  14. Record all MAC addresses for the hardware you own.  Any good router will show you the devices connected to it, but most of the time it's just a MAC address (10:23:E3:F6:03:1A).  Unless you've taken the time to figure out all your devices and their MAC address(es) then you won't know if someone else is on your network.
  15. Do not use hidden SSIDs.  This used to be a recommended security practice.  But this does nothing good, and in fact has negative side-effects.  Any would-be hacker will be using tools that shows him all wifi networks, regardless of hidden SSIDs or not.  So don't fool yourself into thinking you're safe.  But they've also shown that hidden SSIDs also reduce the battery life of your portable devices because the device is constantly having to verify the hidden network is in fact the one it thinks it is.
  16. Don't put personal info into the SSID.  Don't have an SSID of "StephensWiFi" or "375PalmAve."  SSIDs like this compromise your personal info and/or give away your location.  If someone wants to hack into your network, don't make it easier for them.
  17. If you have friends and family visiting, enable the guest SSID(s), use a strong password, and give them access to the guest account.  This keeps them off your main secure network.  If you're not expecting friends or family, then disable the guest SSID.  Again, expose as few of avenues of attack to hackers as you can.

With security there is always a trade-off.  One the one hand there is convenience, on the other is security.  Rarely do they overlap, which means if you want your home network to be more secure, ultimately it will be less convenient for you as the user.  But once you accept this fact you can secure your network and enjoy piece of mind.