Peter's Notes

Demystifying open source

Labels

Blog Archive

Tuesday, November 08, 2011

Using an AVR ISP Mk II with the Arduino IDE

It is possible to program an AVR on an Arduino board using the AVR ISP Mk II programmer directly from the Arduino IDE. The process is faster and an Arduino bootloader is not required to be loaded on the AVR, so you can program AVRs purchased from Mouser, Digikey, etc and then transfer them to a permanent circuit board.

Simply edit boards.txt (location varies-- try searching your root arduino software folder) and add:


atmega328ii.name=Arduino Duemilanove ATmega328 AVR ISP Mk II

atmega328ii.upload.protocol=stk500
atmega328ii.upload.maximum_size=30720
atmega328ii.upload.speed=57600

atmega328ii.upload.using=avrispmkii
atmega328ii.build.mcu=atmega328p
atmega328ii.build.f_cpu=16000000L
atmega328ii.build.core=arduino

##############################################################


Then you can go to Tools>Boards> and select ATMega 328 ISP from the list. Attach your AVR ISP Mk II to the Arduino board (make sure the orientation is correct-- both of the AVR and the ISP cable). Hit program as normal. Voila!

Friday, October 14, 2011

CSS Radial Backgrounds

CSS3 allows you to make radial gradients fairly easily. Unfortunately, you need six lines to cover all the browsers that support CSS3, but luckily all but the old webkit syntax are very similar.

http://www.impressivewebs.com/css3-radial-gradient-syntax/

Full Screen Background Image with CSS

Since the height attribute doesn't work so well in CSS backgrounds (100% will not actually cause your background image to scale to the full height of the window, for example), if you want a full screen background you'll have to go another route. Luckily, this solution is written up cleanly:
http://paulmason.name/blog/item/full-screen-background-image-pure-css-code

Simply copy #full-screen-background-image and you're good to go. The styling also works for DIVs.

Monday, February 07, 2011

Google Chrome Keeps Caching Code

Google Chrome is nice for mobile apps because it has decent developer tools and can render webkit css properties (otherwise, Firefox has better debugging facilities).

What is maddening is that Chrome randomly seems to cache pages regardless of header settings. During development, pages are updated very often-- making debugging in Chrome supremely frustrating. I've only found two solutions:
  1. Reboot
  2. Append a dummy variable to the page URL (for example, myapp.com/index.php?google_sucks=1

JSLint

Lint is a tool which finds common errors in Java code. It's very handy and is usually able to find *something* you ought to fix. Well, there's a JSLint for Javascript too!
Note, it will complain about globals (like alert). You can, at the top of your javascript, put a comment and define a comma delimited list of globals to ignore:
/*global alert, console, $, $$ */

Tuesday, February 01, 2011

Admin Pages Generator

Writing pages to administer tables is a pain, even if they're basic. But no more. See the attached generator. Doesn't work for more complex stuff needing joins etc but its a good quick start.

PHP Data Access Object Generator

When coding in Java, I always used Netbean's auto generation of entity beans. In minutes you can have a couple dozen entity beans created (add the CXF generator and you get the CRUD services to access those entities also!).

With PHP, things aren't so advanced.

But, I did find a PHP script to generate DAOs for MySQL. The trouble is it comes with no documentation!

Luckily someone on devx wrote a tutorial. You do need to login, but that's what bugmenot is for.

Monday, January 17, 2011

iPhone Cookie Hell

I was having a hell of a time getting a mobile website to logout iPhone users. The website uses cookies to keep track of logged in users, and the cookies would simply not delete on an iPhone. Worked fine on Android, Chrome, Safari (on the desktop), etc. The app used the textbook method for deleting cookies in PHP, setting the expiration to a time in the past:

setcookie($usercookie, '', time()-3600);

And then redirected the user to a page with a check for a logged in user which started with;

if(!isset($_COOKIE[$usercookie])) { ... }

Which always said the cookie WAS set. Hey, I just deleted it!

After much pulling of hair, I realized that Mobile Safari won't delete cookies until the user returns from the browser to the home screen. You can ask it to delete the cookie, but those requests just seem to queue up until that return to the home screen. But, it will update their values immediately. So now my logout php looks like:

setcookie($usercookie, ''); // null the cookie value, without specifying a time, for the iPhone
setcookie($usercookie, '', time()-3600, '/'); // delete the cookie, for all other browsers

And the auth check looks like:

if(!isset($_COOKIE[$usercookie]) || empty($_COOKIE[$usercookie])) { ... }

Voila.

Monday, November 15, 2010

Constant Ink Injection System (CISS) for Canon MX860

I bought a Canon all-in-one MX860 from a Slickdeal. This printer is like a miniature version of the excellent Canon ImageClass models at work.

However, the ink ran out in no time and costs a fortune. This printer uses 5 of the CLI-221/PGI-220 ink cartridges which contain less ink than previous models. A brief history of the cartridges can be found here.

The CLI cartridges also keep track ink level unlike prior cartridges, so they need to be reset after refilling.

Three options were open to me:
  1. Refill - I would need ink, syringes, needles, and a reset tool (see this link for refilling with syringes)
  2. Purchase refillable cartridges and ink (this supplier seemed to be well regarded on nifty-stuff and the website is clear on the parts you need to order) ~$100
  3. CISS system - from reading the forums, most of these systems work, it's just that the better ones are less of a headache to setup ~$200
I could not actually find a well reputed dealer for CISS systems for Canon MX860. I found a general list here. I'm sure they exist, but in two hours scouring forums and company websites, I couldn't figure out what to buy on these sites... So I went for a kit out of Australia. Rihac was not only well regarded by the Aussies, but their web site is a dream compared to the other companies. They wouldn't take my Amex, but a Visa card worked, though it's $45 for shipping to California!

A few other tid bits I picked up:
  • Pigment based inks are better for quality, but tend to gum up the works on converted printers
  • Dye based inks aren't as good as pigment based, but less maintenance is required
  • The height of the ink tanks in a CISS is important; place them either level with the printer or raised. If they are too low, not enough ink will come out (EDIT: Do NOT raise above the print head!!! I just did this for 3 pages and my orange ink was ALL used on a long, wet smear... arg!).
  • Make sure the tubing for the CISS is not getting squeezed. Not enough ink will come out, or in the worst case, the heads will overheat.
In the USA, you can get ink to refill after the CISS runs out from Hobbicolors (on eBay) and Precision Colors.

Friday, September 17, 2010

"FriendFeed" Model Schema-Less Data Storage

Modern application developers face a challenge ill-suited to traditional RDBMS'. The data collected by applications is a moving target, with additional data points added often as applications mature. Also, many applications aggregate data from multiple sources where data points captured may differ or change beyond the control the application developer. Traditional RDBMS and the tools and checks built into those tools prefer static schemas. For example, Netbeans has a wizard to create Java entity beans from tables, but no simple way to update the entity beans when the schema changes. While creating the bean can take 5 minutes, adding a column takes hours. What's an architect to do?

One solution is to stuff an entire record into a LOB column in a traditional RDBMS (or whatever the equivalent of the LOB is in the particular RDBMS). This, however, makes indexing difficult.

Oracle has built in libraries to allow indexing and searching of XML data in BLOB and CLOB columns, but the performance is poor (though better than extracting the whole LOB and parsing it in, say, Java). Columns for indexing could be added to the LOB table, however if additional indexes are needed at a further date, the table schema must be altered.

The solution is to the indexing problem is to create separate tables for each index. Details of how this was accomplished at FriendFeed can be found here.

Note also, that if value comparison searches are not needed, a persistent hash map like Project Voldemort can be used instead.