playing with the web

86
Playing with the web Christian Heilmann | http://wait-till-i.com | http://twitter.com/codepo8 Geek Meet Stockholm, December 2008 or “The geek shall inherit the earth”

Upload: christian-heilmann

Post on 20-Jan-2015

7.409 views

Category:

Technology


0 download

DESCRIPTION

My second talk at geekmeet sweden talking about the tools you can use to hack and remix the web.

TRANSCRIPT

Page 1: Playing With The Web

Playing with the web

Christian Heilmann | http://wait-till-i.com | http://twitter.com/codepo8

Geek Meet Stockholm, December 2008

or “The geek shall inherit the earth”

Page 2: Playing With The Web

The web is an awesome opportunity and media.

Page 3: Playing With The Web

I learnt that pretty early and left an old media to work for

the new one.

Page 4: Playing With The Web

One thing that keeps amazing me about it is how simple the

technologies driving it are.

Page 5: Playing With The Web

You don’t need to be a rocket scientist to wreak havoc on the web.

Page 6: Playing With The Web

I am not talking about malicious intent here.

Page 7: Playing With The Web

I am talking about ethical hacking.

Page 8: Playing With The Web

So today I am going to show some tools I love to use to

play and mess with the web.

Page 9: Playing With The Web

Disrupting the process to foster and drive innovation.

Mr. Buzzwordwill see you now!

Page 10: Playing With The Web

Let’s start with the first one – a true Swedish product!

Page 11: Playing With The Web
Page 12: Playing With The Web

Their product?

Page 13: Playing With The Web

cURL

Page 14: Playing With The Web

cURL allows you to get raw text data from any server.

Page 15: Playing With The Web

You can create the full range of HTTP requests from a script

or the shell.

Page 16: Playing With The Web

Including POST requests, simulating cookies and all the

other goodies :)

Page 17: Playing With The Web

Which gives you an amazing amount of power

Page 18: Playing With The Web

Say you want to build an API that doesn’t exist.

Page 19: Playing With The Web

At Mashed08 I got bored.

http://www.flickr.com/photos/37996583811@N01/2600265124/

Page 20: Playing With The Web

Someone came to me and asked if I knew of a currency

conversion API.

Page 21: Playing With The Web

And I didn’t as there is none.(everybody pays good money for that data)

Page 22: Playing With The Web

So I went to Yahoo Finance.

Page 24: Playing With The Web

Simple, predictable URL :)

Page 25: Playing With The Web

I found the location of the result by viewing the source

of the page.

Page 26: Playing With The Web

http://www.wait-till-i.com/2008/06/21/currency-conversion-api/

function convert($from,$to){ $url= 'http://finance.yahoo.com/currency/convert?amt=1&from='.$from.'&to='.$to.'&submit=Convert'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $feed = curl_exec($ch); curl_close($ch); preg_match_all("/tabledata1\">([^<]+)<\/td>/", $feed,$cells); return $cells[1][1];}echo convert(’USD’,'GBP’);

Page 27: Playing With The Web

Turning this into an API was easy:

Page 28: Playing With The Web

header('Content-type:text/javascript');$from = $_GET['from'];$to = $_GET['to'];$callback = $_GET['callback'];if(preg_match("/[A-Z|a-z]{3}/",$to) && preg_match("/[A-Z|a-z]{3}/",$from)){ $to = strToUpper($to); $from = strToUpper($from); $url= ‘http://finance.yahoo.com/currency/convert?’ . ‘amt=1&from=’.$from.’&to=’.$to.’&submit=Convert’; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $feed = curl_exec($ch); curl_close($ch);

Page 29: Playing With The Web

preg_match_all("/tabledata1\">([^<]+)<\/td>/",$feed,$cells); if(is_numeric($cells[1][1])){ $out = ‘{"from":"’.$from.’","to":"’.$to.’","factor":"’.$cells[1][1].’"}’; } else { $out = ‘{"error":"Could not convert currencies, are you sure about the names?"}’; }} else { $out = ‘{"error":"Invalid Currency format, must be three letters"}’;}if(isset($callback)){ if(preg_match("/[a-z|A-Z|_|-|\$|0-9|\.]/",$callback)){ $out = $callback.’(’.$out.’)';

Page 30: Playing With The Web

} else { $out = ‘{"error":"Invalid callback method name"}’; }}echo $out;

Page 31: Playing With The Web

Using the API is as easy...

Page 32: Playing With The Web

<script type="text/javascript"> function converted(obj){ if(obj.error){ alert(obj.error); } else { alert('one ' + obj.from + ' is ' + obj.factor + ' ' + obj.to); } }</script><script type="text/javascript" src="convert.php?from=gbp&to=usd&callback=converted"></script>

Page 33: Playing With The Web

View Source is a good start.

Page 34: Playing With The Web

However, much more win is Firebug.

Page 35: Playing With The Web

It has never been easier to find things to get with cURL.

Page 36: Playing With The Web

Say twitter information...

Page 37: Playing With The Web
Page 38: Playing With The Web

How about showing this as a cool chart?

Page 39: Playing With The Web

We all like to show off what we do on the web.

Page 40: Playing With The Web

Charts can be tricky...

Page 41: Playing With The Web
Page 42: Playing With The Web

Good thing that there’s Google Charts.

(yeah and YUI charts)

Page 44: Playing With The Web

<?php$user = $_GET['user'];$isjs = "/^[a-z|A-Z|_|-|\$|0-9|\.]+$/";if(preg_match($isjs,$user)){ $info = array(); $cont = get('http://twitter.com/'.$user); preg_match_all('/<span id="following_count" class="stats_count numeric">([^>]+)<\/span>/msi',$cont,$follow); $info['follower'] = convert($follow[1][0]); preg_match_all('/<span id="follower_count" class="stats_count numeric">([^>]+)<\/span>/msi',$cont,$follower); $info['followed'] = convert($follower[1][0]);

Page 45: Playing With The Web

preg_match_all('/<span id="update_count" class="stats_count numeric">([^>]+)<\/span>/msi',$cont,$updates); $info['updater'] = convert($updates[1][0]); $max = max($info); $convert = 100 / $max ; foreach($info as $k=>$f){ if($f === $max){ $type = $k; } $disp[$k] = $f * $convert; } if($type === 'updater'){ $t = ' is an '; } if($type === 'follower'){ $t = ' is a ';

Page 46: Playing With The Web

} if($type === 'followed'){ $t = ' is being '; } $title = $user . $t . $type; $out = array(); foreach($info as $k=>$i){ $out[] = $k.'+('.$i.')'; } $labels = join($out,'|'); $values = join($disp,','); header('location:http://chart.apis.google.com/chart?cht=p3&chco=336699&'. 'chtt='.urlencode($title).'&chd=t:'.$values. '&chs=350x100&chl='.$labels);}

Page 47: Playing With The Web

function get($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $feed = curl_exec($ch); curl_close($ch); return $feed;}function convert($x){ $x = str_replace(',','',$x); $x = (int)$x; return $x;}?>

Page 48: Playing With The Web

What if you need to mix and match and filter data?

Page 52: Playing With The Web

And *dum de dum de*...

Page 54: Playing With The Web

/* Useful tweets badge by Christian Heilmann*/var tweets = function(){ var x = document.getElementById('mytweet'); if(x){ var twitterUserId = x.className.replace('user-',''); var s = document.createElement('script'); s.type = 'text/javascript'; s.src = 'http://pipes.yahoo.com/pipes/pipe.run?' + '_id=f7229d01b79e508d543fb84e8a0abb0d&_render=json' + '&id=' + twitterUserId + '&_callback=tweets.tweet'; document.getElementsByTagName('head')[0].appendChild(s); }; function tweet(data){ if(data && data.value && data.value.items){ if(typeof data.value.items.length !== 'undefined'){ var ul = document.createElement('ul'); var all = data.value.items.length; var end = all > 5 ? 5 : all; for(var i=0;i < end;i++){

Page 55: Playing With The Web

var now = data.value.items[i]; var li = document.createElement('li'); var a = document.createElement('a'); a.href = now.link; a.appendChild( document.createTextNode(now.title) ); li.appendChild(a); ul.appendChild(li); } x.appendChild(ul); } } }; return{ tweet:tweet }}();

Page 56: Playing With The Web

One of my favourite toys:

Page 57: Playing With The Web

Using GreaseMonkey you can change any web page out

there with DOM and JavaScript.

Page 58: Playing With The Web

You can for example prototype an enhancement and show it to people with a

single link.

Page 59: Playing With The Web
Page 60: Playing With The Web
Page 61: Playing With The Web
Page 62: Playing With The Web

By playing with the web you can do jobs that until now

cost a lot of money.

Page 63: Playing With The Web

Say you want to help your clients find good keywords to promote their product online.

Page 64: Playing With The Web

You can do some research, surf all the competitors’ sites

and note down the descriptions, keywords and

titles.

Page 65: Playing With The Web

Or you can be a man and use cURL to write a script to do

that.

Page 66: Playing With The Web

Or you can be a clever man and keep your eyes open and

check if there is an API for that.

Page 70: Playing With The Web

All you need to do is getting the top 20, analyzing the keyword frequency and

create a top 20.

Page 72: Playing With The Web

Then you take YUI CSS grids, and spend 30 minutes playing

with colours and fonts.

Page 73: Playing With The Web

And you have a product:

http://keywordfinder.org

Page 74: Playing With The Web

This is all cool, but does it bring us anywhere?

Page 75: Playing With The Web

Yes, if you get excited about the web and its opportunities

you can move things.

Page 76: Playing With The Web

It takes determination!

Page 77: Playing With The Web
Page 78: Playing With The Web
Page 79: Playing With The Web

And the outcome can be rewarding beyond anything

you ever imagined.

Page 81: Playing With The Web

So by all means, put all your wonderful products on the

web.

Page 82: Playing With The Web

Especially when they cater a very specific need.

Page 83: Playing With The Web

The prime number shitting bear...

http://alpha61.com/primenumbershittingbear/

Page 84: Playing With The Web

And never stop to fiddle, tweak and poke at the things people offer you on the web.

Page 85: Playing With The Web

So thank you for having me here and listening.

Page 86: Playing With The Web

And I hope you will have an awesome Christmas!

Christian Heilmann http://scriptingenabled.org | http://wait-till-i.com

twitter/flickr: codepo8