Christian Heilmann

Posts Tagged ‘filtering’

A quick one: (ab)using mediaqueries to not serve CSS to IE < 9

Wednesday, February 22nd, 2012

I am right now writing a post on how to use :target selectors for image galleries. As always, older IE are the fly in the ointment there as only IE9 supports the selector. So I thought about a way to serve the CSS only to the browsers in the know. The options were of course conditional comments, adding a selector IE < 9 doesn’t understand to every selector I want to filter out (like using
body:last-child article the same way we used html>body to filter out IE6) but then it came to me: media queries are only supported in IE9 and above. So you can simply do a:

.foo {
  // ... styles for ALL THE BROWSERS
}
@media screen and (min-width: 400px) {
  .foo {
    // ... styles for newer browsers
  }
}

A test of a 400 pixel wide browser window should be more than enough, right? Discuss on Google+

Dating for geeks – using YQL and Craigslist

Friday, April 16th, 2010

OK, it is Friday, so let’s have some fun. If you go to Craigslist, you will find that there is quite an extensive Personals section (more filled in the US than in Europe, admittedly). It is also full of very obvious messages, so make sure you are OK to watch the links in this article in your work place.

For London, for example the URL of that is:

http://london.craigslist.co.uk/ppp/

This lists all the personals there are – regardless of what type. It also comes as an RSS feed:

http://london.craigslist.co.uk/ppp/index.rss

So, the pattern here is:

http://{location}.craigslist.co.uk/{type}/index.rss

If you want to do a search, it is slighty different:

http://{location}.craigslist.org/search/{type}?format=rss&query={query}

This is exactly what is in use in the open YQL table for craigslist.

Now, the information in craigslist is pretty extensive – and full of stuff you will not want or need.

So, you can use YQL to filter it down to what you need. Say you are a dude and you are looking for a lady you will find that a lot of the content on the results page is not for you. You can filter however down to what you are looking for with the following in YQL query:

select item.title,item.description,item.link
from craigslist.search where location=”london”
and type=”ppp” and query=”w4m”

You can see the result of this here (might contain NSFW text content).

You can also filter down to certain types. For example you can only see the women looking for men – including those who only want a casual encounter:

select item.title,item.description,item.link
from craigslist.search where location=”london”
and type in (“w4m”,”cas”) and query=”w4m”

Results of this query are available here.

You can also broaden your horizons and include different queries, like couples looking for another man:

select item.title,item.description,item.link from
craigslist.search where location=”london” and type=”cas”
and query in(“mw4m”,”w4m”)

Check out these results

Problem here is that you cannot have two sub-selects in a single query – so you need to use query.multi:

select * from query.multi where queries=’
select item.title,item.description,item.link from craigslist.search where
location=”london” and type=”w4m” and query in(“mw4m”,”w4m”);
select item.title,item.description,item.link from craigslist.search where
location=”london” and type=”cas” and query in(“mw4m”,”w4m”)

See the multi results here.

If you put this into a PHP script that gets information from a form, you can easily build a Craigslist date finder:

Craigslist Date Filter

The code is available below or directly on GitHub :

Another proof that YQL simply rocks.

Searching Flickr photos by license and text and returning defined sizes made easy with YQL

Saturday, February 14th, 2009

We (Nagesh Susarla and moi) are just sitting here at Open Hack Day in Bangalore, India and geek out on YQL trying to find how far we can push it to make the life of a hacker easier.

One of the things was using Flickr photos and making sure we can only get photos of a certain license for a certain text. Here’s the magic we YQL statement we came up with:

select * from flickr.photos.sizes where photo_id in (select id from flickr.photos.search(20,20) where text=@text and license=@license)  and label=@label

The (20,20) means “get me 20 photos starting at the 20th” and to make it easier say we do the first 50 results instead. The @parameter are placeholders which will be replaced by URL parameters.

As a URL you can use this and send the right parameters, for example find cats with an attribution license and only square photos (75×75pixels):

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from flickr.photos.sizes%20where%20photo_id%20in%20(select%20id%20from%20flickr.photos.search(50)%20where%20text%3D%40text%20and%20license%3D%40license)%20and%20label%3D%40label&format=xml&text=cats&license=4&label=Square

Possible licenses are:

1 Attribution-NonCommercial-ShareAlike License
2 Attribution-NonCommercial License
3 Attribution-NonCommercial-NoDerivs License
4 Attribution License
5 Attribution-ShareAlike License
6 Attribution-NoDerivs License
7 No known copyright restrictions

Possible labels are Square,Thumbnail,Small,Medium and Original

To make it easier, you can also wrap the whole thing in a method:

function display(o){
var out = ‘’;
for(var i=0;i var cur = o.query.results.size[i];
out+=’‘;
}

var d = document.createElement(‘div’);
d.innerHTML = out;
document.body.appendChild(d);
}

/*
leechFlickr() by Christian Heilmann
Gets an object as the parameter. Object properties:
query (mandatory) – term to search flickr for
amount – amount of photos (defaults to 20)
license – 1 to 7
label – Square,Thumbnail,Small,Medium and Original
callback – callback function name as string

*/
function leechFlickr(o){
if(o.query){
var amount = o.amount || 20;
var license = o.license || 4;
var url = ‘http://query.yahooapis.com/v1/public/yql?’ +
‘q=select%20*%20from flickr.photos.sizes’ +
‘%20where%20photo_id%20in%20(select’ +
‘%20id%20from%20flickr.photos.search(’ +
amount + ‘)%20where%20text%3D%40text%20and’ +
‘%20license%3D%40license)’;
if(o.label){
url += ‘%20and%20label%3D%40label’;
}

url += ‘&format=json&callback=’ + o.callback +
‘&text=’ + o.query + ‘&license=’ + license;
if(o.label){
url += ‘&label=’ + o.label;
}

var s = document.createElement(‘script’);
s.src = url;
document.getElementsByTagName(‘head’)[0].appendChild(s);
}

}

leechFlickr(
{

query:’cats’,
label:’Square’,
callback:’display’
}

);
leechFlickr(
{

query:’parrots’,
amount:10,
license:3,
label:’Square’,
callback:’display’
}

);

See the code in action and download the script.

Does YQL rock or what? No messy user IDs, no mixing and matching all kind of API methods, just plain yummy data.

Displaying useful tweets on your blog (second version using YQL)

Friday, January 16th, 2009

Back in September I showed a solution how to display filtered tweets on your blog using Yahoo Pipes which is in use on this page in the sidebar on the right.

There were a few issues with it: the data returned was pretty big and slowed down the page (yeah I could delay this after page load, but size down the wire is size down the wire) and I only used the last 20 updates, which – with my twitter pace – meant that a lot of times there wasn’t any ‘blogworthy’ tweet available any longer.

So, I dug around and realized that instead of analyzing the RSS feed of your tweets it makes much more sense to use the API, in detail the user timeline which allows me to get up to 200 of the latest tweets using the count parameter.

This is awesome, however, as the API repeats all my information in every status (I guess to cover changes, like location) the result can get very large, right now for example the JSON output of my twitter updates is 120KB – not good.

By using YQL I can easily cut this down to the bare necessities using the following command:

select status.text from xml where url = 'http://twitter.com/statuses/user_timeline/codepo8.xml?count=200' and status.text like '%§%'

Using this with JSON output and wrapper I only get the updates I need as a 1.2KB large JavaScript file!

The HTML and JavaScript solution doesn’t change much:




Now I got a faster useful tweets badge with information that stays longer. Easy.

Unsafe Search – playing with BOSS and YUI3

Tuesday, October 21st, 2008

As I am giving some presentations on YUI3 and BOSS tomorrow I thought I give them a whirl and see what I can come up with. I remembered my esteemed colleague Neil Crosby joking about the idea of an “unsafe search” – take a search result and diff it with the safe search result (adult filters enabled) and you will only get the unsafe results.

Well, BOSS allows you to set filters on the data you get back, this was not too hard to do. I give you Unsafe Search