Could you repeat that?

After a few weeks, working on and off, I’ve almost completely implemented an event calendar that supports repeating events.
 
In my previous update, I mentioned looking at an iCal implementation (which didn’t meet my needs), as well as finding a forum that laid out the groundwork for implementing recurring events in a database. However, I stumbled upon a much simpler solution:
 
A pseudo-cronjob implementation (forum link).
 
From the link above, I would have 3 fields/objects:
 
events (maps an id to the event name, start time, and array of dates)
event-dates (maps a date to an array of id’s)
endlessEvents*
 
*Note: Not yet implemented. Will end up storing a pattern for identifying whether an event falls on a particular day.
 
For events that have a definite end date (either after a number of occurrences or on a specific date), I enumerate all the dates that event would fall on and add the event ID to the specified date(s) in the map of event-dates.
 
If I need to delete an event, I would just need to get the ID and iterate over the map, removing the ID wherever found.
 
If I need to edit an event for a particular day, I would clone the event but give it a different ID, remove the old ID from the event-dates map for that particular day, and add the new event ID.


All that’s left to implement for the calendar is:

  • Endless event pattern matching
  • Editing / Removing an event
  • Modifying the implementation of “ends after x occurrences” to “ends on (date)”

After that, it’s just a short step to implement a checklist displaying what events are happening today. Then I get to play with PhoneGap to try and convert it to an Android / iPhone app.

Automatically updating version control!

There is no logical reason why I am THIS excited about getting my post-commit hook working. But I am! Now when I commit changes from my working copy, the post-commit hook will automatically update the working copy in the folder serving the “beta” sub-domain.
 
In order to get the post-commit hook working with svn, I had to create a small C program (as recommended by the official documentation). I copied it (modifying the paths), compiled it via SSH on my web host and tested it through SSH and found it to work successfully. However, when I made a commit, the post-commit hook failed with exit code 255 with no output.
 
I double-checked my permissions on the C program and tried again, but still the same error. I then tried commenting out the call to the C program and added a simple “whoami >> [path]/whoami.txt” to see who was executing the post-commit hook.
 
Post-commit hook failed with exit code (255) and no output.
 
Ok, NOW we’re getting somewhere. Whatever user account that’s trying to access the post-commit hook script can’t even access the script. I tried chmod-ing the repository, recursively, to 777 (read/write/execute for all) and did another commit. SUCCESS! I found a “whoami.txt” file, but surprisingly, it was my login (which had permissions to begin with).
 
Un-commenting the line that executes the C program to update a different working copy, I made another commit. This time, I started getting meaningful failure messages. The first message stated an authentication failure, so I modified the C program to include my username and password and recompiled it. Another error but this time it was due to requesting interaction (“are you sure you want to overwrite…”). Modified the C program one last time, adding the no-interaction flag, compiled and tested one last commit.
 
Bingo!
 
No error messages and the beta section of the website was updated automatically!
 
In short, to get the post-commit hooks working with svn I needed to:
 

  1. (via SSH) CHMOD -R 777 [path to repo]
  2. Create the following C program:
    #include <stddef.h>
    #include <stdlib.h>
    #include <unistd.h>
    int main(void) {
       execl("[path to svn executable]", "svn", "update", "[path to WC to update]", "--non-interactive", "--username", "[username]", "--password", "[password]",(const char *) NULL);
       return(EXIT_FAILURE);
    }

    Note: MUST have blank line at the end (at least my gcc compiler complained about the lack of one the first time). The code formatter above removes it.

  3. Upload the C-source to my website and compile
  4. (via SSH) CHMOD +s [compiled C-program]
  5. Since my host is a linux host, create a file in the “hooks” directory of the repo named “post-commit”
  6. Add the following two lines to the “post-commit” file:
    #!/bin/sh
    [path to repo]/hooks/[compiled C-program]
  7. Test the post-commit hook by performing a commit

Version control is here!

As the title suggests, version control is finally here! (somewhat)…
 
After doing a lot of research and fiddling with my website via SSH, I managed to set up a subversion repository hosted by my website. I previously tried experimenting by installing Git, but was unable to get it to compile successfully (probably due to permission issues in place on a shared hosting provider, although others on my hosting provider managed to get it working, it involved editing a lot of configurations in the config file, as well as messing with some lines in Makefile).
 
Since I’m still relatively new to subversion (but not version control as a concept), I’ve only activated it for my beta web apps that I’m working on. I didn’t want to try to set it up for my whole website, not knowing how subversion would work with wordpress and having different branches checked out and posting new updates via wordpress and having to commit them to the repository and such (or make an update with my working copy, commit it, only to have it potentially overwrite something I did in wordpress). Yeah, I could probably get around it by always doing an update before committing, but I may not always remember to do that, and frankly, wordpress is doing just fine w/ its own version control so I don’t really NEED it for my entire website.
 
With this version control system in place, I no longer need to (nor will I) make backups of the projects I’m working on by simply copying the directory somewhere else and appending “01”, “02”, etc… to the end of it.
 
Can’t wait to get back to focusing on development rather than part development, part “I better copy this in case I screw it up and can’t figure out how to get it back to the way it was”

Side Projects – Update

To update on the side projects I’ve been working on:

Medication Reminder – What was tried:

 
I tried using jQuery iCalendar but couldn’t figure out how to get it to actually display a calendar or link it to a calendar (it appears it’s only for converting an event into an iCal format) so I decided not to go down that route.

Medication Reminder – What has worked:

 
I’ve had a large amount of success using jQueryUI’s Datepicker (now rolled into jQueryMobile 1.4). Since the intended platforms are mobile devices and intended use is for medication reminders, for those that take a lot of medications, having individual visible events on a calendar would either extend the cells of the calendar or overflow on top of the days below it or be cutoff all together resulting in not all the “advertised” information being displayed, I opted to just color the cell in the calendar if there was SOMETHING for that day. Then, when the user click on that day, a window pops up detailing what all is to be taken that day, and if in the past, when the medication was actually taken.
 
By using the “beforeShowDay” option, I can check to see if there are any medications to be taken that day and set the highlight class as necessary. I also realized that since the class name the beforeShowDay option expects is just a string, I could have multiple classes like: “highlight big-date” (trivially) to highlight the date on the calendar and make the date number really big.
 
With this, I got the idea to include the date itself as a “class” so I could quickly pick the EXACT DOM element for a specific date and perform other DOM manipulations using jQuery (e.g.: if mobile device, do nothing special, but if desktop browser / tablet / sufficiently large display, inject medication name / time).
 
With the “medication-event” rendering problem solved (mostly), I’m now focusing on how to store the “medication-events” in a (relatively) small and robust manner (similar to iCal), specifically as it relates to recurring events. I’ve drawn a lot of inspiration from Google Calendar as far as how to present the input of a “medication-event” (“if it’s not broken, don’t fix it” and “don’t reinvent the wheel” come to mind) and from this thread on webdeveloper.com on how to store the “medication-event”. It has also provided some insight on how to render the recurring events as well as how to handle exceptions (e.g.: take daily at 7 am, except on weekends take at 9 am).
 
One other feature I implemented at the last minute to the “Add event” form is adding an auto-complete functionality for the medication name input. Not knowing what’s “common” prescribed medications, I just took a list from needymeds.org and modified the auto-complete to display the suggestions in a scrollable window (to prevent it from “breaking” the flow of the input page). An added benefit is that the brand names are included so the user can type either the generic / chemical name or the brand name and still find the medication (hopefully).

Medication Reminder – What remains:

 
Once the “medication-event” handling is complete, I’m ready to merge the calendar and the easy “one-touch taken medication” features and move on to packaging the web app in Phonegap to be able to leverage the native notification / popup features of Android/iOS.
 
You can view the event calendar at: http://beta.bradleymize.com/cal/
You can view the “one-touch taken medication” feature at: http://beta.bradleymize.com/pills/