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 »
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 »
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 »