A Script a day, keeps boring away!

Being a software engineer makes life easier, it can save you time, money and hassle. It makes things just easier, cooler without sacrifices!

My Favorite radio show shifted their air time 2 hours!! No Problem

In my way to work, I used to listen to a morning radio show, but one day, they changed it’s air time! one option is to go work late OR!! Create a cron job that runs every day at the show time and download from the radio live streaming url using wget for an hour and save the file to my dropbox folder, so I can play it from my mobile at the end of the day back to home!


0 2 * * * /usr/local/bin/wget -O /Users/AMTourky/Dropbox/Mega_FM/megaFM_3eliesh_$(date '+%m-%d__%H-%M').mp3 http://mgstrm9.twesto.com:7281/stream1.nsv ; sleep 3600; kill $! ; /dev/null || : ;

A 95% discount snap offer on an item, Great BUT!!

Untitled 2

 

The largest e-commerce site in the Arab world made a snap offer on an item, a 95% off the price, from 400 EGP to 20 EGP BUT it’s a little bit tricky! the item will be available in random times for 3 days, so the probability of getting one is too low!

This time I needed something that can do more than just hitting a URL! a nodeJS script that checks the site’s homepage every minute to see if the item is available, if yes, send me a notification on my mobile (I used a dead simple push notification service PushBots).

var checkItem = function()
{
	async.waterfall(
	[
            // used wget instead of the 'http' node package because they didn't return the page normally!
		function(callback) { exec('wget  https://www.home/page/url\ -O page.html', callback); },
		function(stdout, stderr, callback) { fs.readFile('page.html', 'utf8', callback); },
		function(pageContent, callback) { isItemAvailable(pageContent, callback); }
	],
	function(error, isAvailable)
	{
		if ( isAvailable ) { notifyMe(); }
	}
	);
};
var isItemAvailable = function(content, callback)
{
	var lines = content.split('\n');
  	for(var i = 0 ; i < lines.length ; i++)   	{   		var line = lines[i];   		if(line.indexOf('R207') >= 0)
  		{
  			var availabilityLine = lines[i-17];
  			var priceLine = lines[i+9];
  			if(availabilityLine.indexOf('sold_out') < 0 && priceLine.indexOf('20') >= 0)
  			{
  				callback(null, true);
  			}
  			break;
  		}
  	}
	callback(null, false);
};
var notifyMe = function()
{
	instapush.notify(...);
};
setInterval(checkItem, 60*1000);

 

2016-01-23 23.35.14
It arrived the second day 😀

Waiting on online customer service queue for long time!! No Problem

On one of the worst online customer service I’ve ever dealt with they had a very long queue, they start responding after about 30 minutes, and if I didn’t respond on a minute or two, they skip me and pick the next customer. Waiting up to 30 minutes in one page or checking it every minute is unacceptable, but for a software engineer, this can’t be the case! a simple event listener on the chat dom element to be triggered when the agent responds and an Alert will do the trick, I pasted the code below into the developer console and went doing my work!

var isNotified = false;
document.addEventListener('DOMNodeInserted',
	function(evt)
	{
		// ignore the time counter since I joined the queue
		if (!isNotified &amp;&amp; evt.srcElement.className != 'digit')
		{
			alert('Here we go!!');
			isNotified = true;
		}
	}, false);

A lot of times I’m interested in some data from a specific web page, or want to know how frequent it change, or when it change, being a software engineer make all of this an easy task, an automated task, I can create a robot to do it for me. Some times it just require a technology geek to accomplish a cool task; adding a large HDD to home network and give the family an extra storage to their phones/tablets or using an old phone as a surveillance camera while traveling and setup a DDNS service to check it remotely.

Being a software engineer opens a new dimensions in one’s life, changes perspectives and gives a new flavor to almost every thing!

Advertisements