Turn Off and Disable Comment Limiting in Wordpress
Jan 31, 2010
Many people have asked me in the past how to disable comment limiting in WordPress. Enough people asked me that I decided I'd post it on dwrbudr.com. Before I show you how to do it, note that you are basically just
ASKING for more spam comments. However, it's probably more convenient for your users to be able to post comments rapidly.
Here's how enable disabling.
Apple Push Notification Example for iPhone
Dec 28, 2009
I am currently working on an app that needs push notification. Figuring it out based on Apple's docs was basically worthless. Here's a step by step explanation on how to get it working:
- Make sure you have a provisioning profile where the app ID for your app has an explicit name, like this: com.foo.iphone instead of a wildcard based one such as this: com.foo.* If you must, create a new provisioning profile.
- Reinstall the new provisioning profile from above (if you had to create a new one). If you already had an explicit app id name, do nothing for this step.
- From the iPhone Developer Portal, download your new certificate that has Apple Push Notification configured, and install this .cer file into Keychain. You can just drag it into Keychain once you've downloaded it.
- Now you'll need to follow a bunch of steps to generate the .pem file that you'll store on your webserver. This .pem file will be necessary when your backend system wants to send a message to an iPhone that is running your app. To do this, simply follow steps 5-10 from boxedice, which describes this process. Sorry, I was too lazy to write this out myself.
- The last step in the tutorial from above was to generate the .pem file. Copy this to your webserver and put it in a place where you can access it from the backend that's going to send messages to a device.
- In this step we'll modify your app to receive messages from APNs. This part is really easy. In your application delegate class, simply add a few methods that are part of UIApplicationDelegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// ...other startup code
//register for badge, alerts and sound push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
NSLog(@"got back device token: %@\n", devToken);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(@"Error in registration. Error: %@", err);
}
- In didRegisterForRemoteNotificationsWthDeviceToken:, you extracted the device token for the device running your app. Write a small function to pass this to your backend where you can store it. You'll then use the device token when passing messages to a particular device. This is basically how you address individual devices.
- Now, you'll need a backend script or daemon to send messages. boxedice has a nice php example that I basically followed. Note that the payload is a simple JSON object and you pass the device token that we just saved. The device token should be free of angle brackets and spaces. (I say this since you'll see them in the NSLog message in didRegisterForRemoteNotificationsWithDeviceToken:)
That's about it. I got it working on the first try. Perhaps you will too, with the directions here.
JavaScript Flickr API
For a Yahoo hack day, I wrote a hack that allows you to use the Flickr webservices API from JavaScript, with no backend scripting, such as PHP. Initially, I took the XML returned by the raw Flickr API and converted it to JSON manually. Since I wrote the hack, Flickr has released an option in the API to get JSON results back, rather than stupid XML. I've since updated my JavaScript API to handle such a situation, and I'm going to post it here.
Before I link to the code, it's important to note that unless you're the Flickr team using this API on the flickr.com domain, the script won't work immediately - this is because of browser security settings pertaining to cross-domain XMLHttpRequest calls, that is, you cannot open an XMLHttpRequest to any domain other than the one serving the page you currently have open.
For more info on this, see the Yahoo Developer Network documentation. I handled the cross domain problem using Premshree's hack, (using Apache mod_proxy and mod_rewrite), but there are other ways to handle it, such as a PHP proxy script or dynamic JavaScript embedding.
As I said, there are two ways to do it:
I've created two seperate JavaScript files you can download for each case:
- flickr.proxy.js - for the proxy way to do it
- flickr.js - for the mod_rewrite way to do it
So here's an example of how to use the API:
//the first param is your Flickr developer key
//please substitute your own key here
var flickr = new FlickrAPI('cf0fca0cd8c6058a2d625f50c42ba08d', '');
var params = new Array();
params['per_page'] = 15;
params['api_key'] = 'cf0fca0cd8c6058a2d625f50c42ba08d';
var json = flickr.callMethodJSON('flickr.interestingness.getList', params);
var obj = eval('(' + json + ')');
var photos = obj.photos.photo;
for(i = 0; i < photos.length; i++){
url = flickr.getPhotoURL(photos[i]);
document.write('<img src=' + url + '>my pic</img>');
}
This is the easiest way to get things working. Instead of using the other
flickr.js file, use this one
flickr.proxy.js that points us to a PHP proxy script, instead. You'll need a
proxy script, which I have an example of below.
So the exact recipe is:
- use this javascript file in the client
- have the proxy sitting on your server (it's just gonna pass thru http requests). I have provided an example one, which you can find here. Remember, you probably want this file to have a .php extension on it.
Here is a working example:
<script type=text/javascript>
var flickr = new FlickrAPI('cf0fca0cd8c6058a2d625f50c42ba08d', '');
var params = new Array();
params['per_page'] = 15;
params['api_key'] = 'cf0fca0cd8c6058a2d625f50c42ba08d';
var json = flickr.callMethodJSON('flickr.interestingness.getList', params);
var obj = eval('(' + json + ')');
var photos = obj.photos.photo;
for(i = 0; i < photos.length; i++){
url = flickr.getPhotoURL(photos[i]);
document.write('<img src=' + url + '></img>');
}
</script>
That code will show these images in your page:
First, you can use the code above in your client page. Make sure to switch on the api key (first arg to FlickrAPI constructor.) Next, you'll need to use any of the domain-security workarounds I linked to above. If you want to use the one that uses mod_rewrite and mod_proxy, which I think is the quickiest and easiest way, then you'll need to make the following changes.
First, create a mod_rewrite entry in your .htaccess file, that looks a little something like this:
RewriteEngine on
RewriteRule ^\/rest\/(.*)$ http://api.flickr.com/services/rest/$1 [P]
What does all this mean?
- RewriteEngine on - turn on mod_rewrite
- RewriteRule ^\/rest\/(.*)$ http://api.flickr.com/services/rest/$1 [P] - This is the most important thing. This says, match the HTTP request coming in, starting with "/rest/", and capture everything after that. Then, rewrite the url to "http://api.flickr.com/services/rest/(everything we just captured after the "/rest" part of the request. Essentially, this will pass thru the request for "/rest/xyz" to api.flickr.com/services/rest/xyz. The most important part is he [P], which tells mod_proxy to come in and act as a pass-thru for this url, rather than actually sending you to it. We want this because we just want to fetch contents from api.flickr.com/..., not actually do any redirects or anything like that.
Unfortunately, I can't show you this working at the moment because Dreamhost doesn't enable mod_proxy for me. But trust me, this works! However, as I mentioned above, you can use a PHP proxy script to do this too. To accomplish this, read the section below.