November 5th, 2008
@biophonc
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 
Tags: code, css, javascript, prototype
Posted in code, css | 1 Comment »
October 26th, 2008
@biophonc
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 … 
Posted in code, personal | No Comments »
October 24th, 2008
@biophonc
just in time. One of our clients requested it (minified + packed) last week and today I found an updated version and it seems t work fine: http://code.google.com/p/protosafe/
Tags: javascript, prototype
Posted in code | No Comments »
October 9th, 2008
@biophonc
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: php, regex
Posted in code | No Comments »
September 21st, 2008
@biophonc
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: MySQL
Posted in code | No Comments »
September 9th, 2008
@biophonc
Passwords are sometimes hard to remember, or at least hard to read, because good passwords are cryptic. That’s a fact and I am still fine with it, because I pay attention to obvious security flaws or risks. However, there are some situations when you do not need cryptic passwords – like “first time passwords”, or “single time passwords”. For this particular case I came up with a nice idea and I’d like to call it pass phrazr (phraser).
Instead of cryptic passwords, use phrases and or simple sentences. If you just enter some phrases as possible pass phrases it doesn’t work very well, but if you use a directory it does. Plus, you can serve i18ln passwords if you add a locale.
The easiest sentence is SVO structured but “Tim like Dogs” sucks and isn’t fancy at all, so I’m going to use a more stylish composition. Factual phrases with *izm nouns instead of boring objects! RaaaaR.
Here’s a simple MySQL Table:
CREATE TABLE passphrazes (
passphraze_word varchar(30) NOT NULL,
passphraze_type enum('subject','verb','noun') NOT NULL,
PRIMARY KEY (passphraze_word)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
If you still wonder about it - the magic goes here:
SELECT concat(
(SELECT passphraze_word
FROM passphrazes
WHERE passphraze_type = 'subject'
ORDER BY RAND()
LIMIT 1),
'-',
(SELECT passphraze_word
FROM passphrazes
WHERE passphraze_type = 'verb'
ORDER BY RAND()
LIMIT 1),
'-',
(SELECT passphraze_word
FROM passphrazes
WHERE passphraze_type = 'noun'
ORDER BY RAND()
LIMIT 1)
);
No clue jet? Well, by selecting random rows you can generate funny phrases like:
He allocated nahualism.
She reinforced mithridatism.
They served social-evolutionism.
Then style it and additionally pimp it more secure (replace spaces with dashes, plus signs, or even camelize it) in your favourite coding language:
He-allocated-nahualism.
SheReinforcedMithridatism.
They+Served+social-evolutionism.
The use case is hopefully obvious. If someone sign up at your site and you generate the first time password for the user, why not something meaningful? There are tons of possibilities to combine words unique.
*updated*
Tags: code, MySQL, passphrazr
Posted in code, digital life | No Comments »
July 8th, 2008
@biophonc
It took us quite a while until we were all satisfied but now it’s done and you can view it over here:
» http://areal-records.com/
The site relies on prototype, some web 2.0 gimmickry, scriptaculous and the pear framework, a wonderful combine script for CSS and JS. Firefox 3 still needs some »pimping« but for all the other browsers it should work fine, as far as I can tell.
It’s midnight.
Tags: areal records, code, done, prototype, work
Posted in code, personal | No Comments »
July 4th, 2008
@biophonc
My neighbours just had sex - uhh, ahhh, uuhhhh - well for about 4 minutes - not much longer - then they were done. So I’d call it a quickly. I was quite tempted to have a look but I thought that would be indecent and naughty, even though it sounded like a doggy-style
However, I’m no voyeur and it’s a hot night and every cool cat wanna have a kitten - or so…
The only reason I’ve noticed them is, our balcony doors are next to each other and both are wide open. But for my excuse, I’m still fixing a database - or better said, I do a modification. for writershops.com I use the world DB from MySQL plus an extra column for the CIA facts book country code. However, I’m still thinking about to extend it with postal codes and make it public to everyone. Maybe. Time-management is not one of my primary attributes so far.
Tomorrow we have “beer and sausage” at our company, which is quite cool - I mean the fact that we do such things on company time and money. Each first Friday on every new month one department is organizing this little event. Last time we had Becks, this time we’ll have Berliner and sausages.
However (I love this word), I’m currently working on a new JavaScript lib, with a carousel, an interactive navigation and some tab switcher, a lightbox, some fx wrapper and other stuff, based on prototype and scriptaculous. That it nothing phenomenal, but I try to keep it slick as possible and of course flexible. ATM you still can apply any function to the callback functions »beforeStart« and »afterFinish«, via one method call. I’ll post the code when I’ve got something like a milestone release, which seems to be end of July.
Tags: balcony, beer and sausage, javascript, MySQL, neighbours, Thursday, work
Posted in code, motd, personal | No Comments »
March 14th, 2008
@biophonc
I had to update WP, because someone managed to exploit a security hole in my blog. I guess it was the draft exploit - but I am not sure. Also I’ve decided to use the open_base_dir restrictions, because the guys who tryed to hack my/our server, tryed to install a ftp server and if I’m right, then the kids call them self “Caffeine’s Heaven”. I did that ways back in the days too - and luckily I’ve discovered it in time. Also I’ve moved to a subdomain and added some rewriting rules for my blog (301).
Anyhow!
I’ve to hurry, because it is already 9:30am and I’m still sit here in shorts 
Posted in code, digital life | No Comments »
February 23rd, 2008
@biophonc
if you need a very easy regex, to validate emails - here’s some I wrote:
^(([\da-z���\.\_\-\~]+)\@([\da-z���\.\_\-\~]+)+(\.\b[a-z]{2,}))$
Tags: code, email, javascript, validate
Posted in code | No Comments »