Category: Code


PHP: Print amount or number in words

Its been real long since I updated this space. And instead of adding something for the heck of it, I thought of posting something really useful. This is a piece of PHP code that returns an amount/number in words. This is in English, but you can easily translate it to your own. Hope this helps!

This reminds me of Semester 1 assignment given by Shalini Puri ma’am to determine the optimal number of currency coins & notes required to put together a specified amount. Good old days!

Something for your empty home

Here are few lines of code that I have repeatedly found useful, especially when moving home between different web hosts.

Print the complete address of the page from where it is hosted:

<?php
$pageURL = $_SERVER['HTTPS'] == ‘on’ ? ‘https://’ : ‘http://’;
$pageURL .= $_SERVER['SERVER_PORT'] != ’80′ ? $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo $pageURL;
?>

Everyone knows about phpInfo – a dump of all the PHP settings:

<?php phpinfo(); ?>

When using a shared host that allows overriding your PHP ini file, it is worth while knowing the path from where the file is loaded:

<?php var_dump( get_cfg_var(‘cfg_file_path’) ); ?>

Jargon: Code Profiling

Code profiling is a form of dynamic program (code) analysis to investigate the program’s behavior during execution. It is usually done to determine sections of code that can be optimized – to increase overall speed & reduce resource requirements. Code profiler can come in several varieties – from those that measure the frequency & duration of function calls to others that track memory usage. An emulator for micro-processor code (that simulates the processor’s instruction set) is also a type of profiler that measures behavior for the entire execution cycle – invocation to termination.

I first heard of code profiling in the context of reverse engineering software architectures. Often it may so happen that applications with very little documentation are to be enhanced or re-engineered. One way to understand is by analyzing code, which can be a tedious process. Such static program analysis may yield incomplete understanding as the polymorphic calls can’t be determined until run-time. A code profiler determines polymorphic function calls and identifies overloads used during execution which helps establish relationships between classes & components that can be used to reveal the underlying software architecture, if not for a specific pattern.

Amazing Comments In Source Code by Developers

As I was getting over Monday blues, Aditya Tripathi sent this funny-yet-realistic! I’m sure this will get every dev-devil laughing with delight; reminiscing the KLOC written with cryptic comments or nothing at all. Here you go, the best code comments seen in source code…!

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

/*
* You may think you know what the following code does.
* But you dont. Trust me.
* Fiddle with it, and youll spend many a sleepless
* night cursing the moment you thought youd be clever
* enough to “optimize” the code below.
* Now close this file and go play with something else.
*/ View full article »

Jargon: Code Obfuscation

Code obfuscation is the technique used to make source code elusive. Advantages of doing this are protecting intellectual property, reducing security exposure, size reduction or minification and library linking (to avoid DLL Hell). It is also considered a form of security. Types of obfuscations include simple keyword substitution, use or non-use of whitespace to create artistic effects, clever self-generating or heavily compressed programs, and programs that are valid and operate similarly in multiple programming languages. View full article »

prasadgupte | 1999-2014