- Friday, March 13th, 2009 at 1:08 am
I had a nagging issue that started a few weeks ago when I get a lot of email with large attachments (see my last post about emails from my aunt); when I deleted emails from my device the messages are not deleted from the server as they were with my Windows Mobile device. BlackBerry devices do not allow you to setup the mail account yourself (not to any degree of specificity anyways..), so each time I add the account, it is setup as IMAP. The issue is that when I delete items from my device, they are sent to the .Trash folder, and never deleted from the server. This becomes an issue with a small mailbox quota (mine are set to 25mb because I use POP3 on my laptop and delete the messages from the server after they’re downloaded by Thunderbird) which causes the server to reject mail when the mailbox is full.
Surely there is a simple solution, which is to raise the mailbox quota. However, all that does is allow more and more mail to pile up, which would still require me to go in and clear out the trash folder every few weeks (or days, depending on the size of the emails I receive..). So I did some searching and found a nice little snippet of PHP to tackle this issue:
<?
define('PATH', '/home/user/mail/domain.com/mailaccount/.Trash/cur/');
function destroy($dir) {
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.');
destroy($dir.$file.'/');
rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';
?>
I placed this into a PHP file in a folder above public_html (so it’s not accessible by the public) and setup a cronjob to execute this code once every hour for each mailbox that I use on my BlackBerry. This prevents the mailbox from filling up as it deletes the trash every hour and doesn’t require me to check it every so often. :)
Filed under: php, site, tutorial — Tags: blackberry, code, device, email, mail, mobile, php, site, tutorial —
- Sunday, February 22nd, 2009 at 10:10 pm
As I wrote yesterday, I recently upgraded my Wordpress install to 2.7.1. I stated at that time that all was running smoothly, and it was. Until my daily digest of tweets posted. I had discussed this with @mrheadrick briefly and never even realized that the reason he had the issue and I didn’t while we were using nearly the same code to process and post our tweet digest, we were not using the same versions of Wordpress. He was on 2.7.1, and I was only running 2.6.3.
When my latest digest of tweets posted, the time stamp was off by 12 hours. The post should have been created at midnight, and it was posted 12 hours later, at noon. This was the exact same problem that Mark was having. He had complained that he had to manually edit each post’s post date in order to display correctly. My initial thought was an error in the code of the script that creates the post, but that wasn’t the case. It was the new version of Wordpress!
I took a peek at wp-mail.php and discovered that there is some strange formatting of the time stamps. Basically, there is a lot of code used to rip the timestamp from the email apart and recompile it into the format that the Wordpress post database uses. This gets tricky when dealing with servers across different timezones so they use gmdate() instead of date() to create the stamps in GMT time. This timestamp is then converted to your local time and saved in both local time and GMT in the post database.

As you can see here, two tweet digests were posted, however, the local time is wrong on the lower one (this is the post that is 12 hours later than it should be). The GMT time is correct. The post is created at midnight (00:00) CST, which is GMT-6. So, the GMT time would be 06:00. The GMT time on both posts is the same, but the upper is 00:00 local, and the lower is 12:00 local. So what causes this?
On line 16 of wp-mail.php, there is a piece of code that looks like this:
$time_difference = absint(get_option('gmt_offset')) * 3600;
I looked into the absint() function, and found that it is used to always return a positive intiger. The problem with this is that is later on in the file, $time_difference is used to convert the timestamp to your local time. One line 130, you see this code:
$post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
Do you see the problem yet? This creates a timestamp and adds in the offset, in seconds, as defined by $time_difference on line 16. However, if you are like me and you are in the United States, your GMT offset is a negative number. This means that when you add $time_difference (a negative value) it is the same as subtracting it. But, since absint() is used to make this a positive value, so it mucks things up. Instead of subtracting the difference (6 hours) it adds the difference, creating a difference of 12 hours (midnight my time is -6 from midnight GMT, and it’s adding 6 MORE hours, totaling a difference of 12).
So, how do you fix it? Well it’s quite easy, actually. A simple edit to line 16 to remove absint() and you’re in business with the proper post times. Just replace the existing line 16 with this one:
$time_difference = get_option('gmt_offset') * 3600;
Save the file, and you’re done! Now all of your posts will have the right times, and you can go back to not the good old days of pre-2.7.1.
Filed under: php, site, tutorial — Tags: code, php, site, wordpress —
- Wednesday, February 11th, 2009 at 3:32 am
If you’re a regular reader of my blog (either via my website, Livejournal or Facebook Notes), you’ve surely noticed that I have been posting a daily digest of my tweets for that day. I tried to use a site called LoudTwitter, but despite them claiming it could be made to work with hosted Wordpress, it didn’t do a damn thing. So I tried the digest function in TwitterTools (the Wordpress plugin that I use to push new blog posts to Twitter), which also didn’t do anything. Finally I just made my own system.
I got to learn how to use SimplePie, which is great for parsing RSS and ATOM feeds, something that I don’t have a whole heck of a lot of experience with. I played around with how to display them, and decided that the visual styles that LoudTwitter uses were really nice and simple so I went with that. I then made further tweaks to the script, including making Twitter usernames into links to that users profile, as well as linking hashtags to the Twitter’s search engine. With some much appreciated help from @mrheadrick I learned about the usage of preg_replace(), and got some creative cronjobs going thanks to help from Dan@Surpass.
I’ve become quite interested in the immense power that Twitter possesses as I find more and more great uses for it. There are TONS (literally) of projects that use the Twitter API to make some really fun data sets. One of my favorites is Curse Bird, which was created by @richardhenry. I’ve also found some really neat people to follow on Twitter such as Adam Savage from Mythbusters (@donttrythis) and @woot. I’ve also noticed that when I mention someone or something, they follow me. I was talking about a new show called “One Way Out” on Discovery Channel, and the star of the show started following me. Same thing with the Foo Fighers.
So anyways, I mentioned in my last update that I had my interviews scheduled for Monday the 26th of January at 8am. I woke up at 5am and had a nice breakfast, left an hour early to make sure that I had plenty of time to get downtown, park and make it up to the 7th floor. My initial thoughts regarding how the interviews went were not too good. I had three back-to-back-to-back. The first one went ok, but not great. I didn’t feel that I was concise enough in my answers and felt my answers were hundreds of miles from the questions. The second interview went much better, and my confidence was booming after I was done. My answers flowed much better and I felt like they were received much better by the two people interviewing me. The third interview started out well enough, but it careened out of control quickly. I think it was because I knew two of the three people in the third interview prior to going in, whereas the first two were with people I had never met before. The mood was rather light at first, but it became pretty obvious that they were getting right down to business once the questions started coming out. They hit me with a few curve balls that I was not expecting at all and I had some long pauses to think of something as fast as I could. I started to get really nervous and my mouth got really dry. But I felt like I ended it well and didn’t feel like a complete failure walking out. I headed back to my store and reflected with my boss a little and it made me feel a lot better about the whole thing. I also spoke briefly with a candidate from another store going for the same position and she agreed that she was not expecting some of the questions that came up in the third interview either, which made me feel better about it.
On the following Thursday I had a feedback session with one of the supervisors in the work center I was applying for regarding my interviews. I was told that I had very strong knowledge of the job and I finished highly among the applicants. Unfortunately, there aren’t any openings right now. It’s unclear exactly what happened, as I assume there was an opening and it was either eliminated or filled by someone else. A lot of jobs were recently cut, and I don’t know if this position was involved in those cuts. I talked to my boss after the feedback session and we agreed that the whole process helped me immensely in my development, and no matter what the outcome is I will be better off having gone through the whole process.
Aside from that, I got a pretty nasty 48 hour bug in the early morning hours of the 29th of January. It started with some flu like symptoms including vomiting and fever. I woke up at 5am and threw up, and when I was taking a shower afterwards my hands started to get tingly and numb. I started breathing faster, which made it worse and eventually I started to hyperventilate which caused my whole arms to be numb and I couldn’t move my hands. Mae woke up and started to panic, and called 911. Paramedics came and checked vitals, said it was a panic attack. Took about an hour or so to get feeling back in my hands, and the flu symptoms kept me up most of the day. I didn’t eat anything for two days, and finally started feeling better on Sunday.
Work was fairly routine for the week, and I took the weekend off for my step brother Chris’ going away party. He is being deployed to Iraq for a year, so he got a shindig together at The Bierstube in Red Wing. Lots of beer was consumed, and lots of fun was had by all. Mae and I split the cost of a hotel room with Robert and Micayla so we didn’t have to drive home or try to find Chris’ house in the middle of the night. I also took Sunday off in anticipation of a nasty hangover, which never came about. There’s a fair amount of pictures up on Facebook from myself and Chris’ wife Stephanie.
Now that I’ve bored you with what is surely the longest post I’ve written in some time, I’m gonna finish watching Dirty Jobs and go to bed.
Filed under: life, twitter — Tags: bar, beer, chris, code, friends, life, mae, php, robert, sick, site, twitter, work —
- Thursday, February 5th, 2009 at 4:05 pm
What is it?
TCTraffic is a Twitter that you can follow to get updates from other folks dealing with the same issues as you are. Get real time updates of traffic situations from people who are on the scene experiencing it first hand.
How Do I Get Updates On My Mobile Device?
Start following @TCTraffic, and turn on mobile updates. That’s it!
How Do I Contribute?
Post your traffic notes to your Twitter account and be sure to include “#tctraffic” somewhere in your post. That’s it!
Questions? Want one for your area? Email tctraffic@robmonroe.net.
Filed under: php, site — Tags: code, php, site, traffic, twitter —
- Sunday, November 9th, 2008 at 5:42 am
I did some tweaking to the stats display engine that I wrote for generating my own music stats today, which now includes data about the top 10 albums by play count, play count by genre, and I improved the execution time a bit with some newly learned functions. I also squashed a bug that was causing artists or albums with “&” in their name to display improperly due to the way PHP handles “&” in URLs. Rich helped me out with that one and we got it all squared away.
I looked around at a few scripts and libraries that allow you to easily make charts and graphs from your data, but I didn’t get too far. After all the work to get things to the state they’re in now, I didn’t feel like creating another headache for myself. At least not today. But it’s on the back burner for now. I am also thinking of some sort of way to track the history of say, the top 100 tracks/artists/albums to show how their play counts change over time. The only problem with this is that I would need to sync at specific intervals, which doesn’t happen very much right now.
Anyways, with the new data that I was able to harvest, I found some interesting information regarding my listening habits:
| Genre |
Plays |
%OT |
|
Total |
%OT |
| Rock |
41,379 |
48% |
|
4,928 |
42% |
| Metal |
21,633 |
9% |
|
2,545 |
12% |
| Classic Rock |
7,962 |
9% |
|
1,412 |
12% |
| Punk |
7,440 |
9% |
|
1,558 |
13% |
| Country |
4,559 |
5% |
|
516 |
4% |
| Rap |
1,556 |
2% |
|
329 |
3% |
| Alternative |
1,160 |
1% |
|
218 |
2% |
| Pop |
683 |
1% |
|
133 |
1% |
| Industrial |
490 |
1% |
|
142 |
1% |
| Techno |
135 |
0% |
|
12 |
0% |
This table illustrates the number of plays that each genre has, and the percent of the total plays for that genre on the left; and on the right it shows how many songs there are for that genre, and the percentage of the total library that that particular genre accounts for. While it’s pretty much assumed that these two would have very similar percentages, I found it interesting that Rock takes up nearly half of all of my listening time.
http://www.robmonroe.net/music
Anyone care to share their listening habbits? I would be more than happy to run your iTunes library through my stats engine so you could have a gander. Just let me know!
Filed under: music, php, site — Tags: code, data, ipod, music, php, site, stats —
- Saturday, November 1st, 2008 at 5:26 pm
All Flickr sets, tags, and photos are fully integrated into the site. I found a really nice script called FAlbum which uses the Flickr API to include all of your photos on your site. It even includes the comments, EXIF data, AND the notes that people leave on your photos, all within your Wordpress site.
The install was super easy (although I had a few troubles getting the SEO links to work) to install, it just took a little while to get the theme tweaked how I liked it.
Relatedly, I found a very cool function in PHP called eregi(), which is a case insensitive check to see if a given string exists within a string.
PHP:
-
<?php
-
$string = 'XYZ';
-
if (eregi('z',
$string)) {
-
echo "'$string' contains a 'z' or 'Z'!";
-
}
-
?>
Particularly, I am now using this to evaluate the $_SERVER['REQUEST_URI'] variable and tell me which section of the site the user is viewing. This is what controls whether or not the navigation box for a specific section of the site appears as white (normal) or red (if you're viewing that section).
A very handy tool indeed. Anyways, enjoy the photos :)
Filed under: media, photography, site — Tags: code, flickr, photography, php, site —
- Sunday, September 7th, 2008 at 12:49 am
I've recently discovered the power of explode(), and it's a powerful little tool that anyone using PHP should know about.
PHP:
-
<?
-
$var1 = "apples oranges bananas pears grapes";
-
-
foreach($fruit AS $echo){
-
-
}
-
?>
This will result in the following output:
CODE:
-
apples<br />
-
oranges<br />
-
bananas<br />
-
pears<br />
-
grapes<br />
When using the explode() function, you fill it in in the following manner:
PHP:
-
$name =
explode("__DELIMITER__", __
$VARIABLE__);
__DELIMITER__ is what you will explode, or split by. In the example above I used " " (space).
__$VARIABLE__ identifies which string to split. This should be defined before the explode.
In the example above, I used space as the delimiter, and I exploded $var1. This will split the string at each space, and assign each split of the string to a new variable, which is defined before the explode(). In the example, I used $fruit. Each new variable is then assigned as $fruit[0], $fruit[1], $fruit[2], etc. The array starts at zero, and stops when there is no more data to split.
The second part of the example echos the array.
PHP:
-
foreach($fruit AS $echo){
-
-
}
foreach() loops through all of the items in the array, and echos the code betwen { and } for each item. In this case, each item is echoed, followed by <br />. As you can see by the resulting code, each item from the original variable is echoed nicely, on it's own line.
You can play around with different strings and delimiters, and the results are pretty much endless
For more information, view the official PHP.net page for explode().
Filed under: php, tutorial — Tags: code, php, tutorial —