Skip to content

Instantly share code, notes, and snippets.

@pchatterjee
pchatterjee / gist_test.txt
Created April 21, 2012 01:54
A test gist
A test of a gist
@pchatterjee
pchatterjee / php_example_1.php
Created April 21, 2012 02:12
php example 1
<?php
echo "Hello World\n";
# author : me
# purpose : a test gist
?>
<?php
# Shows all information, defaults to INFO_ALL
phpinfo();
?>
@pchatterjee
pchatterjee / SingletonPattern_example.php
Created August 2, 2012 03:13
PHP Singleton Pattern Example
<?php
class Singleton
{
protected static $instance = null;
protected function __construct()
{
# Thou shalt not construct that which is unconstructable!
}
protected function __clone()
{
@pchatterjee
pchatterjee / calculator_v2.php
Created September 20, 2012 14:47
Calculator Example (v2)
<?php
/* ======================================================
PHP Calculator example using "sticky" form (Version 2)
======================================================
- uses a dropdown select box to select operation
- does very basic validation
- uses a function to calculate result
- traps a devide by zero error
<?xml version="1.0" encoding="UTF-8"?>
<quotes>
<quote><text category="romantic">There is no remedy but to love more.</text>
<source>Henry David Thoreau</source>
<dob-dod>1817-1862</dob-dod>
<wplink>http://en.wikipedia.org/wiki/Henry_David_Thoreau</wplink>
<wpimage>http://upload.wikimedia.org/wikipedia/commons/f/f0/Benjamin_D._Maxham_-_Henry_David_Thoreau_-_Restored.jpg</wpimage>
</quote><quote><text category="romantic">There is always some madness in love. But there is also always some reason in madness.</text>
<source>Friedrich Nietzsche</source>
<dob-dod>1844-1900</dob-dod>
<?php
# always include this line
@date_default_timezone_set("GMT");
#declare the currency array
$ccodes = array(
'AUD','BRL','CAD','CHF',
'CNY','DKK','EUR','GBP',
'HKD','HUF','INR','JPY',
'MXN','MYR','NOK','NZD',
<?php
# always include this line
@date_default_timezone_set("GMT");
#declare the currency array
$ccodes = array(
'AUD','BRL','CAD','CHF',
'CNY','DKK','EUR','GBP',
'HKD','HUF','INR','JPY',
'MXN','MYR','NOK','NZD',
<?php
# always include this line
@date_default_timezone_set("GMT");
#declare the currency array
$ccodes = array(
'AUD','BRL','CAD','CHF',
'CNY','DKK','EUR','GBP',
'HKD','HUF','INR','JPY',
'MXN','MYR','NOK','NZD',
<?php
# error_hash to hold error numbers and messages
# must be kept in the config file
$error_hash = array(
1000 => 'Currency type not recognized',
1100 => 'Required parameter is missing',
1200 => 'Parameter not recognized',
1300 => 'Currency amount must be a decimal number',
1400 => 'Error in service',