Category > General

Using Twitter for sending server downtime alert

Emran Hasan » 25 March 2009 » In General, PHP, Programming » 28 Comments

Today I’ve written this simple PHP script to alert me through Twitter whenever our company’s local server is down. The script is called by a cron every 5 mins in my central hosting. Without much babble, here goes the code (if you’re interested to know why I needed this, that’s at the bottom of the post):

<?php

// Specify the target URL in your server
$targetUrl  = 'http://YOUR_SERVER_URL';

// Specify what the response is from the server
$targetText = 'Hello from Daredevil';

// We will be using cURL for fetching the content
$ch = curl_init();

// Set the params
curl_setopt($ch, CURLOPT_URL, $targetUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Get the response
$response = curl_exec($ch);
curl_close($ch);

// Are things in right place ?
if ($response == $targetText) {
    die('Site is up and running!');
}

// Nope, so here are the sender's twitter info
$username = 'SENDER_TWITTER_USERNAME';
$password = 'SENDER_TWITTER_PASSWORD';

// Receiver's twitter username
$receiver = 'RECEIVER_TWITTER_USERNAME';

// Alert message to send
$message = 'Daredevil is not responding, please fix ASAP!';

// The Twitter API address (new direct message)
$url = 'http://twitter.com/direct_messages/new.json';

// We will be using cURL for this
$ch = curl_init();

// Set the params
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$receiver&amp;text=$message");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

// Send the request
$response = curl_exec($ch);
curl_close($ch);

// Success or failure
if (!empty($response)) {
    echo 'Recipient has been notified.';
} else {
    echo 'No response from twitter.';
}

Why I needed this?

Recently we have setup a server at our office for committing work to a local SVN repository and have the QA test our work whenever they are ready. We also have a staging server where we do SVN update from this repo. Now, for the last few days, I’ve found the local server to be off due to a few reasons – but every time I realized this at night when I am back home and can’t do anything to turn it on. So I thought about this Twitter alert which is sent to my cell phone immediately when the server goes offline.

Btw, if Twitter doesn’t send SMS to your country, don’t worry. Check out the excellent service at Twe2 that I’ve been using for a couple days.

Cheers!

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Continue reading...

Tags: , , , , , , ,

A Workshop on “Freelancing IT Jobs – How to Make Yourself Ready”

Emran Hasan » 07 March 2009 » In General, Workshop » 3 Comments

Today I facilitated this workshop on Freelancing, organized by BDjobs.com. The primary focus of the workshop was to introduce the concept of freelancing to the attendee’s as well as to provide them with a general hands-on path on how to start freelancing. The total workshop covered a variety of sections starting from freelancing overview, freelance site reviews, tips on building a professional profile, the bidding process, tips on successful bidding, client management techniques, payment pitfalls, payment methods, etc.

You can download the presentation file here in two formats: PDF and Powerpoint.

The full workshop description is provided below. If you’re interested in attending the next workshop on April, get in touch with BDjobs.com.

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Continue reading...

Tags: , ,

Seven Things

Emran Hasan » 20 February 2009 » In General, Random » 10 Comments

Well, this seven unknown things internet meme has been circulating in the web for a while and I am joining after seeing this in a few blogs I follow. However, haven’t seen this in my blogger network from Bangladesh so hope it will make a few laughs.

So here goes seven random (weird) things about me:

1. The veins in my left eyes are dried up, so I practically use my right eye for everything…pirate king!

2. The real break in my programming life came when I went to a programming contest with a team and was declined to participate. We had our rights and they later let us in, but gave us a almost broken PC. We cracked three out of 5 problems straight in DOS edit as the compiler would hardly run :)

3. I do not watch TV programs for the last 5 years. DVDs and downloaded movies/TV series are the only source of entertainment. My most fav TV series is The X Files.

4. When I was a kid, I was damn fond of toys. I had a whole collection of figures from HE-MAN, J.I.JOE, Thundercats, Transformers, and a few others.

5. I was present only in 48% classes in my second year in college, whereas the rule of thumb was a minimum of 85%. After the test exams, I was given a punishment of attending to library from 8am to 5pm for 26 days where the only thing allowed is study (textbook only). No friends, no gossip, no newspaper.

However, I convinced my father that this punishment was imposed to me as one teacher did not like my attitude in his class; i made my father to the principal with an application where its mentioned that I cannot attend this due to medical condition. Principal had to agree and I only had to do it for 2hrs for the sake of records ;)

6. The first program I wrote for money was a file copying & renaming program in VB6 for $20. It would transfer some old mail server (don’t rem the name) files from an old server to a new one and would rename their extension to match Microsoft Exchange. Exchange was smart enough to read & convert automatically, so it looked as if the program did the conversion. Heh heh.

The fun part is, later another company was somehow convinced that it’s a huge work and went into a partnership with me where I received a down payment of $1500 and a 30% profit sharing with the same application plus a few UI improvement. Not bad ;)

7. I never studied Computer Science nor did any programming classes. I have been in business studies concentration since school and did my bachelors in Business Administration (BBA). Currently I’m pursuing my masters in Business Administration (MBA) as well.

Here are the seven people I’m tagging:

1. Hasin Hayder
2. Anis Uddin Ahmad
3. NHM Tanveer Hossain Khan
4. Omi Azad
5. Trivuz
6. M.M.H Masud
7. Suhreed Sarkar

And here goes the rules:

- Link your original tagger(s), and list these rules on your blog.
- Share seven facts about yourself in the post – some random, some weird.
- Tag seven people at the end of your post by leaving their names and the links to their blogs.
- Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.

Enjoy!

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Continue reading...

Tags: , , , ,

Code Updates (HTTP class, Extended CodeIgniter Model, Cross-domain AJAX transport)

Emran Hasan » 18 February 2009 » In Code Igniter, General, PHP, Programming, Web Development » 10 Comments

Greetings to all the readers of my blog.

Many of you have been writing to me in the last couple days when I took the site down. The main objective was to add the new theme and push a few code updates of the existing libraries. I really appreciate your concern and would like to reassure you that the site is up and will be up as usual :) Now, besides the slightly customized theme from Elegant Themes, I have put a few code updates. They are detailed below:

Extended Model for CodeIgniter

The original version of the Extended Model for CodeIgniter has been serving many people well. Although most users loved the nifty functions of the Model, many (including me) didn’t like the hacking of CI core to get this functionality. With the release of CodeIgniter 1.7, we can avoid that as we can now overload the Model class of CI like the other libraries. Follow this instruction:

1. Download the updated version from here
2. Put it in your application/libraries folder
3. In your model files, use it this way: class Product extends MY_Model
4. Everything else is same just like the original one

HTTP Class

There is not much update in this class except for a few bug fixes (thanks to you guys). Also, I have included a license file in the package as many of you have asked. It’s released under the MIT license. The original post is here for reference.

Download the update from here and the API reference is here.

Cross-domain AJAX calls using PHP

A minor bug fix in the code. Thanks to a few of you who pointed them out. Original post is here. Download the update from here.

I have accelerated plans for the blog in 2009 so stay tuned for some worthy posts in this month. And do write to me if you feel you have any questions/ideas/suggestions.

Cheers!

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Continue reading...

Tags: , , , , , , , , ,

Nokia N81 8GB

Emran Hasan » 10 December 2008 » In General, Mobile phone » 16 Comments

Today I bought a Nokia N81 8GB smartphone from my friend Nesar. This is an upgrade from my previous Nokia 6300, which I’ve been using for 1.5 year (thats the longest time I’ve used one model). The Nseries of Nokia has been attracting a lot of people lately, with their great music and photo capture features. One of my colleagues, Anis, also bought N73 just two months back.

Nokia N81 8GB
Nokia N81 8GB

Now, good points first. The N81boosts an extremely loud set of sterio speakers – combined with its Music Express, it delivers the highest quality of music I’ve ever purchased. Combined with the built-in FM radion, the dedicated music keys, and a multimedia menu – this is a music powerhouse, thanks to the all new Symbian 9.3 OS.

The Symbian OS is superb with all the applications and now has some stunning gameplay capabilities. The phone also has all kind of connectivity point you might need – GPRS, EDGE, Wifi, Bluetooth, WLAN, 3G. And don’t forget the built-in 8GB memory.

The only downside of this phone is the camera. It’s a 2 megapixel camera – which I don’t have any clue how got into a Nseries phone. If there is not enough light, the pictures are somewhat blurry. It has flash and a number of picture modes, so its a decent one – but nowhere in comparison with other Nseries 3.2mp and 5mp cameras.

All in all, here are the facts:

  • 2.4” QVGA main color display (320 x 240 pixels), up to 16.7 million colors
  • S60 3rd Edition Feature Pack 1 based on Symbian OS v9.2
  • Dedicated media keys for quick and easy access to music and video
  • WLAN IEEE802.11 b/g with UPnP (Universal Plug and Play) support
  • Bluetooth Specification 2.0 (profiles supported: DUN, OPP, FTP, HFP, GOEP, GAP, SPP, HSP, BIP, A2DP)
  • Micro USB 2.0 Full Speed (mass storage class)
  • Nokia AV Connector 3.5mm
  • Up to 2 megapixel (1600×1200 pixels) camera, MPEG-4 VGA video capture of up to 15fps
  • Zoom: digital up to 20x
  • Front camera (CIF)
  • Video call and video sharing support (WCDMA network services)
  • Integrated flash (modes: on, off, automatic, redeye reduction)
  • Rotating gallery with Navi wheel support
  • Nokia Nseries digital music player supports MP3 (VBR), AAC, eAAC+, AAC+, WMA/M4A, WAV
  • OMA DRM 1.x, 2.0, Windows Media DRM (OTI/OTA with Nokia Music Store*)
  • Synchronize music with Windows Media Player 11
  • Media keys (play/pause, stop, forward, rewind)
  • Stereo FM radio (87.5-108MHz /76-90MHz)

Let’s see how long it can serve my ever-growing thirst of technology :)

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Continue reading...

Tags: , , , ,