PHP strftime on Windows is stupid

Thursday 01/8/2009  –  Category: Uncategorized  –  No Comments

Apparently %e, %T, %R and %D (there might be more) don't work on Windows because "not all conversion specifiers may be supported by your C library".

Workaround: You can add the # flag to force single digits and remove the leading zero without the space that %e will add.

Examples:
%#d for day of the month
%#I for the 12-hour clock hour

lastfm_jzting

Ok, so this requires that you have a Last.fm account with recorded data...if you don't, you can just admire my pretty graph.

LastGraph lets you create really cool stacked graph of your listening habits.  Just stick in your Last.fm username and you can generate a timeline poster based on a certain timeframe.

LastGraph is inspired by Lee Byron's What have I been listening to? project.  More information on stacked graphs and academic paper can be found on Lee Byron's site.

Count unique records with DataMapper

Saturday 01/3/2009  –  Category: Uncategorized  –  No Comments

dm-aggregates provides an aggregate method that allows for "multiple aggregate functions to be used in a single query, with automatic grouping when :fields is specified"

Hit.aggregate(:ip_address).length

Will yield the number of unique IP addresses in the hits table.

stats

It didn't occur to me until a day or two after I released Flickr Original that I should probably record usage stats, so I added a few lines of code to track views/downloads. Earlier this week I finally decided to do something with all the data. I decided on a simple line graph to trend views/users/downloads and a counts summary table (inspired by the one from the Flickr stats page).

For the line graph I initially looked at gruff but ended up using the Google Chart API in conjuction with mattetti's Googlecharts gem because it seemed easier to use (and no need to install RMagick/Imagemagick).

The Googlecharts gem basically takes in parameters and generates the url that creates the image.
Gchart.line(:data => [0, 40, 10, 70, 20]) generates:
http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc which is this generated image:

The parameters you can use are pretty self-explanatory from the usage examples. I also wanted to add point markers and gridlines (a la Google Analytics), which have to be added as custom params. You can do this by setting the :custom hash to a query string with the extra variables (see the Chart API docs for all the options...there are a lot!) .

Code snippet:

Generates:
flickr stats

Custom Parameters
Line style
chls=
[data set 1 line thickness],
[length of line segment],
[length of blank segment]

chls=3,1,0 creates a solid line 3px thick

Gridlines
chg=
[x axis step size],
[y axis step size],
[length of line segment],
[length of blank segment]

chg=14.29,50,1,4 creates gridlines of 1px line segments spaced 4px apart with a step size of 100/7 on the x-axis and 100/2 on the y-axis. This gives us gridlines for each day and a halfway marker for the counts.

Markers
chm=
[marker type],[color],[data set index],[data point],[size],[priority]

o = circle, 0 uses the current data set, -1 to draw a marker on each data point

chm=o,0066FF,0,-1,6 creates blue 6px circle markers on each point of the current set

Ranges in Ruby (and .. vs …)

Saturday 01/3/2009  –  Category: Uncategorized  –  1 Comment

Ranges in Ruby are nifty: you can define a set by its start and end values and a range of values will be generated.  This works "as long as the objects can be compared using their <=> operator and they support the succ method to return the next object in sequence."

Ranges created with .. will include the last value while those created with ... will exclude the last value.  The syntax for this isn't the most intuitive, I had to go back to the docs to make sure I was using the right form.

A simple example:

(1..10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


(1...10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]

Date ranges using Merb and DataMapper:
(make sure to add the dm-helpers dependency for Rails-like date/time helpers)

yesterday = (Time.now-1.day).to_date
today = Date.today
@views_yesterday = Hit.count(:type => 'view', :created_at => yesterday..today)

Will yield all hits of type view that were created yesterday.

 Page 8 of 14  « First  ... « 6  7  8  9  10 » ...  Last »