jakeasaur.us

Design Principles

Published Sunday, May 24 at 22:07 GMT

A few years back I found these while researching and had scribbled them down without a source, reference, name, URI or anything. They never see daylight stuck in my moleskine so I decided to share. If anyone knows where these are from, I would be delighted to properly cite.

  • Principle of least astonishment
  • Common things easy, rare things possible
  • Consistency
  • Law of Dementer
  • Subtraction
  • Simplicity over generality
  • Reflexivity
  • Independence
  • Once and only once

SQL Bitmask

Published Thursday, May 14 at 04:53 GMT

The Boolean is the simplest of the data types, until your working with millions of records and need to be able to add booleans easily. Our geek ancestors solved this problem by using the low level value of Integers as an array of true/false flags rather then a binary representation of a number.

Lets say we have three possible options each having a binary value:

              CHEDDAR = 0001
              SWISS   = 0010
              CURD    = 0100
              GRUYERE = 1000
              

Lets plugin a little boolean algebra and order a couple burgers:

              new_burger(CHEDDAR | SWIS)
                 0001 Cheddar
               | 0010 Swiss
                 0011 Cheddar & Swiss
              
              new_burger(SWISS | GRUYERE)
                 0010 Swiss
               | 1000 Gruyere
                 1010 Swiss & Gruyere
              
              new_burger(CHEDDAR | SWISS | CURD | GRUYERE)
                 0001 Cheddar
                 0010 Swiss
                 0100 Curd
               | 1000 Gruyere
                 1111 Cheddar & Swiss & Curd & Guryere
              

Now testing for a value is a simple comparision. Lets test if we asked for cheddar or gruyere on the first burger.

                 0011 Cheddar & Swiss
               & 0001 Cheddar
                 0001 > 0 == true
              
                 0011 Cheddar & Swiss
               & 1000 Gryuyere
                 0000 > 0 = false
              

We can also perform the same comparisons in SQL which we can use to build a Sphinx index. You can also query by the comparison, however I can’t imagine it would be very effective on a large scale.

              sqlite> CREATE TABLE burgers (cheese_bitmask smallint);
              

Add Swiss & Gruyere burger

              sqlite> INSERT INTO burgers VALUES (10);
              

Is there a burger with Swiss?

              sqlite> SELECT COUNT (*) FROM burgers WHERE (cheese_bitmask & 2) > 0;
              1
              

Is there a burger with curd?

              sqlite> SELECT COUNT (*) FROM burgers WHERE (cheese_bitmask & 4) > 0;
              0
              

And there you have it, bitmasks in your SQL. I have only tested this in MySQL and sqlite3, I would think all databases support bitwise operations, although the & (and) and | (or) operators may be different.

Git Commits To Push

Published Tuesday, May 12 at 01:10 GMT

If your local branch is ahead of a remote branch Git can quickly tell you which commits differ between the two.

              git log master ^origin/master  
              

And there you have it, your pending commits waiting to be pushed.

Googled from coderrr.

Feed Mail

Published Sunday, Apr 26 at 23:45 GMT

Since converting to linux I have been rethinking how I work. Feeds take up most of my time and for the past four months I have been hunting for the answer. It wasn’t until after setting up my own email server when I realized feeds are nothing more then a mailing list.

Solution: Write a script to pull new entries from feeds, parse the content, generate a multipart html/text email from the entry html and the parsed content.

Fetchmail then pulls my email into my mail spool allowing dovecot to deliver messages to my IMAP data store, filtering with Procmail.

Instantly I can view my feeds from any IMAP client from mutt to the iPhone. IMAP clients capable of displaying HTML content show the entry, otherwise the plain text is shown.

Entry tags, flags, triggers and the like all centralized with the power of IMAP.
What’s in your wallet.