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)
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 »
What is a “Zebra Table”? It’s a striped table with alternating row colors like this:
A simple Zebra Table
You can achieve this with very different approaches:
CSS only
With CSS 3 you can achieve such a table with the pseudo class nth-child. The rules are extremly simple and no additonal markup is required. Just add these lines to your CSS:
tr:nth-child(even) {background-color: #FFF}
tr:nth-child(odd) {background-color: #FFCC00}
But since not all browsers understand this CSS 3 selector this is perhaps not the best solution.
Instead of relying on Browsers CSS 3 support you can also use JavaScript to achieve the same result.
Read the full article »