Django Signals Example

signals

Have you read the Django Signals Documentation and wondered, “Okay, how the heck do you actually use it? How about an example?” If so, then you’ve come to the right place.

Will demo by example adding signals for pre_save, pre_delete to raise an exception if a READ_ONLY_FILE exists to prevent the DB from changing. Then, add signals for post_save and post_delete to print the change to stdout. Using print as an example, a more useful thing would be to write it to syslog or something – say you want to log every DB change that occurs.

Read more

Lazy Social Buttons

Lazy Social Buttons

Want social buttons on your wordpress blog pages, but you don’t want to pay the performance penalty? Try Lazy Social Buttons by Go Daddy.

The WordPress Plugin is a wrapper for the Go Daddy open source lazy-social-buttons posted on github written by LindsayD. She’s the real mastermind behind this. I merely evangelized the concept like mad, then put a WordPress wrapper on the outcome.

Read more

Go Daddy API, Example use

Very recently, Go Daddy released it’s public API that can be used with Go Daddy Cloud Servers and Easy Database. Since I’m a Go Daddy Cloud Servers customer (and employee of Go Daddy), I wanted to provide you with an example use of the API.

I had an extra server that I wanted to delete. Of course, I could do this with the GUI, but for practice, I decided to delete it with a script.

The first thing I did was grabbed a copy of the Go Daddy API for PHP, which can be found here:
https://github.com/godaddy/gdapi-php

and gave the documentation a once over:
http://docs.cloud.secureserver.net/

I then went to the Go Daddy Cloud Servers GUI and clicked the API tab, accepted the TOS, and generated an API key. It was easy, one click and my access key and secret key were provided.

I then created a file called csremove.php:

Read more

_setSiteSpeedSampleRate usage

If you’re doing a low number of pageviews (<5M / month), you can crank your GA SiteSpeed up to 100%, I think. This is a bit of a theory, need to look into it more. I'm going to crank up mine to 100% and see what I can glean from it. Note this line: _gaq.push(['_setSiteSpeedSampleRate',100]);

<script type="text/javascript">    
var _gaq = _gaq || [];  
 _gaq.push([‘_setAccount’, ‘UA-YOURNUMBER-1′]);  
 _gaq.push([‘_setSiteSpeedSampleRate’,100]);
 _gaq.push([‘_trackPageview’]);   (function () {     
var ga = document.createElement(‘script’); 
ga.type = ‘text/javascript'; ga.async = true;    
 ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js';    
 var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);   
})(); 
 </script>

There is a lot you can do with Google Tracking API. Can hardly wait to start playing with this.

Dave

Hack to make vipers-video-quicktags detect iPad and use HTML5 Video Tag

I use this WordPress plugin, vipers-video-quicktag, in a couple sites I maintain. I use it to display FLV video. I’ve found if I create .mp4 videos with the H.262 video and AAC audio codecs, it’ll play in the Flash player, as well as on iPhone, iPad and iPod. This is neat, a single video format that works on all 3.

Problem is, with vipers-video-quicktag, it doesn’t detect iPhone/iPod/iPad on the Flash video option and just tries to display it with the Flash player, which we all know doesn’t work on iPhone/iPod/iPad.

The trick is to detect iPhone/iPod/iPad and instead of putting in the Flash video, instead put in a HTML5 Video tag.

WordPress: http://wordpress.org/extend/plugins/vipers-video-quicktags/
Author’s Page: http://www.viper007bond.com/wordpress-plugins/vipers-video-quicktags/

If you know how to read a diff file, here’s how I hacked it in. Remember, this is only going to work universally, if your videos are .mp4 with H.264/AAC encoding.

# diff -Naur vipers-video-quicktags.php.orig vipers-video-quicktags.php
--- vipers-video-quicktags.php.orig     2010-05-23 22:15:11.000000000 -0700
+++ vipers-video-quicktags.php  2010-05-23 22:19:22.000000000 -0700
@@ -3663,7 +3663,9 @@
                //$content .= "// <![CDATA[\n";
 
                foreach ( $this->swfobjects as $objectid => $embed ) {
-                       $content .= '   swfobject.embedSWF("' . htmlspecialchars( $embed['url'] ) . '", "' . $objectid . '", "' . $embed['width'] . '", "' . $embed['height'] . '", "9", vvqexpressinstall, ';
+# dkhack, replace this line with HTML5 Video tag when it's iPhone, iPad, iPod:
+                       # $content .= ' swfobject.embedSWF("' . htmlspecialchars( $embed['url'] ) . '", "' . $objectid . '", "' . $embed['width'] . '", "' . $embed['height'] . '", "9", vvqexpressinstall, ';
+                       $content .= 'if ((navigator.userAgent.indexOf(\'iPhone\') != -1) || (navigator.userAgent.indexOf(\'iPod\') != -1) || (navigator.userAgent.indexOf(\'iPad\') != -1)) document.getElementById("'.$objectid.'").innerHTML = \'<video width="'.$embed['width'] .'" height="'.$embed['height'].'" poster="'.preg_replace("/\.[^\.]{3}$/", ".jpg",  $embed['flashvars']['file']).'" src="'. $embed['flashvars']['file'].'" controls />\'; else  swfobject.embedSWF("' . htmlspecialchars( $embed['url'] ) . '", "' . $objectid . '", "' . $embed['width'] . '", "' . $embed['height'] . '", "9", vvqexpressinstall, ';
 
                        if ( empty($embed['flashvars']) || !is_array($embed['flashvars']) ) {
                                $content .= 'vvqflashvars';

Basically, what it’s doing is detecting iPhone/iPod/iPad in JavaScript and writing this:

<video width="'710" height="400" poster="http://host.tld/path/to/video.jpg" src="http://host.tld/path/to/video.mp4" controls />

One more thing to note…. When I tested this with my iPad, it didn’t work at first. Something is wrong with the iPad – it doesn’t want to see the movie when it’s at it’s default location in WordPress after upload. Is there a 300 level redirect in there somewhere that iPad doesn’t like? Maybe something with .htaccess. Workaround: What fixed it for me was creating a new directory in my DOCUMENT_ROOT called “videos” and then I put symlinks in there to the physical files, and then used these http://host.tld/videos/my_video.mp4 URLs and it works fine.

Dave.

Putting a Facebook share link on your site

Putting this up as an example of how to do a share link. It’s a share link to http://goshinkarate.com/intro_offer.html (my kids take Karate here – Great program!)

 

Share

 

The code for this is:

<a name="fb_share" type="button" share_url="http://goshinkarate.com/intro_offer.html" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

 

You can put this code on your site and let your visitors share the Goshin Karate introductory special with their friends!

 

Amendment….

 

Let’s see what the Go Daddy Social Visibility product ad looks like:

 

Share

 

<a name="fb_share" type="button" share_url="http://www.godaddy.com/business/social-networking.aspx" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

BP Events bp-events invites broken, workaround

bp-events version 1.1 on top of buddypress 1.1.3 isn’t working for invites, it’s broken. After hours and hours of combing the web looking for a solution, I couldn’t find one. I figured out a workaround.

There were several other places online that I found other complain about this same problem. As far as I can tell, nobody has published any solution or workaround. Until now. I have a workaround – more like a hack, but it works!

I don’t know the WordPress/BuddyPress framework, but I’m pretty skilled at PHP, and can debug by following the HTTP request, and walk through the codebase. I used tcpflow to watch the HTTP requests and responses, and walked the codebase by dropping print lines in appropriate places to see how the request traversed the code.

Here’s what I found out. When bp-events gets to the “Send Invites” section, when you check a checkbox of a friend, it invokes an AJAX call, via JavaScript, to wp-load.php. Well, what it sends to the server is action=groups_invite_user, friend_id=. Everything else is hogwash. There is nothing in the request to tell you what event it’s for!

Ok, so the reason for this is that bp-events uses the same api as bp groups. It borrows from bp groups to draw your “Select Friends” widget. I have not found the real root cause. What it’s supposed to do is send an action=events_invite_user and should also send the event_id, I speculate. I haven’t been able to figure out how to craft an HTTP request to wp-load.php that will perform the intended behavior. I do, however, have a workaround that fixes the problem. Keep reading if you want a workaround hack that fixes this problem.

Read more