In a little app that I recently launched I tried to use Twitters API. Turns out it’s incredible easy to do so if you use Ruby on Rails.
Here are the things that I needed to do to get a first version running:
Create a new Rails application. Then create a Model Twitter that extends Rails’ ActiveResource:
class Twitter < ActiveResource::Base
self.site = "http://twitter.com"
self.user = "yourusername"
self.password = "yourpassword"
self.element_name = "status"
end
As you can see you can add the credentials to your Twitter account. Because Twitter’s API uses <status> as root element of the API’s XML we set “elmenet_name” to status.
Well that’s all you have to do. Fire up the console (ruby script/console) type in
Twitter.post(:update, :status => "Yay, I just used the API")
and you will see you just twittered with rails.
Other operations are simple to. If you – for example – want to load all replies to your account just use:
.
Additional goody:
If you want to use an URL-shortener within ruby you can use the API of is.gd:
url = Net::HTTP.get 'is.gd', '/api.php?longurl=' + CGI.escape("http://somereallylongurl.com/blub")
Twitter.post(:update, :status => "Here: " + url)
It has been a long time since my last blog post. I have a new job and unfortenatley this means I have less time for other things such as this blog. Nonetheless I’ve decided to start blogging again. If you have little time you gotta try to get your stuff out fast…
Like Giles Bowkett I’m going to try to get some apps out. Starting with alsichsoaltwarwiedu.de. Sorry it’s german… because of that I’m going to continue this posting in german:
Die Idee zu “Als ich so alt war wie du” kam mir, als ich Jasper’s Neidlos zum erstne mal auf Youtube sah. Und weil ich sowieso schon lange mal mit der Twitter-Api rumspielen wollte war das die Gelegenheit dazu. Es stellt sich heraus: Die Twitter-Api ist kinderleicht zu verwenden, vor allem mit Rails’ ActiveResource.
Jedenfalls könnt ihr auf alsichsoaltwarwiedu.de in wenigen Zeichen beschreiben warum früher alles besser oder viel härter war. Das ganze wird dann automatisch auf Twitter gepostet.
Der umgekehrte Weg geht natürlich auch: Sende ein reply an “@alsichsoaltwar” auf Twitter und dein Beitrag taucht automatich auf alsichsoaltwarwiedu.de auf.
If you ever clicked on a google cache link you know their highlighting. Some time ago I wrote a prototype.js-based highlighiting script to achieve the same. Whenever someone finds your site in a search engine this scripts highlights the entered keywords. By default there are only a bunch of search engines included but you can add as many as you want.
It’s kind of a work in progress because I wrote it some time ago and I think there is room for improvement. But fornow: Feel free to use it. I would be happy if you give me feedback.
Usage is simple, just get the keywords:
var keywords = (new SearchKeywords()).get();
And then highlight them:
Read the full article »
It’s been a long time since my last posting. Today I’m going to show you my cycle-helper for cakePHP. If you haven’t read my other posts on alternating row colors, do so now: Alternate Table Rows in CakePHP (and ZF, Rails, Smarty)
The cycle-helper is easy to use and install and if your familiar with the rails cycle-helper you already know how it works…. So: how does it look when you use my helper for alternating row colors:
<table>
< ?php foreach($rows as $row):?>
<tr <?php echo $cycle->cycle('', ' class="altrow"');?>>
<td>< ?php echo $row['rowdata'];?></td>
</tr>
< ?php endforeach ?>
</table>
I think it’s pretty nice and a more beautiful approach then what cake bake produces.
Of course you can also use it with css-classes “even” and “odd”:
Read the full article »
In my last posting I talked about alternating table row colors with plain PHP. But how is this handled in different frameworks like CakePHP, Zend Framework, Rails or Smarty?
[UPDATE: My CakePHP-Cycle-Helper is described here: http://functino.com/2009/07/cakephp-cycle-helper-alternating-row-colors-with-cake/]
I’m going to show you simple examples for each of this tools.
In Smarty you can alternate table row colors (or any other thing) with the simple cycle function like this:
Read the full article »