August 2008 Archives

I was given today a little project, as a freelancer sometimes you have to prepare for the unthinkable even though their title begs to differ. I mean today it's been a spacey day, wasn't that bad since I learned something too.

So, you must be wondering what happened? If you are a developer, imagine 3,000+ \r\n invading the HTML source code. Plus different \r\n with 3,4,6 spaces, obvious the designer who did the layout surely like to annoy others. \r is carriage return while \n is newline, windows style, I think.

What does this do? Nothing, you can't see it when you are displaying the HTML, but if you check the source code then you notice big spaces and carriage returns.

Solution? My solution is pretty straight foward, yet it lacks efficency.

In the PHP you must get the HTML in a variable.

Then to remove the excessiveness our smart designer added:

$regex = preg_replace('{^[^>]([\r\n])?( | )?([\r\n]+)$}mx','',$html);
$regex = preg_replace('#([ ]+[\r\n][\r\n])#x','',$regex);
$regex = preg_replace('#(([\r\n]{3,}|[\r\n]{4,})([\r\n]+))#x','
',$regex);

I started by telling the regex engine to replace after > is set, search for possible returns and newlines is there are any present, search 3 spaces OR 1 space, optinally. Search for one or many \r\n and replace them with nothing.

Later on the second preg_replace, check for one or many spaces followed by two /r/n

And lastly, search 3 /r/n OR 4 /r/n to unlimited, followed by one /r/n+ and remove them.

I think I could have done better, but since deadlines are not something you can negotiate with--well, you get the idea. This got it done and that's all it matters. Luckily, I compared the line numbers, the original file had 4312 lines and the modified one ended with 313 lines.

Break Brains

Cheers

Lights out

| | Comments (0) | TrackBacks (0)

Today it was the first power outage that took around six hours to fix. I was alone with my big brother and sister at home, our parents are already working since their vacation ended a week ago, we can't help but to wait for our time to resume our studies. Someone like me who has been sitting on the chair "daily" knows it's a bit weird to go outside. It wasn't bad, infact if it happens again I wouldn't mind either. Today there was something I missed that have kept me thoughtful through this unforseen day.

When someone starts doing a chore, or an action that is repetitive, we tend to give all our attention. Our lifes are now "intertwined" with technology. We sit in front this computer, chat, blog, play, make dramatic events, argue, insult and laugh. The distraction it creates is so much we forget our surroundings, most of the time we forget the little details that keeps the family together. It is sad.

What has happened to our old lives? Most of our time we spent the sitting in front of a ridiculous virtual world. What about this mundane world? We have let ourselves flashes and metal take the social status of everything.

These six hours gave me the chance to take ahold of what was broken to pieces. We sat down. At first we just stared at the walls and our minds mumbling innerly "when will the electricty come back". Thirty minutes passed, we started talking of what have happened lately and chit chat for hours.

Hours passed in a blink of an eye, and I realized that it was wrong to condemn something that has never happened. It didn't matter anymore, the realization today has left me wordless, to the point that If I was going to condemn someone it would be my lack of words to be spoken.

The hardest part for me is constructing a bridge to communitcate again. I can't believe I have missed this, as I am an observant person. I tend to attempt to breakthrough possible problems before they happen, yet I feel powerless since the lack of communication has caused so much damage over the years. I wouldn't know what to say, and I can't proudly say "Hey, I know what went wrong!"

videoCast PHP Parser

| | Comments (0) | TrackBacks (0)

Well, here I am again, with a working parser that might be helpful for your development, especially if you are looking for a youtube link parser.

What is this?

videoCast PHP Parser is a pretty simple class that helps you parse links like http://vimeo.com/613460 into an embedded HTML. It supports Youtube, Dailymotion (permalinks only), Metacafe, Revver and vimeo.

How to use?

This is the easy part. Upload the parser to your site and in your php file.

require_once 'viCastPHP.php';

$parseVideos = new viCastPHP();
$parseVideos->getFormat($_POST['text']); // You will need to change this and adapt it to your needs

Another way of using this parser is

$parseVideos->limitParse(3)->excludeSites(array('youtube','metacafe'))->getFormat($_POST);
or
$parseVideos->limitParse(3)->getFormat($_POST);

getFormat must be called last for it to take effect of the changes.

excludeSites() only accepts arrays or a plain string.Right now the strings you may put in the array or string are only: "youtube","dailymotion","revver","vimeo","metacafe".

limitParse() only limits # for each pattern. (I'm thinking of extending this but that depends now)

What was this for?

I created this for learning purpose for both PHP5 OOP and Regular Expressions. I thought I'd share it with you guys :).

Get the parser NOW!

Yesterday out of boredom I started playing with Regex (Regular Expressions). I somehow got carried away and found that regex is actually fun once you learn it. It's like playing chess, all the strategy you have to do to match and process your text is part of winning over content.

Well, what I did is pretty little, that is converting plain urls like

http://www.youtube.com/watch?v=PF-cXjxgREQ

To

It also supports links with http://au.youtube.com/watch?v=PF-cXjxgREQ and so on. Of course youtube alone wasn't enough so I threw at it Metacafe, revver, dailymotion, vimeo support.

Of course, an issue came up with dailymotion, that is the way the "categorize", so the URL is affected and it only works with Permalinks. I'm currently working on a fix that might actually fix the redundancy of "/section/section/section/".

Try the parser, live!
Paste links like

http://www.youtube.com/watch?v=pkuLh4u0H8E
http://www.dailymotion.com/video/x5qbhc_99-dreams_shortfilms
http://www.metacafe.com/watch/1269694/trick_shot_masters/
http://revver.com/video/1076971/sexy-fitness-break-tight-glutes/
http://vimeo.com/707539

Paste them inside the textarea :) (of course!) Anyway, this will be available under New BSD License as soon as I finish a few things.

I'm still new at regex! Can't wait to master it soon :)

Digg.com phailing?

| | Comments (0) | TrackBacks (0)

It's been a while since I visited digg.com. I don't know why but I get this feeling that it's being overrun by 12-17 year old kiddos submitting silly stuff. Sadly it somehow ends up in the front page, so digg is kinda becoming the next 4chan which is actually the most horrible thing that can happen besides hearing that Kevin Rose is getting a sex change (of course this is just a rumor! err).

Anyway, going back to topic, as if there's any, this is a damn blog (a.k.a: weblog, diary, net diary, a system used to vent about the government and how much they hate it, not limited to personal attacks) . Furthermore, Root of All Evil has enlightened me on how much does blogging actually sucks.

Wait, what wasn't that topic but here we go again! Now that's digg.com phailing hard I wonder where I'm going to get my daily fix of interesting articles/sites and not an endless loop of

Politics
Memes
Something photoshopped
Britney
Idiots pasting memes
Hollywood idols...
Batman..

I think I'm just going to take a break and read a book...

About this Archive

This page is an archive of entries from August 2008 listed from newest to oldest.

July 2008 is the previous archive.

September 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.1