How To Create a Teapot with PHP

Saw on @toolmantim‘s blog that he turned his blog into a tea pot. He even made a Rack middleware that can turn any Rake app into a teapot. “Cool! it can be cool addition to Topify, too”, I thought to myself. The problem? Topify is PHP and not Ruby. The solution? 6 lines of PHP code:

And now you can do :

arikfr:~ arik$ curl -i -X BREW http://topify.com/
HTTP/1.1 418 I’m a teapot
Date: Wed, 13 May 2009 08:51:07 GMT
Server: Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2
X-Powered-By: PHP/5.2.6
Content-Length: 29
Content-Type: text/html

We do serve ICE Tea, though.

It’s not as elegant as Ruby code or Ruby gem, but it does the work.

If you use this on your own server, please ping me. I would love to hear :)

Just Created a Simple Twitter App to Check Who You’re Blocking

Just created a simple Twitter app using OAuth that allows you to check who you’re blocking on Twitter (currently there’s no inherent option to see this information on Twitter website). This is very basic and very preliminary – was mainly developed as an OAuth exercise for myself.

I’ve used the PHP twitter-async library and the code sample by @jmathai.

I would really love if someone could help me with the design :)

Looking forward to hear your feedback,
Arik

Posted via email from Arik’s posterous

Mac OS/X Tip: How To Change Screen Capture Location

I really like the built in screen capture ability of OS/X. I specially like the ability to easily take a screen capture of only part of the screen by using Cmd+Shift+4. What I didn’t like was the fact that it created a hell of a clutter on my desktop with all that screenshots.

Cluttered Desktop

Cluttered Desktop

For long time I’ve been just manually moving the screenshots to different folders / deleting them. But today I decided that enough is enough and looked for a solution. And of course a simple solution exists. To save you the reading here’s a summary of what you need to do:
1. Open the Terminal.
2. Create a new folder for the screenshots by using mkdir, i.e.

mkdir /Users/Arik/Desktop/Screenshots

3. Run the following command:

defaults write com.apple.screencapture location [the-folder-you-created-in-step-2]

That’s it. Almost. Now you need to logout and login again in order for the changes to take effect. Instead you can use the following command (from Terminal):

killall -HUP SystemUIServer

Now you really done.

Hope it helps.
Arik

Shortening URLs using bit.ly API and PHP+Zend Framework

Recently for Topify I needed to shorten some long urls (our invite links) and my obvious choice of shortener was bit.ly. I tried looking for PHP wrapper for their API, but only found this project which was way more than I needed. So I’ve decided to write my own simple client using the Zend Framework HTTP Client. Here’s the result:

<?php
function bitly_shorten ($url) {
    $client = new Zend_Http_Client('http://api.bit.ly/shorten');
    $client->setParameterGet(array(
        'version' => '2.0.1',
        'longUrl' => $url,
        'login' => 'arikfr',
        'apiKey' => 'R_03feadf27c1c7c1a1ac3c3e7d6d41a27'
    ));    

    $response = $client->request();
    if ($response->isSuccessful() ) {
        $phpNative = Zend_Json::decode($response->getBody());
        if ($phpNative['errorCode']==0) {
            return $phpNative['results'][$url]['shortUrl'];
        }
    }
    return "";
}
?>

As I said – it’s simple. There’s a lot more to do with it, but it serves the purpose I needed it for and I think it might be useful for others who only want to shorten some urls. If you need more than that, you might want to take a look at the above mentioned project.

Arik

Save Valuable Time – Block Facebook for 75% of Your Time

Lior Levin asked me today if it’s possible to create a Firefox extension, that will block Facebook part of the time. As a result, I created a Firefox extension (a compiled Greasemonkey) that blocks Facebook for 45 minutes each hour (form :16 to :59), i.e. blocking Facebook for 75% of your time.

This is a very rough alpha version. It will work, but it has a lot more to do with.

Facebook Diet - Firefox Extension to Block Facebook for 45min each hour

Will be glad to hear if you’re using it, and what you think of it.

Download extension | Download Greasemonkey Userscript

Arik

Gravatars to Google Contacts Importer

I really like avatars and therefore I’m a big fan of Gravatar. When Google first released their Contacts API, the first thing I though of was creating a small application to sync my friend’s Gravatars to my Google Contacts addressbook. The problem was that the first version of the API didn’t have an option to manage the photos of the contacts. Few months later, Google updated the API to include the option to update the contact’s photos. I played a bit with the new API, but never had the time to write the appliaction.

Yesterday  (October 11 2008), the guys from Automattic/Gravatar wrote a post the summarizes their last year. This reminded me of this small project that I always wanted to code. I’ve decidced to code a first release of the application and put the code on Google Code for other to contribute.

Gravatars to Google Contacts Importer 

I’v decided to make it a .NET application and not a Python script, to address more people (I guess that more people are comfortable with running application than Python scripts). The reason that this isn’t a webapp, is because it takes a whole lot of time to process each contact list. If there was an option to question the Gravatar API for existence of a Gravatar for each email, it would make everything a bit quicker.

It’s .NET 2.0, so I guess there shouldn’t be a problem to run it on Linux using Mono, although I didn’t try that. The code is very simple, so if someone wants to translate it to other languages it’s possible and shouldn’t take too much time.

This is an alpha version, therefore don’t be scared if a nasty exception jumps at you :-) There are a lot of things to imporve, like adding threads to speed up things, time left counter and more. When I will have some more free time, I might add all this.

This is my first opensource project and your comments are mostly appreciated. 

Arik

How To Send SMS Message From Python Via Skype

In case you didn’t know, Skype offers an extensive API for their application. This API can be used via Java library, COM module or a Python library. The Java library, COM Module and Python library all share similar features and I decided to try out the Python library. What I wanted to do is to write a simple Python script that uses the Skype API to send SMS message from Skype. After going through their API documention, I was ready to go and the outcome was this short script: 

I think that the code is pretty straightforward and doesn’t require additional explaining. Feel free to ask questions at the comments.
Arik

Beware Of A Virus Spread Via Facebook

Image by Jofelly

This morning I’ve received a notification email from Facebook, notifying me that my friend Asaf left me a new message on my wall. This seemed to be OK until I read the message:

“hello Arik, hehe.. you could be tht naughty i didnt knw..really hard to see tht from my eyes lol :-)

have a luk urself…

http://www.google.com.id.ewv1g6d2.ij4s0h.2b99df1a.cn/gallery.php?id=dd83hikzt&auth=9490559&cyua=iy2qpfpelm

(click open or run when prompted)

The contents of the message was suspiciously similar to the Messenger virus messages. Another look at the URL gave out the fact that this is not a Google url, but a phishing site. Because I use Ubuntu at the moment, I wasn’t concerned too much of being hit by a virus, so I followed the link. The link goes to a download page of Picture_dl.exe, which I guess is some sort of a virus/worm.

I couldn’t find this message on my wall, so either Facebook removed it already or the email didn’t come from them. Either way, I’ve notified their support about that, and I hope they will act accordingly.

Bottom line – beware of viruses being spread via Facebook/look like Facebook notifications, and don’t click on every link

Arik


Make the Unread Items in Google Reader Disappear

אין יותר מספרים מלחיצים

The Unread Items counter in Google Reader is putting you under pressure? Can’t sleep because of it? Well, you don’t have to see it any more. I’ve hacked a simple Greasemonkey script that hides the unread items counter in Google Reader. There’re two flavours of the script: one that hides only the all items counter and other one that hides all the counters.

To those of you who don’t know what Greasemonkey is:

Greasemonkey is a Mozilla Firefox extension that allows users to install scripts that make on-the-fly changes to most HTML-based web pages. [..]

Greasemonkey can be used for adding new functionality to web pages (for example, embedding price comparison in Amazon.com web pages), fixing rendering bugs, combining data from multiple webpages, and numerous other purposes.

(From Wikipedia entry on Greasemonkey)

You can find a lot more scripts on userscripts.org . Beware that some scripts become unstable/not working due to constant updates of the web sites (most of Gmail scripts break every version update).

I’ve also created three bookmarklets that allow you to unhide and hide the counters, but had trouble to embed them in the post. So if anyone interested in them, just leave here a comment.

Comments are mostly welcomed.

Enjoy.

Arik