Moazzam’s Ramblings

7Jun/100

The world of programming

A friend of mine sent me this picture which shows who did what in the field of computing. He found the picture on Smash magazine's website (don't know where). But here it is:

About programming

Click to enlarge

Filed under: Uncategorized No Comments
2Oct/090

Removing mywebsearch as the default search engine from Firefox

If you have accidentally installed myWebSearch as the default search engine for firefox, and want to remove it then do the following :

  1. Close Firefox
  2. Go to C:\program files\mozilla firefox\chrome\
  3. Delete the files m3ffxtbr.jar and m3ffxtbr.manifest
  4. Go to c:\program files\ and delete the mywebsearch folder, if it is there.
2Sep/093

HTTP Request class for Android

Here is a class that can be used to make HTTP get and HTTP post requests. I haven't commented everything but the usage should be pretty clear from the method signatures.

Note: This is for Android 1.5.

[java]
import java.net.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.apache.http.client.HttpClient;

import org.apache.commons.*;
import android.util.Log;

public class HttpRequest {

/**
* HttpGet - doesn't read cookies
*
* @param sUrl
* @return
*/
public static HttpData get(String sUrl) {
HttpData ret = new HttpData();
String str;
StringBuffer buff = new StringBuffer();
try {
URL url = new URL(sUrl);

BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((str = in.readLine()) != null) {
buff.append(str);
}
ret.content = buff.toString();
} catch (Exception e) {
Log.e("HttpRequest", e.toString());
}
return ret;
}

/**
* HTTP post request
*
* @param sUrl
* @param ht
* @return
* @throws Exception
*/
public static HttpData post(String sUrl, Hashtable ht) throws Exception {
StringBuffer data = new StringBuffer();
Enumeration keys = ht.keys();
while (keys.hasMoreElements()) {
data.append(URLEncoder.encode(keys.nextElement(), "UTF-8"));
data.append("=");
data.append(URLEncoder.encode(ht.get(keys.nextElement()), "UTF-8"));
data.append("&");
}
return HttpRequest.post(sUrl, data.toString());
}
/**
* HTTP post request
*
* @param sUrl
* @param data
* @return
*/
public static HttpData post(String sUrl, String data) {
StringBuffer ret = new StringBuffer();
HttpData dat = new HttpData();
String header;
try {
// Send data
URL url = new URL(sUrl);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

// Get the response

Map> headers = conn.getHeaderFields();
Set>> hKeys = headers.entrySet();
for (Iterator>> i = hKeys.iterator(); i.hasNext();) {
Entry> m = i.next();

Log.w("HEADER_KEY", m.getKey() + "");
dat.headers.put(m.getKey(), m.getValue().toString());
if (m.getKey().equals("set-cookie"))
dat.cookies.put(m.getKey(), m.getValue().toString());
}
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
ret.append(line);
}

wr.close();
rd.close();
} catch (Exception e) {
Log.e("ERROR", "ERROR IN CODE:"+e.toString());
}
dat.content = ret.toString();
return dat;
}
}
[/java]

You will also need this class along with it.

[java]

import java.util.Hashtable;

public class HttpData {
public String content;
public Hashtable cookies = new Hashtable();
public Hashtable headers = new Hashtable();
}
[/java]

10Aug/090

Google Voice Review

I had signed up for Google Voice a week or so ago and I got an email today saying that I was invited to test it out. So, here is a somewhat detailed review of it. Keep in mind that it is still in testing phase :) .

How does it work?

Google lets you choose a phone number for your Google Voice account. It will, then, ask you for your phone number. You can give it a number of your mobile/cell phone or your home phone. Whenever someone calls your Google voice phone number, you home phone or cell phone will ring (depending on what phone number you gave Google when signing up).

You can have more than one phone ring when your Google Voice number is called. And, you have filter calls. For example, you can have your cell phone ring if your business clients call and have your home phone ring if your friends call. This can be used to prioritize your phone calls.

How do you place calls you ask? You can login to your Google Voice account from your browser and click on place call button. It will ask you for the phone number you wish to call and which phone it should ring (your home phone or any other phones you have added). It will, then, call you on the phone you specify, then it will call the other person and connect you both.

If you wish to access it from your phone (make phone calls, send SMS, etc), Google has made mobile apps for Android and Blackberry. They also made an app for iPhone but Apple rejected it. Google also has a mobile version of Google voice website, so you can always login to your account through your web browser.

[screenshots]

The features:

- ListenIn - You can listen to your friends leaving your a voicemail. You don't have to wait will they are done recording it.

- Record calls - This, I think, is a great feature. You can record your calls whenever you want. It can be at the start of a conversation or in the middle. Press 4 to start recording and press 4 again to stop recording.

- Switch phones - If you are talking on your mobile phone and the voice quality is bad, you can hit * on your mobile phone and all other phones you added to your voice account will start ringing. You can, then, pick up the phone with best reception and start talking again without anyone noticing ;) .

You can also make international calls. And, Google has very cheap rates. It would have been good to have unlimited international calls for a flat rate (like MetroPCS does) but it still is better than most international calling plans out there.

It sounds too good to be true

Depending upon how important your privacy is to you, it might be. I read Google's privacy policy. It states that even after you have terminated your account, your phone calls, voicemails, SMS, etc will remain on Google's backup systems. I don't know if other phone carriers that (I should probably read their privacy policy and find out - it's good to know) but yeah. They don't say whether your voicemails, etc will be deleted permanently if you were to delete them.

This shouldn't come as a surprise, though. Gmail does the same thing. Your emails are never physically deleted from their servers. They are just marked as deleted so you don't see them anymore.

Visit these links for more information:

http://www.google.com/support/voice/bin/answer.py?hl=en&answer=115037

http://www.google.com/googlevoice/legal-notices.html

http://www.google.com/googlevoice/privacy-policy.html

http://www.google.com/support/voice/bin/answer.py?hl=en&answer=154724

Filed under: Uncategorized No Comments
29Jul/090

Cheap cell phone plans

Almost a century ago (when my grandparents were young) land lines were considered to be very advanced technology. Dial tone phones came out when I was a kid. In just a few decades, phones have become so common and mobile that they have become a part of almost everyone's daily life. Cell phones (or mobile phones) are now so common that everyone and their mother has one. We all know where there is a need, there is someone taking advantage of that need. So, we have carriers like Tmobile, Sprint, Bell, etc. charging their customers based on the minutes used.

The cell phone industry underwent another change (in USA) about a year ago. What was the change? Flat rate plans for cell phones! What was its cause? An unknown company - Metro PCS - that came out of nowhere and took over a chunk of cell phone users with its cheap prices. Their lowest plan goes for $30. It doesn't have voicemail or anything else. However, you can make as many calls as you want and you can receive them. For about $15 more, you can get voicemail, etc. And, unlimited data, unlimited texts, unlimited calls and unlimited international calls.

Even land lines don't offer international calls for that price! Metro PCS successfully grabbed customers from various national service providers *cough* like Sprint and Tmobile *cough* .

What did this cause?

This made cell phone carriers (at least some of them) rethink their plans too. Sprint is not offering a $50 plan with unlimited calls, unlimited texts and unlimited data. Tmobile is offering a $50 ($89 for families) plan for unlimited calls to already existing customers. You have to get text and data separately.

What's the catch?

Metro PCS has great service is metro cities like New York City, Seattle, etc. It's reception is bad in other areas. However, they are working on increasing their coverage. And, they don't have a very wide selection of phones. In fact, they have only one smart phone. Since Metro PCS operates on CDMA network, you cannot use their service with your current phone (assuming you have a GSM phone like me).

Sprint did the same thing. For their $50 unlimited everything plan, they have a custom set of phones which are regular phones  and they don't offer this service with smart phones. This means if you want to browse the net, you are stuck with the phone keypad and a small screen which means you won't be using that unlimited data a lot. I have seen a lot of people text like crazy on regular flip phones so I think people will use that regardless of their phone.

Tmobile' service is $50 for only calls. If you want unlimited text, it is additional $5 and unlimited internet is $20. The good thing, however, is that it works on a GSM network so you can use it with any GSM phone. The bad thing? Tmobile drops calls very frequently. If your friends text you today, you might get that text tomorrow. Sometimes even voicemail is delayed. The data, on the other hand, is good.

ATT seems to be doing its own thing with iPhones. As far as I know, they charge over a $100 for 400 minutes. However, a lot of people are willing to pay that because of their iPhones.

For more information, visit the links below:

http://metropcs.com

http://tmobile.com

http://sprint.com

29Jul/090

Google voice

Yes, people. It's out. At least for the test phase Google didn't really keep it a secret that it wants to get into the telecom industry. And, we all know that when Google does something, it changes everything! :)

Google voice is an application that runs on your phone and PC. Google will assign you a phone number. If anyone calls that number, your phone receives the call. You can check your voicemail on the phone or your PC. You can even read transcripts of your voicemail (speech to text). Another great thing about Google voice is that it lets you select which phone should ring when someone calls. For now, you have to get an invite to be able to use Google voice (please send me an invite if you have any left :) ). However, that will hopefully change in the future.

What does it mean for us as consumers? Hopefully a change in the way telecom industry operates and cheaper prices (a big shout out to MetroPCS for cheap cell phone service). There is one concern, though. Google owns an email service, a video service, online albums, and now phones. Can this lead to the "big brother" concept where "they" watch everything we do? Gmail scans through your email to show you relevant ads.  Google states that no human being goes through them but how can we be sure? I know the whole privacy thing is an issue of its own. I would like to hear your (the reader's) thoughts on this. Please leave comments and let me know what you think :)

1Jul/090

Producer/consumer queues in C#

What is a producer/consumer queue

In a restaurant there are chefs in the kitchen who wait for orders from customers. As soon as a customer orders something, they (the chefs) make it and serve it to them (the customer). A producer/consumer queue is the same. There are workers who wait for a "job" to be entered into the queue and then process it when it is entered. The advantage of this method is that the workers consume negligible resources when they wait for a job to be added to the queue. So, "jobs" can be finished as soon as possible.

One of the advantages of this approach is that the class which adds the jobs to the queue (the customer) doesn't have to wait for the workers (the chefs) to finish what they are doing. It will keep inserting the jobs (orders) and the workers (chefs) can take their time processing it (cooking the order).

How do we accomplish this in C# you ask? Simple. The workers will check a job queue to see if anything has been inserted. If they find that there is a job waiting to be processed, then they will remove it from the queue and process it. This way, two workers won't end up working on the same job. If there are no jobs in the queue then the worker will go to sleep and wait for a signal to wake up when something is added to the queue. The "job manager" or the class that adds the jobs, will insert nulls if it is done adding jobs.

If that was hard to understand, let me explain it in another way. The restaurant will hire 20 chefs and 1 waiter. The customers will place their orders with the waiter. A chef will ask the waiter if he needs to cook anything for a customer. If the waiter says, "Yes, a customer ordered lamb curry" then the chef will start cooking lamb curry. If the orders of all customers have been cooked (or are being cooked by some other chef), then the chef will go to sleep and ask the waiter to wake him up if a customer orders something. However, the waiter will not wake up a specific chef. He will wake up all the chefs when an order comes in. The chef who wakes up first will start cooking and the rest of them will go back to sleep (and ask the waiter to wake them up if any other order comes in). At the end of the day, the waiter will give blank orders signaling to the chefs that they are done for the day.

Now that we know what a producer/consumer queue is, let's see how we can implement it in C#.

Frist we will take a look at the class which will "consume" the jobs - the resaurant containing the chefs and the waiter.

[csharp]
using System;
using System.Threading;
using System.Collections.Generic;

public class WorkerQueue : IDisposable
{
/* We will store our worker threads in this list. */
private List threads = new List();
/* The number of worker threads to use */
private int threadsToUse = 20;
/* synchronization lock */
private object locker = new object();
/* The queue in which jobs are stored */
private Queue jobs = new Queue();
/* wait handle - used to wake up sleeping threads and to make them wait (sleep) */
EventWaitHandle wh = new AutoResetEvent(false);

/* public variable for accessing threadsToUseProperty */
public int ThreadsToUse { set {threadsToUse=value;} get { return threadsToUse; } }

/* The constructor of this class */
public void WorkerQueue()
{
/* In the constructor, we will start worker threads, which will
* wait for a job to be entered into the queue.
*/
for (int i; i {
Thread t = new Thread(work);
threads.Add(t);
t.Start();
}
}

/* This is the method that other classes will use to add jobs to the queue
* All it does it, add the job to the queue and signal the worker threads
* that something has been added, so they can wake up and process it
* (if they are asleep). If the worker threads are already awake, then
* wh.Set() will have no effect (and won't error out)
*
* This is the waiter taking orders
*/
public void AddJob(string item)
{
lock (locker)
{
jobs.Enqueue(item);
}
wh.Set();
}

/* The method that will be used in worker threads. This will check our job queue
* to see if any jobs are available. If any job is available, then it will process that job
* and check for more jobs. If there are no jobs in the queue, then it will go to sleep
* (by using waitHandle.WaitOne method) until a new job is entered into the queue.
*
* In this method, we will end the worker queue by inserting nulls in the queue,
* so this worker thread will watch out for that and kill itself (by returning control)
* when it sees a null.
*
* This is our chef
*/
private void work()
{
while (true)
{
string item = null;
lock (locker)
{
/* chefs asking the waiter if anything needs to be cooked */
if (jobs.Count > 0)
{
item = jobs.Dequeue();
/* return if a null is found in the queue */
if (item == null) return;
}
}
if (item != null)
{
/* if a job was found then process it */
Console.WriteLine(item);
}
else
{
/* if a job was not found (meaning list is empty) then
* wait till something is added to it
*/
wh.WaitOne();
}
}
}

/* When the object of this class is about to be removed from memory
* we will signal all the worker threads to stop by inserting nulls in the queue
* and then we will wait for them to finish the jobs already in the queue
*
* Letting everyone know we are done for the day
*/
public void Dispose()
{
for (int i=0; i {
AddJob(null);
}
for (int i=0; i {
threads[i].Join();
}
}

}
[/csharp]

Now that we know what the restaurant looks like, let's take a look at the customer (the producer which will add the jobs)

[csharp]
using System;

public class Customer
{
public static void Main()
{
WorkerQueue q = new WorkerQueue();
q.AddJob("Lamb curry");
q.AddJob("Beef Steak");
}
}

[/csharp]

1Jul/091

Dua for setting of a debt

If you are in debt, then you should recite these duas (in images).  [ From "Fortress of a Muslim" ]

Dua

Dua

Dua

Dua

15May/091

The Downtown Boathouse for kayaking

The downtown boathouse is located on Pier 40, 72 and 96  in Manhattan. It is operated by a group of volunteers who love kayaking and (I think) want everyone to experience the joy of kayaking. 

The whole thing is free and they provide all the equipment, and teach you how to do it. You can kayak for 20 minutes at a time (then you have to bring the kayak in and wait in line if you want to do it again). They do this to make sure everyone gets a chance to kayak.  The only thing I didn't like much was that you can only kayak in an an enclosed area in the bay. They don't let you out of it. They do it for your safety but still!. Oh, and they have single kayaks (operated by one person) and double kayaks (which are operated by 2 people). 

They also take you on 3 hour guided tours of the hudson river. The only requirements are that you be physically fit (as you have to paddle for 3 hours straight) and that you know how to swim. The tour begins at 8:00 AM so you have to be there pretty early. 

For more information, you can visit their site at: http://downtownboathouse.org/

11May/090

Android 1.5 SDK Released !

Google has released Android 1.5 SDK. This release is based on the cupcake branch in Android's repository. Cupcake was a modified version of the SDK written by a group of independent developers and functioned better than the 1.0 SDK. Android 1.5 SDK also has other enchancements like a better profiler. For a list of all changes and enhancements, please visit: http://developer.android.com/sdk/RELEASENOTES.html