Barton's Picture linux counter image.

Barton Phillips Blog

Leave me a comment about our site or something you are interested in.

Date: 2013-06-17

Do NOT Text and Drive

Why is it so difficult? Every phone today has GPS so the phone knows when it is moving and how fast. Phone companies and manufacturers should change their phone software so when the phone is moving at car speed the phone can not make or receive calls until the phone is not moving for two minutes. The phone can take incoming messages and prompt the owner that there are messages once the phone is not moving. Some newer high end cars have this feature in their navigation and phone systems but not enough. It really would not be that hard to do. Reply

Date: 2012-12-03

How to create dynamic script tags with PHP or JavaScript using a data-uri

I have made a demonstration of how to create script tags using data uri's. The demo also show how to make dynamic iframes.

The demo is dynamicscript.php and describes the features. The JavaScript requires a browser that supports blobs and the URL.createObjectURL() function. Firefox and Chrome support these new HTML5 features. I have no idea if Internet Explorer suports these or not.

Please feel free to comment on this demo.


Date: 2012-11-12

Resize a large image using Javascript and localStorage

There are times you would like to use an image that is not on a server where you can use server side code to re-size the image. For example there is this nice picture of the mountains but it is 3,000 pixels wide by 2,500 pixels hight and the file-size is almost 2 Meg. Sure you could do <img src="reallybig.png" width="500">. But you are still loading 2 Meg over the Internet even though your image is only going to be 500 pixels wide.

By using some JavaScript code and localStorage you can re-size the image once and cache it in localStorage as a base64 URI. The base64 URI will be maybe 500,000 bytes or less. Sure your browser would cache the 2 Meg image and the second time you load the page it would be faster than the first, but you are still moving 2 Meg from the cache instead of 500k.

I have written a little example program that illustrates how to do the re-sizing. The program is localstorage.html. Take a look. If you have Firefox or Chrome you can use Firebug or Chrome's Development Tools to watch the load process the first time and subsequent time. You will notice a big difference in how long it takes to load the page.


Date: 2012-10-25


I installed the APC ES 550G UPS to my Linux Mint 13 desktop. I got the 'apcupsd' package via the repository and had it all up and running within a half hour. Get the 'apcupsd', 'apcupsd-cgi' and the 'apcupsd-doc' packages via apt-get or synaptic. Then edit the /etc/apcupsd/apcupsd.conf file. Change UPSCABLE to usb and UPSTYPE to usb. You can change times etc. if you want but it is not necessary to get things going. Look at the rest of the stuff in /etc/apcupsd just to get an idea how everything works. You might want to comment out the FIELD UPSTEMP "UPS Temp" "" in multimon.conf as this device does not seem to support tempreture. You will also need to edit the /etc/default/apcupsd and change ISCONFIGURED=no to yes. Then you can start the daemon by 'sudo invoke-rc.d apcupsd start' (or 'sudo /etc/init.d/apcupsd start'). You can use your browser to check the status by going to 'http://localhost/cgi-bin/apcusbd/multimon.cgi'.

I have my computer and my wireless router plugged into the UPS. I tested it out by pulling the UPS plug and sure enough the power stayed up and the power outage was logged in my syslog, an email was sent to 'root' and the multimon.cgi reported the outage. I plugged the UPS back in and the event was logged on all three: email, syslog, multimon.cgi.

All in all the APC UPS seems to work just fine. The status log (/var/log/apcupsd.status) shows an UPS load of only 26% and predicts 27 minutes of UPS power. With only 26% load I may plug my phone answering machine in to the UPS also so I don't have to reset the clock every time we have a brown-out.

For $59.99 from this seems like a perfect fit for my home system. I understand that APC has software for Window$ if you really want to punish yourself. As always APC like most vendors could mention that the UPS works just fine on Linux and point people to the 'apcupsd' packages. But maybe APC is afraid of alienating Microsoft or maybe they just figure if someone is smart enough to use Linux they are probably smart enough to figure everything out for themselves.


Date: 2012-10-09

Some Security Tips

The "robots.txt" file has its legitimate uses but not everyone who reads it are legitimate. In many cases the file will give nefarious individuals a glimpse into your directory structure and files you didn't intend. For example if you list a directory like "admin" and have not made it unreadable either via a password or have an "index.html" file in the directory or use the "Options -Indexes" server directive, then even if there are no links anywhere to "admin" the person reading your robots.txt file knows you have that directory and may therefore be able to look at it and all the files therein.

Another thing to keep in mind when writing a web page is that anything you get via the web may be evil. For example if you have a form with an "input" box you should make sure that the input data does not contain nefarious markup. You may be asking for someone's name which you intend on displaying on the form action page. What if the person entered the following markup: <script>windows.location =</script>

If the browser rendering your site has JavaScripts enabled that little snippet would redirect from your site to another site with a big advertisement. The result could be worse depending on where the redirection goes.

This type of devilishness is not restricted to "input" boxes. Say your site gets the "HTTP_USER_AGENT" and displays it. Many browsers have html markup in the User Agent Strings. I have seen <script> tags as well as anchor tags (<a). What to do? Well it is good practice to escape all tag markers, that is less than (<) and greater than (>) symbols as &lt; and &gt;. Using PHP you could make a function:

function escapeltgt($value) {
  $value = preg_replace(
           array("/</", "/>/"),
           array("&lt;", "&gt;"), 
  return $value;

Use the function on anything that could be dangerous.