Categories
Uncategorized

Quick JSON Parsing with C#

It’s quite sad that Microsoft doesn’t ship a decent JSON parser with .NET, not even the latest .NET 4. If we look at the web, everyone uses JSON today. Without no out of the box support for JSON, I was having much troubles consuming different APIs Services. But just a few moments ago, I found the JSON.NET project on CodePlex. The library has cool Linq integration that makes JSON parsing easier.

For test purposes, I am outputting this JSON string on http://localhost/json.php :

After downloading the JSON.NET package, I added a reference to “Newtonsoft.Json.dll”. Then used the following code snippet (C#) to parse the data and print the values from a console app:

Categories
PHP Python

A Python Script Every PHP Developer would love

PHP’s mail() function is one of the best things in the language. It is also the item most people suffer with while working locally. So whats the problem? The problem is we usually don’t have a SMTP server installed on our local machines (while we do in our production servers). PHP doesn’t do magic, it can’t send the emails without a SMTP server. Since you don’t have one, don’t go nuts seeing PHP can’t deliver your email 🙂

Remembering this problem, I spent 20 minutes hacking a Python script that does the magic for your PHP setup. The Python script creates a dummy SMTP server and listens to the port you select (defaults to 25). Keep the script running while using the mail() function in PHP. You shall get detailed yet readable mail data printed on your screen.

So isn’t there the nice smtp4dev tool and mail servers like postfix? Why re-invent the wheel? Ah, good question. Postfix is cool and it actually sends the email depending on your configuration. But it’s not probably a good option for debugging purposes. Do you want your mailbox filled up with test emails? 😉 Also AFAIK, it has no way to run on Windows. And I admit, sometimes emails are delivered quite late while using postfix. On the other hand, smtp4dev is a nice tool for similar purposes but it’s not cross OS either. It’s Windows only. Besides, it crashes if you try to send emails in French (probably an issue with Unicode). My python script solves this issue. It doesn’t fill up your mailbox, it handles French (and other languages with special chars) and most importantly runs on all the major OS.

Enough talks! So where’s the script? It’s right here:

How do I run it? First create a new file named: capture_email.py and copy-paste the codes into that file. If you’re on Linux or Mac, you already have Python 😀 Just type this command and hit enter:

If you’re on Windows, download a version of Python from http://python.org and install it. I recommend using Python version 2.5+ but less than 3. Python 3 is not supported. Double click on the file to run it.

Now that the script is running, try sending an email with mail() in PHP. Keep any eye on the Terminal/Command prompt for the output.

If something goes wrong, please let me know. Hope this script will be useful for the PHP devs out there. 🙂

Categories
Personal

āĻ‰āĻ‡āĻ¨ā§āĻĄā§‹āĻœ, āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸ āĻ“ āĻ†āĻŽāĻžāĻ° āĻĒā§‹āĻ¸ā§āĻŸ

āĻ†āĻœāĻ•ā§‡ āĻ¯āĻžāĻ°āĻž āĻ†āĻŽāĻžāĻ° āĻāĻ‡ āĻĒā§‹āĻ¸ā§āĻŸāĻŸāĻŋ āĻĒā§œāĻ›ā§‡āĻ¨ āĻ¤āĻžāĻ°āĻž āĻ…āĻ¨ā§‡āĻ•ā§‡āĻ‡ āĻšā§ŸāĻ¤ āĻ†āĻŽāĻžāĻ° āĻ‰āĻ‡āĻ¨ā§āĻĄā§‹āĻœ āĻ“ āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸ āĻŦāĻŋāĻˇā§ŸāĻ• āĻĒā§‹āĻ¸ā§āĻŸāĻŸāĻŋ āĻĒā§œā§‡āĻ›ā§‡āĻ¨ āĨ¤ āĻŦāĻ˛ā§‡ āĻ°āĻžāĻ–āĻž āĻ­āĻžāĻ˛ āĻ†āĻŽāĻŋ āĻĻā§€āĻ°ā§āĻ˜āĻĻāĻŋāĻ¨ āĻ¯āĻžāĻŦā§Ž āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°ā§‡ āĻ†āĻ¸āĻ›āĻŋ āĨ¤ āĻ…āĻ¨ā§‡āĻ•ā§‡āĻ‡ āĻ†āĻŽāĻžāĻ° āĻĒā§‹āĻ¸ā§āĻŸ āĻĻā§‡āĻ–ā§‡ āĻ…āĻŦāĻžāĻ• āĻšā§Ÿā§‡āĻ›ā§‡āĻ¨ āĨ¤ āĻ•ā§‡āĻ¨ āĻ†āĻŽāĻŋ āĻāĻ­āĻžāĻŦā§‡ āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸āĻ•ā§‡ āĻĒāĻšāĻžāĻāĻ˛āĻžāĻŽ āĻāĻ¤ āĻĒā§āĻ°āĻžāĻŖ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ°āĻ•āĻžāĻ°ā§€ āĻšā§Ÿā§‡ āĨ¤ āĻļā§āĻ§ā§ āĻāĻ‡ āĻĒā§‹āĻ¸ā§āĻŸā§‡āĻ‡ āĻ¨āĻž, āĻŸā§āĻ‡āĻŸāĻžāĻ° āĻāĻŦāĻ‚ āĻĒā§āĻ°āĻœāĻ¨ā§āĻŽ āĻĢā§‹āĻ°āĻžāĻŽā§‡āĻ“ āĻ†āĻŽāĻŋ āĻāĻ•āĻ‡ āĻ•āĻžāĻœ āĻ•â€āĻ°ā§‡āĻ›āĻŋ, āĻ•āĻŋāĻ¨ā§āĻ¤ā§ āĻ•ā§‡āĻ¨ ?

āĻ†āĻŽāĻŋ āĻŦāĻšā§āĻĻāĻŋāĻ¨ āĻ¯āĻžāĻŦā§Ž āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸ āĻ•āĻŽāĻŋāĻ‰āĻ¨āĻŋāĻŸāĻŋāĻ¤ā§‡ āĻāĻ•āĻŸāĻŋ āĻœāĻŋāĻ¨āĻŋāĻ¸ āĻĻā§‡āĻ–ā§‡ āĻ†āĻ¸āĻ›āĻŋ, āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸ā§‡āĻ° āĻ­āĻžāĻ˛ āĻ—ā§āĻ¨ āĻŦā§‹āĻāĻžāĻ¤ā§‡ āĻ‰āĻ‡āĻ¨ā§āĻĄā§‹āĻœāĻ•ā§‡ āĻĒāĻšāĻžāĻ¤ā§‡ āĻšāĻŦā§‡ āĨ¤ āĻ…āĻ¨ā§āĻ¯ āĻ•ā§‹āĻ¨ āĻ“āĻāĻ¸ āĻ¨āĻž, āĻļā§āĻ§ā§āĻ‡ āĻ‰āĻ‡āĻ¨ā§āĻĄā§‹āĻœā§‡āĻ° āĻĻā§‹āĻˇ āĨ¤ āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸āĻ•ā§‡ āĻ­āĻžāĻ˛ āĻŦāĻ˛āĻ¤ā§‡ āĻšāĻžāĻ¨ āĻŦāĻ˛ā§āĻ¨, āĻ•āĻŋāĻ¨ā§āĻ¤ā§ āĻ¸āĻžāĻĨā§‡ āĻ‰āĻ‡āĻ¨ā§āĻĄā§‹āĻœāĻ•ā§‡ āĻŸā§‡āĻ¨ā§‡ āĻ•āĻŋ āĻ˛āĻžāĻ­ ? āĻ—āĻžā§Ÿā§‡ āĻŸā§‡āĻ¨ā§‡ āĻ§āĻ°ā§‡ āĻ•ā§‡āĻ¨ āĻ‰āĻ‡āĻ¨ā§āĻĄā§‹āĻœ āĻĢā§āĻ¯āĻžāĻ¨āĻĻā§‡āĻ° āĻĒāĻšāĻžāĻ¤ā§‡ āĻšāĻŦā§‡? āĻ†āĻœāĻ•ā§‡ āĻ†āĻĒāĻ¨āĻŋ āĻ¤āĻžāĻĻā§‡āĻ° āĻŦāĻŋāĻĻā§āĻ°ā§āĻĒ āĻ•āĻ°āĻŦā§‡āĻ¨ āĻ•āĻžāĻ˛ āĻĒāĻžāĻ˛ā§āĻŸāĻž āĻ¤āĻžāĻ°āĻž āĻ•āĻ°āĻŦā§‡ āĨ¤ āĻāĻ°āĻĒāĻ° āĻ¨āĻžāĻ•āĻŋ āĻ•āĻžāĻ¨ā§āĻ¨āĻž āĻ•ā§‡āĻĻā§‡ āĻŦāĻ˛āĻŦā§‡āĻ¨ āĻ˛āĻŋāĻ¨āĻžāĻ•ā§āĻ¸ āĻĢā§āĻ°ā§€, āĻ“āĻĒā§‡āĻ¨-āĻ¸ā§‹āĻ°ā§āĻ¸, āĻāĻŸāĻž āĻ¨āĻŋā§Ÿā§‡ āĻŦāĻŋāĻĻā§āĻ°ā§āĻĒ āĻ•āĻ°āĻž āĻ…āĻŽāĻžāĻ¨āĻŦāĻŋāĻ• āĨ¤

āĻ¯ā§‡ āĻ•ā§‹āĻ¨ āĻ…āĻĒāĻžāĻ°ā§‡āĻŸāĻŋāĻ‚ āĻ¸āĻŋāĻ¸ā§āĻŸā§‡āĻŽ āĻ¨āĻŋā§Ÿā§‡āĻ‡ āĻŦāĻŋāĻĻā§āĻ°ā§āĻĒ āĻ•â€āĻ°āĻž āĻ¯āĻžā§Ÿ āĨ¤ āĻļāĻžāĻŽā§€āĻŽ āĻ­āĻžāĻ‡ āĻ¯ā§‡āĻŽāĻ¨ āĻ˛āĻŋāĻ–ā§‡āĻ›ā§‡āĻ¨ āĻ¤ā§‡āĻŽāĻ¨ āĻ…āĻ¨ā§āĻ¯āĻ°āĻžāĻ“ āĻ˛āĻŋāĻ–āĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡ āĨ¤ āĻ†āĻĒāĻ¨āĻžāĻ° āĻĒā§āĻ°āĻŋā§Ÿ āĻœāĻŋāĻ¨āĻŋāĻ¸ āĻ¨āĻŋā§Ÿā§‡ āĻŦā§āĻ¯āĻ™ā§āĻ— āĻ•â€āĻ°āĻ˛ā§‡ āĻ†āĻĒāĻ¨āĻžāĻ° āĻ¯ā§‡āĻŽāĻ¨ āĻ˛āĻžāĻ—ā§‡ āĻ…āĻ¨ā§āĻ¯āĻĻā§‡āĻ° āĻ¸ā§‡āĻ­āĻžāĻŦā§‡ āĻ˛āĻžāĻ—ā§‡āĨ¤ āĻāĻ‡ āĻœāĻŋāĻ¨āĻŋāĻ¸āĻŸāĻŋāĻ° āĻĒā§āĻ°āĻ¤āĻŋ āĻ†āĻ˛ā§‹āĻ•āĻĒāĻžāĻ¤ āĻ•â€āĻ°āĻžāĻ‡ āĻ›āĻŋāĻ˛ āĻ†āĻŽāĻžāĻ° āĻ˛ā§‡āĻ–āĻžāĻ° āĻ‰āĻĻā§āĻĻā§‡āĻļā§āĻ¯ āĨ¤ āĻ†āĻ¸ā§āĻ¨ āĻ†āĻŽāĻžāĻĻā§‡āĻ° āĻ¯āĻžāĻ° āĻ¯ā§‡āĻŸāĻž āĻ­āĻžāĻ˛ āĻ˛āĻžāĻ—ā§‡ āĻ¸ā§‡ āĻ¸ā§‡āĻŸāĻž āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°āĻŋ, āĻ¸ā§‡āĻŸāĻžāĻ° āĻ­āĻžāĻ˛ āĻĻāĻŋāĻ• āĻ¤ā§āĻ˛ā§‡ āĻ§āĻ°ā§‡ āĻ…āĻ¨ā§āĻ¯āĻ•ā§‡ āĻ‰ā§ŽāĻ¸āĻžāĻšāĻŋāĻ¤ āĻ•āĻ°āĻŋ, āĻāĻ° āĻœāĻ¨ā§āĻ¯ā§‡ āĻ…āĻ¨ā§āĻ¯āĻ•ā§‡ āĻ–āĻžāĻ°āĻžāĻĒ āĻĒā§āĻ°āĻŽāĻžāĻŖ āĻ•â€āĻ°āĻžāĻ° āĻĻāĻ°āĻ•āĻžāĻ° āĻ¨ā§‡āĻ‡ āĻŦ‍āĻ˛ā§‡āĻ‡ āĻ†āĻŽāĻŋ āĻŽâ€āĻ¨ā§‡ āĻ•āĻ°āĻŋ āĨ¤

āĻ†āĻŽāĻžāĻ° āĻ˛ā§‡āĻ–āĻžā§Ÿ āĻ¯āĻĻāĻŋ āĻ•ā§‡āĻ‰ āĻ†āĻ˜āĻžāĻ¤ āĻĒā§‡ā§Ÿā§‡ āĻĨāĻžāĻ•ā§‡āĻ¨ āĻ¤āĻŦā§‡ āĻ¤āĻžāĻ° āĻœāĻ¨ā§āĻ¯ā§‡ āĻ†āĻ¨ā§āĻ¤āĻ°āĻŋāĻ•āĻ­āĻžāĻŦā§‡ āĻ•ā§āĻˇāĻŽāĻž āĻšāĻžāĻ‡āĻ›āĻŋ āĨ¤