flickr.groups.pools.getPhotos and php_serial

filled under:
December 4, 2008 

If you try to get a serialized array (php_serial) from the flicker api from a group (flickr.groups.pools.getPhotos), you may find your self a little bit lost, because you do not get the photos you want, only the amount of how many. You double check if everything is set to public, your account is ok and even try to upgrade it – but that’s not it. You used the usefull API querybuilder from flicker and then it works in that case and you wonder why it doesn’t in your application. The simple solution is, it doesn’t work with the php_serial format. Skip this parameter and you get your set as XML response. The only thing you need to do is, use the XMLReader and iterate through the result set.

It took me quite a while to figure this out – like 1,5 hours – so eventually this post is usefull for someone ;)

tags:

simple method to add a safari css

filled under:
November 5, 2008 

There are some selector hacks out there, but I don’t like them – ie: (@media screen and (-webkit-min-device-pixel-ratio:0) {}). My personal favourite is done with Prototype because I use it a lot and it is pretty simple:

<link rel="stylesheet" type="text/css" media="none" href="/css/safari.css" id="safari" />
<script type="text/javascript">
	// matches all safari/chrome versions
	if(Prototype.Browser.WebKit) {
		$('safari').media="all";
	}
</script>

If you set the media attribute to none – no media device will display it. By adding the little if statement, you can check if the Browser is WebKit, which is the engine name of safari or chrome and alter the media value to all.

If you do not use prototype, you can do it like this:

<script type="text/javascript">
	// targets safari 3 - not 2!
	if(window.devicePixelRatio) {
		document.getElementById('safari')media="all";
	}

	// targets all safari or better said webKit engines
	if(navigator.userAgent.indexOf('AppleWebKit/') > -1) {
		document.getElementById('safari')media="all";
	}

	// prototype way + targeting old and new webKit with two stylesheets
	if(Prototype.Browser.WebKit) {
		var mySafari = (window.devicePixelRatio) ? 'safari3' : 'safari2';
		document.getElementById(mySafari)media="all";
	}
</script>

Note, this method shouldn’t be used for “accessible” Websites, because it relies on javascript. You can do it then serverside as well by “sniffing” the UserAgent from the HTTP Request and add your little switch there – whereas this isn’t a 100% safe method though, because some people alter their UserAgent strings and there are tons of vendors/versions thus your detection may fail from time to time.

An alternative to this way is to load the needed script on the fly, so you can reduce a HTTP Request, by writing the link tag dynamically to your document. However – the describe method above is shorter ;)

new theme

filled under:
October 26, 2008 

it was time for a change – so I’ve made a new theme for my blog. Nothing special but it looks quite ok (haven’t tested it in IE, I don’t care bout it – but in safari, firefox, chrome and opera it looks good). At least YSlow say it has Grade B and if only the google syntax highlighter plugin would produce valid xhtml, then it would be valid … ;)

tags:

how to cut a string with regex (the neat way)

filled under:
October 9, 2008 

It is fairy a common task to cut a string – ie when a teaser text should not be longer than n characters. A lot of people use substring() or substr(), depending on their favourite language. However with regex it is really easy and you do not need to cut a word:

// in php it would be:
preg_match("/(.{1,15}(\s))/", $yourString, $matches);

// or in java something like this - maybe ; )
Pattern myPattern = Pattern.compile((.{1,15}(\\s)));
Matcher myMatch = myPattern.matcher(yourString);

To put it in plain english:
* get the first 15 characters (same as substring)
* BUT – and here goes the magic: match less until you find a whitespace character and cut the rest.

So it could look like this in php:

<?php
// you could check the length of the string but actually you don't need to ...
$myString = "People seem to enjoy things more when they know a lot of other people have been left out of the pleasure.";

preg_match("/(.{1,15}(\s))/", $yourString, $matches);
echo $matches[0]." ...";

// would print:
// People seem to ...
// and with {1,27}
// People seem to enjoy things ...
?>

beer o’clock! cheers :)

tags:

daily madness

filled under:
September 24, 2008 

I got up to late today and my ticket list is ways to long plus I need to finish some work for a client. However – the weather is fine today and I don’t feel stressed or something like that. I bought the new Roots Manuva and really like it. I had a “club-mate” and a delicious Panini toast (yummy) and I am very looking forward to have an after work beer – in about 2 hours ;)

At my work we usually do Java/JSP stuff but a few weeks I did a small PHP Job here and today I made the statistic in mysql. Actually nothing special but a welcome change if you imagine stupid JSP Struts tasks day in and day out and boring style-stasi requests from project managers and so on. But I am hip to the spirit and love computer work – or at least the creative-innovative part of it – the rest I try to reject and forget. Actually it is always the same – some project manager come up with a kick ass idea and then during the production it gets reduced to something really boring and forgettable unimportant whatsoever.

My coffee is empty [...] ^^

tags:

MySQL EXPLAIN aka DESCRIBE for UPDATE/DELETE

filled under:
September 21, 2008 

Ever tryed to “explain” a delete or an update statement? It will fail. It took me nearly an hour to figure this out. Actually I’ve never needed to explain a simple DELETE statement, but in todays case I did and was wondering why my query always failed. It is too bad that there is no such “feature”. With InnoDB you can use of course the ON DELETE/UPDATE stuff but in my case I didn’t want to alter the existing DB.

However, if you need to delete multiple rows over multiple tables, you may do something like this: ;)

DELETE stats, links, logins
FROM promo_stats AS stats
LEFT JOIN promo_links AS links USING(promo_link_id)
LEFT JOIN promo_logins AS logins USING(promo_login_id)
WHERE stats.promo_item_id=6;
tags:

Stupid New Media

filled under:
September 17, 2008 

A Project manager recently emailed me about a non working link but without to mention which link he was taking about, so I replied: «What kind of link, in what situation – how can I reproduce it?» – After a short while he sent me a screen shot and said it would happen when he clicks on a flash file. (Why does he bother me? He has sent me the flash file and someone else created it.)

Nevertheless I am a very kind IT guy and explained the issue to him – So I wrote him that a link to an external resource always consist out of: 1) a protocol name, 2) an instruction for the browser that it is an external resource :// and finally 3) the domain name and last but not least the TLD and optional paths or parameters.

You may call me a fault finder but that’s something that happened not the first time. I guess this is a classic example of: stupid new media. People who are working in the new media should knew what a friggin link is – especially when they are Project Manager of a website!

trip to hamburg/Schleswig-Holstein

filled under:
September 15, 2008 

I just came back from a short trip to Hamburg and Schleswig-Holstein. Actually it was my Moms bday and I bought her some stuff for the kitchen and I hope she will enjoy the designer pepper mill ;) On Sunday we went to the Arboretum (some sort of a botanical garden), which is a really nice place, although there is a small fee to pay. There’s a little lake with lotus, water lilies and koi fish. I took some pics with my phone, so if you’re interested you can get a picture ;)

tags: