Flickr is one of my favorite web applications. Often times, instead of building a photo uploading utility for small web sites I am working on, I will simply integrate the clients’ Flickr account into their website, using RSS and the Flickr API. Here’s how I do it.
Get the RSS Feed
require ‘rss’
require ‘net/http’
require ‘rexml/document’
@flickr_rss [...]
25 Feb
by: Matt in Development, PHP
tags: garbage collection, memory leak, php
Been working on a command line script that takes days to finish execution (yes, DAYS). Unfortunately, it had a healthy flow of memory leaking. It would fatally crash with your typical “out of memory” error.
I spent hours debugging the potential source – free’d results of mysql queries, unset variables, you name it I tried [...]
Very simple error_log viewer…
<?php
$fname = "./error_log";
if(file_exists($fname)) {
if($_REQUEST['mode'] == ‘del’) {
unlink($fname);
} else {
$contents = file_get_contents($fname);
?>
<div style="margin-bottom: 1em;"><a href="?mode=del">Delete error_log</a></div>
<?php
echo nl2br($contents);
}
} else {
echo ‘No Errors!’;
}
?>
12 Feb
by: Matt in Development, PHP
tags: php, serialize, session, unserialize, var_export
The ability to transfer data from one executing script to the next as components of a web application is of the utmost importance. Sometimes the objects in transit can grow in size to 10’s of megabytes of data. Nested classes, arrays of smaller classes, arrays of data, indexes, etc.
I’ve been on a pretty [...]
Came up with this snippet while writing a Rails log file parser. It will take any number of seconds and convert it to Xm Xs format (which was useful for my display purposes):
def convert_seconds_to_time(seconds)
total_minutes = seconds / 1.minutes
seconds_in_last_minute = seconds – total_minutes.minutes.seconds
"#{total_minutes}m #{seconds_in_last_minute}s"
end
convert_seconds_to_time(630)
=>”10m 30s”
I didn’t [...]
Started
……………………………………………………………………………………………
Finished in 1702.88777 seconds.
105 tests, 369 assertions, 0 failures, 0 errors
08 Feb
by: Matt in Development, PHP
tags: ob_flush, ob_implicit_flush, php
I write a lot of administrative scripts that have rather long execution times. Often it’s desirable to be able to monitor the progress of the script in the browser, in realtime. By default I have my PHP installation setup with gzip output buffering enabled. This reduces the size of data transmitted to [...]
I always lose this snippet of code, which will run RCov for all your controllers and models, and output the results to the /public folder of your Rails app:
>rcov test/functional/*.rb test/unit/*.rb –output=public/rcov –rails
There are certain situations where you want a periodically executed script to have one and only one instance running at a time to prevent against poisoning of data due to simultaneous execution.
There’s actually an extremely simple way to accomplish this in a PHP environment by taking advantage of mySQL’s built in “lock” functionality.
The following simple [...]
Matt’s post below got me thinking about how I would accomplish the same thing in Ruby, turning an array into a string with each element separated by a comma. Here’s what I came up with.
array_of_strings = ["foo", "bar", "foobar"]
str = array_of_strings.collect{|a| a + ", "}.to_s.chop.chop
=> "foo, bar, foobar"
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.