Archive for December, 2009

Recall: 2009

December 25th, 2009

Couple days ago I was reading my last blog in 2008 and became a little bit nostalgic. One year is not a long time, but lot’s of things can happen in one year. Saying it again, never had such expectation out of time but I must say 2009 was the BEST year of my life so far! Because, I got married in 2009! I got married to love of my life in July, 22nd :)

Spoke at tech seminar arranged by PhpExperts group, and that was a great day for me to be in front of lots of talents from Bangladesh. It helped me to understand this local community I know and I love from my heart. I met lot’s of people I know from twitter/friendfeed/facebook but never saw them before. Though I couldn’t meet all the guys I know…and well, it helped me to get closer with some talent speakers , whoa!

Working at Trippertlabs is always fun, what a year it has been for this company! Working on some exciting iPhone projects and after a couple days you see them in the top list at iPhone app store, how does it feel? I can remember the weekend we worked on some iPhone quiz applications and one of them went to #1 position in the free app category. This excitement continued through out the year dude but out of all these biggest news from my company was acquisitions by Playdom!

“Amra Positive” idea came from some frustrations and interest to learn python. This is a personal project I developed for local community to share all good news within 150 chars. I was glad to receive some positive response from all kinds of users. I hope to upgrade this app soon on spare time but I will love to get more feedback and advices from you guys :)

What else? There are lots of things to recall from 2009. What an eventful year! But let’s not be more geek on this…let me remind my promise that I wanted to have Eid-ul-adha with my village people. This is one of the place I truly love to be. This year wasn’t any exception. As usual I had my Eid with my village people with some different moments….

What’s gonna happen in 2010? There’s gonna be lots of changes in my life, Uhm, but no guess…as I always say, wake up every morning and do what you enjoy the most…i will be keep following this theory by keeping very less expectations….

Regular Expression to Find All Mentioned Names by ‘@’

December 12th, 2009

Most of the time we use ‘@’ to mention someone’s name in email thread, forum, etc. How about to find those mentioned names using PHP regular expression? Let’s consider the following text.

“Hey @Junal how about going for a vacation to @Srimangal? @Jewel said it’s an awesome place”
We will find all names that is mentioned by @ here. So let’s write the pattern first.

$pattern = “/^(?:[a-zA-Z0-9?. ]?)+@([a-zA-Z0-9]+)(.+)?$/”;

See, first portion of the pattern is optional, some one can start your name @junal or hey @junal right. And then we are matching with ‘@’ separating them from @ sign. Rest portion of the patter is quite easy, as we can keep text after the name (I.e @junal you suck)

Ok, now let’s use the php preg_match() function to find the matches. If we find the matched it will return 1 else 0.

$pattern = "/^(?:[a-zA-Z0-9?. ]?)+@([a-zA-Z0-9]+)(.+)?$/";
$str = "Hey @Junal hey how are you?";
preg_match($pattern, $str, $matches);
print_r($matches);
//Output : 
Array
(
    [0] => Hey @Junal hey how are you?
    [1] => Junal
    [2] => hey how are you?
)

So, if we want to find first matched name then it’s pretty straight forward to get it from $matches[1]
but what if we want to find multiple name from a text? Well, then we have to search $matches[2] if there is anymore mentioned name wit @ right?… let’s do it this way…

do {
   preg_match($pattern, $matches[2], $more_matches);
   $name_list[$counter++]  = $more_matches[1];
   $count = count($more_matches);
   $matches[2]=$more_matches[($count-1)];
   $more_matches = "";
   } while($count>=3);

this above code might be confusing. So let’s see the complete function that returns us an array of names that are mentioned by ‘@’ and well, we will also remove the duplicate names.

< ?php
/*
 * isn't the name self explanatory ?
 */
function giveme_names_from_at($str) {
    $pattern = "/^(?:[a-zA-Z0-9?. ]?)+@([a-zA-Z0-9]+)(.+)?$/";
    $str = trim($str);
    preg_match($pattern, $str, $matches);;
    if($matches) {
        $counter = 0;
        $name_list = array();
        $name_list[$counter++] = $matches[1];
 
        do {
            preg_match($pattern, $matches[2], $more_matches);
            $name_list[$counter++]  = $more_matches[1];
            $count = count($more_matches);
            $matches[2]=$more_matches[($count-1)];
            $more_matches = "";
        } while($count>=3);
 
        if(!empty($name_list)) {
            $all_names = array();
            $i = 0;
            foreach ($name_list as $key => $value) {
                if (!is_null($value) && (!in_array($value, $all_names))) {
                    $all_names[$i] = $value;
                    $i++;
                }
            }
        }
        return $all_names;
    }
}
 
//Example 
 
$str = "Hey @Junal how about going for a vacation to @Srimangal? @Jewel said it's an awesome place";
$names = giveme_names_from_at($str)
print_r($names);
 
//Output: 
Array
(
    [0] => Junal
    [1] => Srimangal
    [2] => Jewel
)
?>

Ok well, output shows what we needed. But using regular expression is not always a good idea as it’s slower than standard string manipulation functions. How would you like to find these answers without using RE? Or can we improve this pattern to make It smarter?

Dear Brac Bank Internet Service, You Suck!

December 6th, 2009

Really pissed off at Brac Bank internet banking service. I have been using it for last 1 year to see my transaction, debit, credit etc. Link that they gave me to log in, wasn’t even with a domain name. But anyways, that’s not my headache. I’m happy as long as I get the proper information that I registered for.

Few days back, I tried to log in to see my transaction and stuff and it said site is down or moved to a new address.

Site was moved in a new address

Site was moved in a new address

I tried it after 2 days again, but no information regarding the change. Shouldn’t have the informed me that they moved to a new location? Don’t I deserve it as their customer? So I sent an email to their IT dep and asked about it, they replied saying …

“….This requires a higher level of security for our systems and processes. Therefore, we are asking all previous I-banking subscribers to register once again to ensure that the new security standards are maintained.

after reading this, first thing came in my mind was like “WTF”, why the hell I have to register or fill up a form again? Don’t you already have my all information. I have never seen this kind of service before from any site!

But what could I do, I went to Brack Bank and registered for it again. And today they sent me a new link and log in information to use the internet banking service. I was happy yay! But hey, when I went to log in from the actual link it says “This site only supports Internet Explorer”! What?!? I don’t use IE and when I have to use I use it in VB XP. Do you think I should login to XP just to use your service dear BB?

Sorry i dont use IE for browsing...

Sorry i dont use IE for browsing...

I’m sorry, but this is complete bullshit. Don’t Firefox and Chrome have Anti-fishing capability? Or .NET framework (site is developed on .NET) always asks you to restrict users with IE?

I don’t know what option I should choose now. But Brac Bank should be careful about their customer serive. Till now it sucks!

Get Adobe Flash playerPlugin by wpburn.com wordpress themes