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

āωāχāĻ¨ā§āĻĄā§‹āϜ, āϞāĻŋāύāĻžāĻ•ā§āϏ āĻ“ āφāĻŽāĻžāϰ āĻĒā§‹āĻ¸ā§āϟ

āφāϜāϕ⧇ āϝāĻžāϰāĻž āφāĻŽāĻžāϰ āĻāχ āĻĒā§‹āĻ¸ā§āϟāϟāĻŋ āĻĒ⧜āϛ⧇āύ āϤāĻžāϰāĻž āĻ…āύ⧇āϕ⧇āχ āĻšā§ŸāϤ āφāĻŽāĻžāϰ āωāχāĻ¨ā§āĻĄā§‹āϜ āĻ“ āϞāĻŋāύāĻžāĻ•ā§āϏ āĻŦāĻŋāώ⧟āĻ• āĻĒā§‹āĻ¸ā§āϟāϟāĻŋ āĻĒā§œā§‡āϛ⧇āύ āĨ¤ āĻŦāϞ⧇ āϰāĻžāĻ–āĻž āĻ­āĻžāϞ āφāĻŽāĻŋ āĻĻā§€āĻ°ā§āϘāĻĻāĻŋāύ āϝāĻžāĻŦā§Ž āϞāĻŋāύāĻžāĻ•ā§āϏ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇ āφāϏāĻ›āĻŋ āĨ¤ āĻ…āύ⧇āϕ⧇āχ āφāĻŽāĻžāϰ āĻĒā§‹āĻ¸ā§āϟ āĻĻ⧇āϖ⧇ āĻ…āĻŦāĻžāĻ• āĻšā§Ÿā§‡āϛ⧇āύ āĨ¤ āϕ⧇āύ āφāĻŽāĻŋ āĻāĻ­āĻžāĻŦ⧇ āϞāĻŋāύāĻžāĻ•ā§āϏāϕ⧇ āĻĒāϚāĻžāρāϞāĻžāĻŽ āĻāϤ āĻĒ⧁āϰāĻžāĻŖ āĻŦā§āϝāĻŦāĻšāĻžāϰāĻ•āĻžāϰ⧀ āĻšā§Ÿā§‡ āĨ¤ āĻļ⧁āϧ⧁ āĻāχ āĻĒā§‹āĻ¸ā§āĻŸā§‡āχ āύāĻž, āϟ⧁āχāϟāĻžāϰ āĻāĻŦāĻ‚ āĻĒā§āϰāϜāĻ¨ā§āĻŽ āĻĢā§‹āϰāĻžāĻŽā§‡āĻ“ āφāĻŽāĻŋ āĻāĻ•āχ āĻ•āĻžāϜ āĻ•â€āϰ⧇āĻ›āĻŋ, āĻ•āĻŋāĻ¨ā§āϤ⧁ āϕ⧇āύ ?

āφāĻŽāĻŋ āĻŦāĻšā§āĻĻāĻŋāύ āϝāĻžāĻŦā§Ž āϞāĻŋāύāĻžāĻ•ā§āϏ āĻ•āĻŽāĻŋāωāύāĻŋāϟāĻŋāϤ⧇ āĻāĻ•āϟāĻŋ āϜāĻŋāύāĻŋāϏ āĻĻ⧇āϖ⧇ āφāϏāĻ›āĻŋ, āϞāĻŋāύāĻžāĻ•ā§āϏ⧇āϰ āĻ­āĻžāϞ āϗ⧁āύ āĻŦā§‹āĻāĻžāϤ⧇ āωāχāĻ¨ā§āĻĄā§‹āϜāϕ⧇ āĻĒāϚāĻžāϤ⧇ āĻšāĻŦ⧇ āĨ¤ āĻ…āĻ¨ā§āϝ āϕ⧋āύ āĻ“āĻāϏ āύāĻž, āĻļ⧁āϧ⧁āχ āωāχāĻ¨ā§āĻĄā§‹āĻœā§‡āϰ āĻĻā§‹āώ āĨ¤ āϞāĻŋāύāĻžāĻ•ā§āϏāϕ⧇ āĻ­āĻžāϞ āĻŦāϞāϤ⧇ āϚāĻžāύ āĻŦāϞ⧁āύ, āĻ•āĻŋāĻ¨ā§āϤ⧁ āϏāĻžāĻĨ⧇ āωāχāĻ¨ā§āĻĄā§‹āϜāϕ⧇ āĻŸā§‡āύ⧇ āĻ•āĻŋ āϞāĻžāĻ­ ? āĻ—āĻžā§Ÿā§‡ āĻŸā§‡āύ⧇ āϧāϰ⧇ āϕ⧇āύ āωāχāĻ¨ā§āĻĄā§‹āϜ āĻĢā§āϝāĻžāύāĻĻ⧇āϰ āĻĒāϚāĻžāϤ⧇ āĻšāĻŦ⧇? āφāϜāϕ⧇ āφāĻĒāύāĻŋ āϤāĻžāĻĻ⧇āϰ āĻŦāĻŋāĻĻā§āϰ⧁āĻĒ āĻ•āϰāĻŦ⧇āύ āĻ•āĻžāϞ āĻĒāĻžāĻ˛ā§āϟāĻž āϤāĻžāϰāĻž āĻ•āϰāĻŦ⧇ āĨ¤ āĻāϰāĻĒāϰ āύāĻžāĻ•āĻŋ āĻ•āĻžāĻ¨ā§āύāĻž āϕ⧇āĻĻ⧇ āĻŦāϞāĻŦ⧇āύ āϞāĻŋāύāĻžāĻ•ā§āϏ āĻĢā§āϰ⧀, āĻ“āĻĒ⧇āύ-āϏ⧋āĻ°ā§āϏ, āĻāϟāĻž āύāĻŋā§Ÿā§‡ āĻŦāĻŋāĻĻā§āϰ⧁āĻĒ āĻ•āϰāĻž āĻ…āĻŽāĻžāύāĻŦāĻŋāĻ• āĨ¤

āϝ⧇ āϕ⧋āύ āĻ…āĻĒāĻžāϰ⧇āϟāĻŋāĻ‚ āϏāĻŋāĻ¸ā§āĻŸā§‡āĻŽ āύāĻŋā§Ÿā§‡āχ āĻŦāĻŋāĻĻā§āϰ⧁āĻĒ āĻ•â€āϰāĻž āϝāĻžā§Ÿ āĨ¤ āĻļāĻžāĻŽā§€āĻŽ āĻ­āĻžāχ āϝ⧇āĻŽāύ āϞāĻŋāϖ⧇āϛ⧇āύ āϤ⧇āĻŽāύ āĻ…āĻ¨ā§āϝāϰāĻžāĻ“ āϞāĻŋāĻ–āϤ⧇ āĻĒāĻžāϰ⧇ āĨ¤ āφāĻĒāύāĻžāϰ āĻĒā§āϰāĻŋ⧟ āϜāĻŋāύāĻŋāϏ āύāĻŋā§Ÿā§‡ āĻŦā§āϝāĻ™ā§āĻ— āĻ•â€āϰāϞ⧇ āφāĻĒāύāĻžāϰ āϝ⧇āĻŽāύ āϞāĻžāϗ⧇ āĻ…āĻ¨ā§āϝāĻĻ⧇āϰ āϏ⧇āĻ­āĻžāĻŦ⧇ āϞāĻžāϗ⧇āĨ¤ āĻāχ āϜāĻŋāύāĻŋāϏāϟāĻŋāϰ āĻĒā§āϰāϤāĻŋ āφāϞ⧋āĻ•āĻĒāĻžāϤ āĻ•â€āϰāĻžāχ āĻ›āĻŋāϞ āφāĻŽāĻžāϰ āϞ⧇āĻ–āĻžāϰ āωāĻĻā§āĻĻ⧇āĻļā§āϝ āĨ¤ āφāϏ⧁āύ āφāĻŽāĻžāĻĻ⧇āϰ āϝāĻžāϰ āϝ⧇āϟāĻž āĻ­āĻžāϞ āϞāĻžāϗ⧇ āϏ⧇ āϏ⧇āϟāĻž āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻŋ, āϏ⧇āϟāĻžāϰ āĻ­āĻžāϞ āĻĻāĻŋāĻ• āϤ⧁āϞ⧇ āϧāϰ⧇ āĻ…āĻ¨ā§āϝāϕ⧇ āĻ‰ā§ŽāϏāĻžāĻšāĻŋāϤ āĻ•āϰāĻŋ, āĻāϰ āϜāĻ¨ā§āϝ⧇ āĻ…āĻ¨ā§āϝāϕ⧇ āĻ–āĻžāϰāĻžāĻĒ āĻĒā§āϰāĻŽāĻžāĻŖ āĻ•â€āϰāĻžāϰ āĻĻāϰāĻ•āĻžāϰ āύ⧇āχ āĻŦ‍āϞ⧇āχ āφāĻŽāĻŋ āĻŽâ€āύ⧇ āĻ•āϰāĻŋ āĨ¤

āφāĻŽāĻžāϰ āϞ⧇āĻ–āĻžā§Ÿ āϝāĻĻāĻŋ āϕ⧇āω āφāϘāĻžāϤ āĻĒā§‡ā§Ÿā§‡ āĻĨāĻžāϕ⧇āύ āϤāĻŦ⧇ āϤāĻžāϰ āϜāĻ¨ā§āϝ⧇ āφāĻ¨ā§āϤāϰāĻŋāĻ•āĻ­āĻžāĻŦ⧇ āĻ•ā§āώāĻŽāĻž āϚāĻžāχāĻ›āĻŋ āĨ¤