<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Rizal Almashoor's Blog</title>
	<link>http://www.rizalalmashoor.com/blog</link>
	<description>Valid use of Null</description>
	<pubDate>Mon, 23 Aug 2010 21:25:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>
	<language>en</language>
			<item>
		<title>Tolstoy for bedtime</title>
		<link>http://www.rizalalmashoor.com/blog/tolstoy-for-bedtime/</link>
		<comments>http://www.rizalalmashoor.com/blog/tolstoy-for-bedtime/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:25:21 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/tolstoy-for-bedtime/</guid>
		<description><![CDATA[Last night I read Tolstoy to my four-year-old.
No, it wasn&#8217;t Leo Tolstoy&#8217;s War and Peace; it was Alexei Tolstoy&#8217;s The Enormous Turnip.
]]></description>
			<content:encoded><![CDATA[<p>Last night I read Tolstoy to my four-year-old.</p>
<p>No, it wasn&#8217;t Leo Tolstoy&#8217;s War and Peace; it was Alexei Tolstoy&#8217;s <a href="http://www.usborne.com/catalogue/catalogue.aspx?area=yr&#038;subcat=frlt&#038;id=2113">The Enormous Turnip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/tolstoy-for-bedtime/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Worthy of a Moleskine</title>
		<link>http://www.rizalalmashoor.com/blog/worthy-of-a-moleskine/</link>
		<comments>http://www.rizalalmashoor.com/blog/worthy-of-a-moleskine/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 05:31:36 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/worthy-of-a-moleskine/</guid>
		<description><![CDATA[When I first heard about Moleskines I immediately fell in love with them. Just the idea of carrying around these notebooks &#8211; the type used by van Gogh, Picasso and Hemingway, no less! &#8211; felt awe-inspiring.
They are available in Kuala Lumpur, and the prices are perhaps more awe-inspiring than the notebooks themselves. The smallest and [...]]]></description>
			<content:encoded><![CDATA[<p>When I first heard about <a href="http://www.moleskine.com/moleskine_world">Moleskines</a> I immediately fell in love with them. Just the idea of carrying around these notebooks &ndash; the type used by van Gogh, Picasso and Hemingway, no less! &ndash; felt awe-inspiring.</p>
<p>They are available in Kuala Lumpur, and the prices are perhaps more awe-inspiring than the notebooks themselves. The <a href="http://www.moleskine.com/catalogue/classic/volant/flexible_black_cover/set_of_2_volant_notebooks_plain__black__extra_small.php">smallest and thinnest</a> costs RM25 for two (promotion price). Looking at what I scribble in my throwaway, sub-ringgit notebooks &ndash; random to-do items, shopping lists, phone numbers &ndash; it&#8217;s very obvious that Moleskines are not for me. They&#8217;re for poets, writers, and painters, not for ordinary people with everyday lives.</p>
<p>My wife, however, can paint. So yesterday we drove down to <a href="http://www.cziplee.com">Czip Lee</a> Bangsar and she got herself some art supplies plus a <a href="http://www.moleskine.com/catalogue/folio/folio_art/folio_watercolour_album__a4.php">Moleskine Folio Watercolour Album A4</a>. She has already filled two pages with her watercolours. Let me say this: she is worthy of a Moleskine.</p>
<p>I <em>almost</em> bought the RM25 set-of-two but put it back at the last minute. But I did get myself an RM9 <a href="http://www.cultpens.com/acatalog/Faber-Castell-Pitt-Artists-Drawing-Pen.html">Faber-Castell PITT artist pen</a>. I&#8217;m using it to scribble random to-do items, shopping lists, phone numbers, etc. It&#8217;s so nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/worthy-of-a-moleskine/feed/</wfw:commentRss>
		</item>
		<item>
		<title>By value, by reference: by analogy</title>
		<link>http://www.rizalalmashoor.com/blog/by-value-by-reference-by-analogy/</link>
		<comments>http://www.rizalalmashoor.com/blog/by-value-by-reference-by-analogy/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 17:59:55 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/by-value-by-reference-by-analogy/</guid>
		<description><![CDATA[Here&#8217;s my best attempt to explain C# value types and reference types, and &#8220;pass by value&#8221; and &#8220;pass by reference&#8221; to a newbie. (Not you, of course.)
Value types
A piece of paper, on which is written the number 5. You use this number to calculate something.
Reference types
A piece of paper, on which is written a memory [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s my best attempt to explain C# value types and reference types, and &#8220;pass by value&#8221; and &#8220;pass by reference&#8221; to a newbie. (Not you, of course.)</p>
<h3>Value types</h3>
<p>A piece of paper, on which is written the number 5. You use this number to calculate something.</p>
<h3>Reference types</h3>
<p>A piece of paper, on which is written a memory location. You then go to the memory location in order to access an object.</p>
<p>(Aside: the &#8220;object reference not set to an instance of an object&#8221; exception means that the piece of paper has the special value of &#8220;unspecified&#8221;, and when you try to use this piece of paper to access an object, you aren&#8217;t able to.)</p>
<p>(Another aside: in C#, by default, you aren&#8217;t able to do anything with references except to use it to access an object. In C and C++, however, you could perform arithmetic on references &ndash; powerful and dangerous.)</p>
<h3>Pass by value</h3>
<p>I&#8217;m a function. You hand me a piece of paper. I take out my own piece of paper, copy down what&#8217;s written on your piece of paper, and give your piece of paper back to you. Whatever I scribble on my piece of paper doesn&#8217;t affect your piece of paper.</p>
<h3>Pass by reference</h3>
<p>I&#8217;m a function. You hand me a piece of paper. I write on your piece of paper and give it back to you. Your piece of paper is definitely affected.</p>
<h3>Passing reference types by value</h3>
<p>I&#8217;m a function. You hand me a piece of paper with a memory location written on it. I take out my own piece of paper, copy down the memory location, and give your piece of paper back to you. I can&#8217;t change what&#8217;s on your piece of paper, but I can affect your object.</p>
<h3>Passing reference types by reference</h3>
<p>I&#8217;m a function. You hand me a piece of paper with a memory location written on it. I rub out the memory location, write a new memory location, and give back the piece of paper to you. You are now referencing another object in the new memory location.</p>
<h3>Strings</h3>
<p>Strings are a special case. Technically they&#8217;re reference types, but for the sake of convenience, we&#8217;re able to treat strings as value types. Although we&#8217;re passing the memory locations of our strings to functions, we don&#8217;t have to worry about these functions modifying our strings. This is because strings are immutable, like so:</p>
<pre class="brush: csharp">
class ImmutableType
{
    private int _value;

    public ImmutableType(int value)
    {
        _value = value;
    }

    public int Value
    {
        get
        {
            return _value;
        }
    }
}

class Program
{
    public static void Main()
    {
        ImmutableType x = new ImmutableType(5);
        // will output 5
        Console.WriteLine(x.Value);
        // set y to refer to the same object as x
        ImmutableType y = x;
        // will output 5
        Console.WriteLine(y.Value);
        // illegal, no set accessor, so our object is safe
        //y.Value = 6;
        // no choice but to create a new object
        y = new ImmutableType(6);
    }
}
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/by-value-by-reference-by-analogy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>When all you have is a hammer</title>
		<link>http://www.rizalalmashoor.com/blog/when-all-you-have-is-a-hammer/</link>
		<comments>http://www.rizalalmashoor.com/blog/when-all-you-have-is-a-hammer/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 19:08:04 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/when-all-you-have-is-a-hammer/</guid>
		<description><![CDATA[&#8230; everything looks like a nail. The point I would like to make here is this: when all you know is C#, everything looks like a class.
(Note: When I say C#, I mean Java or C#. At the core both are the same. I only mean to avoid from having to repeatedly say &#8220;Java/C#&#8221; which [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; everything looks like a nail. The point I would like to make here is this: when all you know is C#, everything looks like a class.</p>
<p>(Note: When I say C#, I mean Java or C#. At the core both are the same. I only mean to avoid from having to repeatedly say &#8220;Java/C#&#8221; which is distracting.)</p>
<p>After having had to continually switch between PHP and C# over the course of a year, I&#8217;ve come to realize that different languages are better at solving different types of problems. Actually it&#8217;s not really about the language per se (which is just syntax), but the paradigm. PHP is excellent for UI-driven websites with fluid requirements and short release cycles. C# is excellent for Windows apps and web services. Java is excellent for mid-tier components that can run on Unix. C++ is excellent for writing device APIs. VBA on MS Access is excellent for form-driven apps that come with their own database on file. Perl is excellent for text processing.</p>
<p>Thus, the more languages you know, the higher the likelihood of your being able to use the best tool for the job. Ultimately, that&#8217;s all a programming language is: a tool, suited for a particular purpose. </p>
<p>For some reason there are people who identify themselves with a particular language. They have a mental block when it comes to learning new programming languages. I think that&#8217;s a mistake. Wouldn&#8217;t it be better to be able to use the best programming language for the job at hand, and to identify oneself with this ability?</p>
<p>Having said that, it isn&#8217;t easy to get the chance to practise a new language for a real project. But at the very least one should keep an open mind, and to jump in without hesitation when the opportunity arises.</p>
<p>P.S. There are also other variations to the first paragraph: when all you know is PHP, everything looks like an ordered map; when all you know is Lisp, everything looks like a linked list; when all you know is JavaScript, everything looks like a collection of named values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/when-all-you-have-is-a-hammer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling a SOAP web service from PHP</title>
		<link>http://www.rizalalmashoor.com/blog/calling-a-soap-web-service-from-php/</link>
		<comments>http://www.rizalalmashoor.com/blog/calling-a-soap-web-service-from-php/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 07:05:25 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/calling-a-soap-web-service-from-php/</guid>
		<description><![CDATA[The SOAP binding is RPC/encoded, and the WSDL is not published.
Using the PHP SoapClient:

define('NEWLINE', "&#60;br /&#62;\n");

// SOAP client

$options = array
(
	'location' =&#62; 'https://example.com:1234/sample/service',
	'uri' =&#62; 'http://example.com/sample/namespace/data',
	'style' =&#62; SOAP_RPC,
	'use' =&#62; SOAP_ENCODED,
	'trace' =&#62; true // in conjunction with $soapClient-&#62;__getLastRequest() below
);
$soapClient = new SoapClient(null, $options);

// SOAP header

$nsHeader = 'http://example.com/sample/namespace/security';
$elementName = 'Security';

$usernameToken-&#62;Username = new SoapVar('user9', XSD_STRING, null, null, null, $nsHeader);
$usernameToken-&#62;Password = [...]]]></description>
			<content:encoded><![CDATA[<p>The SOAP binding is RPC/encoded, and the WSDL is not published.</p>
<p>Using the PHP SoapClient:</p>
<pre class="brush: php">
define('NEWLINE', "&lt;br /&gt;\n");

// SOAP client

$options = array
(
	'location' =&gt; 'https://example.com:1234/sample/service',
	'uri' =&gt; 'http://example.com/sample/namespace/data',
	'style' =&gt; SOAP_RPC,
	'use' =&gt; SOAP_ENCODED,
	'trace' =&gt; true // in conjunction with $soapClient-&gt;__getLastRequest() below
);
$soapClient = new SoapClient(null, $options);

// SOAP header

$nsHeader = 'http://example.com/sample/namespace/security';
$elementName = 'Security';

$usernameToken-&gt;Username = new SoapVar('user9', XSD_STRING, null, null, null, $nsHeader);
$usernameToken-&gt;Password = new SoapVar('pass1234', XSD_STRING, null, null, null, $nsHeader);

$content-&gt;UsernameToken = new SoapVar($usernameToken, SOAP_ENC_OBJECT, null, null, null, $nsHeader);

$soapHeader = new SoapHeader($nsHeader, $elementName, $content);
$soapHeaders[] = $soapHeader;
$soapClient-&gt;__setSoapHeaders($soapHeaders);

// SOAP call

$method = 'getData';
$parameters = array
(
	new SoapParam('abcdef', 'param1'),
	new SoapParam(12345, 'param2')
);

$success = true;
try
{
	$result = $soapClient-&gt;__soapCall($method, $parameters);
}
catch (SoapFault $fault)
{
	echo "Fault code: {$fault-&gt;faultcode}" . NEWLINE;
	echo "Fault string: {$fault-&gt;faultstring}" . NEWLINE;
	$success = false;
}

echo $soapClient-&gt;__getLastRequest(); // output the request XML

if ($success)
{
	echo "&lt;pre&gt;\n";
	print_r($result);
	echo "&lt;/pre&gt;\n";
}

if ($soapClient != null)
{
	$soapClient = null;
}
</pre>
<p>Using curl:</p>
<pre class="brush: php">
define('NEWLINE', "&lt;br /&gt;\n");

$ch = curl_init();

$data = '&lt;soapenv:Envelope xmlns:ns2="http://example.com/sample/namespace/security"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://example.com/sample/namespace/data"&gt;
  &lt;soapenv:Header&gt;
    &lt;ns2:Security&gt;
      &lt;ns2:UsernameToken&gt;
        &lt;ns2:Username&gt;user9&lt;/ns2:Username&gt;
        &lt;ns2:Password&gt;pass1234&lt;/ns2:Password&gt;
      &lt;/ns2:UsernameToken&gt;
    &lt;/ns2:Security&gt;
  &lt;/soapenv:Header&gt;
  &lt;soapenv:Body&gt;
    &lt;ns1:getData soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
      &lt;param1 xsi:type="xsd:string"&gt;abcdef&lt;/param1&gt;
      &lt;param2 xsi:type="xsd:integer"&gt;12345&lt;/param2&gt;
    &lt;/ns1:getData&gt;
  &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;';

$fh = fopen('soap_response.txt', 'w'); 

curl_setopt($ch, CURLOPT_URL, 'https://example.com:1234/sample/service');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSLKEY, 'sample.pem');
curl_setopt($ch, CURLOPT_FILE, $fh);

if (curl_exec($ch) === false)
{
    echo "Curl error: " . curl_error($ch) . NEWLINE;
}
else
{
    echo "Operation completed successfully" . NEWLINE;
}

curl_close($ch);
fclose($fh);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/calling-a-soap-web-service-from-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling a WCF service from PHP</title>
		<link>http://www.rizalalmashoor.com/blog/calling-a-wcf-service-from-php/</link>
		<comments>http://www.rizalalmashoor.com/blog/calling-a-wcf-service-from-php/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 06:55:06 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/calling-a-wcf-service-from-php/</guid>
		<description><![CDATA[The WCF service needs to use basicHttpBinding.
The PHP code:

define('NEWLINE', "&#60;br /&#62;\n");

// SOAP client

$wsdl = 'http://example.com/SampleWcfService.SampleService.Service?wsdl';
$soapClient = new SoapClient($wsdl, array('cache_wsdl' =&#62; 0));

// SOAP call

$sampleData-&#62;SampleProperty = "abc";

$parameters-&#62;sampleId = 123;
$parameters-&#62;sampleData = $sampleData;

try
{
	$result = $soapClient-&#62;GetData($parameters);
}
catch (SoapFault $fault)
{
	echo "Fault code: {$fault-&#62;faultcode}" . NEWLINE;
	echo "Fault string: {$fault-&#62;faultstring}" . NEWLINE;
	if ($soapClient != null)
	{
		$soapClient = null;
	}
	exit();
}
$soapClient = null;

//echo "&#60;pre&#62;\n";
//print_r($result);
//echo "&#60;/pre&#62;\n";

echo "Return value: {$result-&#62;GetDataResult}" [...]]]></description>
			<content:encoded><![CDATA[<p>The WCF service needs to use basicHttpBinding.</p>
<p>The PHP code:</p>
<pre class="brush: php">
define('NEWLINE', "&lt;br /&gt;\n");

// SOAP client

$wsdl = 'http://example.com/SampleWcfService.SampleService.Service?wsdl';
$soapClient = new SoapClient($wsdl, array('cache_wsdl' =&gt; 0));

// SOAP call

$sampleData-&gt;SampleProperty = "abc";

$parameters-&gt;sampleId = 123;
$parameters-&gt;sampleData = $sampleData;

try
{
	$result = $soapClient-&gt;GetData($parameters);
}
catch (SoapFault $fault)
{
	echo "Fault code: {$fault-&gt;faultcode}" . NEWLINE;
	echo "Fault string: {$fault-&gt;faultstring}" . NEWLINE;
	if ($soapClient != null)
	{
		$soapClient = null;
	}
	exit();
}
$soapClient = null;

//echo "&lt;pre&gt;\n";
//print_r($result);
//echo "&lt;/pre&gt;\n";

echo "Return value: {$result-&gt;GetDataResult}" . NEWLINE;
</pre>
<p>IService.cs:</p>
<pre class="brush: csharp">
using System.ServiceModel;

namespace SampleWcfService.SampleService
{
    [ServiceContract(Namespace = "http://example.com/SampleWcfService/SampleService")]
    public interface IService
    {
        [OperationContract(Name = "GetData")]
        string GetData(int sampleId, SampleType sampleData);
    }
}
</pre>
<p>Service.cs:</p>
<pre class="brush: csharp">
namespace SampleWcfService.SampleService
{
    public class Service : IService
    {
        public string GetData(int sampleId, SampleType sampleData)
        {
            return string.Format("sampleId = {0}, sampleType.SampleProperty = {1}", sampleId, sampleData.SampleProperty);
        }
    }
}
</pre>
<p>SampleType.cs:</p>
<pre class="brush: csharp">
using System.Runtime.Serialization;

namespace SampleWcfService.SampleService
{
    [DataContract(Namespace = "http://example.com/SampleWcfService/SampleService", Name = "SampleType")]
    public class SampleType
    {
        [DataMember(Name = "SampleProperty")]
        public string SampleProperty { get; set; }
    }
}
</pre>
<p>App.config:</p>
<pre class="brush: xml">
&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
	&lt;system.serviceModel&gt;
		&lt;services&gt;
			&lt;service
				behaviorConfiguration="SampleWcfService.SampleService.Service.Behavior"
				name="SampleWcfService.SampleService.Service"&gt;
				&lt;endpoint address=""
						  binding="basicHttpBinding"
						  contract="SampleWcfService.SampleService.IService" /&gt;
				&lt;host&gt;
					&lt;baseAddresses&gt;
						&lt;add baseAddress="http://example.com/SampleWcfService.SampleService.Service" /&gt;
					&lt;/baseAddresses&gt;
				&lt;/host&gt;
			&lt;/service&gt;
		&lt;/services&gt;
		&lt;behaviors&gt;
			&lt;serviceBehaviors&gt;
				&lt;behavior name="SampleWcfService.SampleService.Service.Behavior" &gt;
					&lt;serviceMetadata httpGetEnabled="true" /&gt;
				&lt;/behavior&gt;
			&lt;/serviceBehaviors&gt;
		&lt;/behaviors&gt;
	&lt;/system.serviceModel&gt;
&lt;/configuration&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/calling-a-wcf-service-from-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using log4php</title>
		<link>http://www.rizalalmashoor.com/blog/using-log4php/</link>
		<comments>http://www.rizalalmashoor.com/blog/using-log4php/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 23:46:13 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/using-log4php/</guid>
		<description><![CDATA[A how-to for the excellent log4php:

Rolling daily file
Log error statements into one file, and info statements into another
Send emails

Usage

include_once('/var/www/example/components/log4php/2.0.0/Logger.php');

class Example
{
	private $logger;

	function __construct()
	{
		$loggerConfig = '/var/www/example/config/log4php.xml';
		Logger::configure($loggerConfig);
		$this-&#62;logger = Logger::getLogger('example');
	}

	public function doSomething()
	{
		$var = $this-&#62;getSomeValue();
		$this-&#62;logger-&#62;debug('in doSomething: $var = ' . $var);
		try
		{
			$this-&#62;doSomethingSpecific();
		}
		catch (Exception $ex)
		{
			$this-&#62;logger-&#62;error($ex-&#62;getMessage());
			throw new Exception("There is a problem with Something. We apologize for any inconvenience caused.");
		}
		$this-&#62;logger-&#62;info("doSomething successful");
	}
}

log4php.xml

&#60;log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/"&#62;
   [...]]]></description>
			<content:encoded><![CDATA[<p>A how-to for the excellent <a href="http://incubator.apache.org/log4php/index.html">log4php</a>:</p>
<ol>
<li>Rolling daily file</li>
<li>Log error statements into one file, and info statements into another</li>
<li>Send emails</li>
</ol>
<h3>Usage</h3>
<pre class="brush: php">
include_once('/var/www/example/components/log4php/2.0.0/Logger.php');

class Example
{
	private $logger;

	function __construct()
	{
		$loggerConfig = '/var/www/example/config/log4php.xml';
		Logger::configure($loggerConfig);
		$this-&gt;logger = Logger::getLogger('example');
	}

	public function doSomething()
	{
		$var = $this-&gt;getSomeValue();
		$this-&gt;logger-&gt;debug('in doSomething: $var = ' . $var);
		try
		{
			$this-&gt;doSomethingSpecific();
		}
		catch (Exception $ex)
		{
			$this-&gt;logger-&gt;error($ex-&gt;getMessage());
			throw new Exception("There is a problem with Something. We apologize for any inconvenience caused.");
		}
		$this-&gt;logger-&gt;info("doSomething successful");
	}
}
</pre>
<h3>log4php.xml</h3>
<pre class="brush: xml">
&lt;log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/"&gt;
    &lt;appender name="default" class="LoggerAppenderDailyFile"&gt;
        &lt;param name="file" value="/var/www/example/logs/%s.log" /&gt;
        &lt;param name="datePattern" value="Ymd" /&gt;
        &lt;layout class="LoggerLayoutPattern"&gt;
            &lt;param name="ConversionPattern" value="%d{Y-m-d H:i:s} [%p] %c: %m (at %F line %L)%n" /&gt;
        &lt;/layout&gt;
    &lt;/appender&gt;
    &lt;appender name="exampleDebugLog" class="LoggerAppenderDailyFile"&gt;
        &lt;param name="file" value="/var/www/example/logs/debug.%s.log" /&gt;
        &lt;param name="datePattern" value="Ymd" /&gt;
        &lt;layout class="LoggerLayoutPattern"&gt;
            &lt;param name="ConversionPattern" value="%d{Y-m-d H:i:s} [%p] %c: %m%n" /&gt;
        &lt;/layout&gt;
        &lt;filter class="LoggerFilterLevelRange"&gt;
            &lt;param name="LevelMin" value="debug" /&gt;
            &lt;param name="LevelMax" value="debug" /&gt;
        &lt;/filter&gt;
        &lt;filter class="LoggerFilterDenyAll" /&gt;
    &lt;/appender&gt;
    &lt;appender name="exampleInfoLog" class="LoggerAppenderDailyFile"&gt;
        &lt;param name="file" value="/var/www/example/logs/info.%s.log" /&gt;
        &lt;param name="datePattern" value="Ymd" /&gt;
        &lt;layout class="LoggerLayoutPattern"&gt;
            &lt;param name="ConversionPattern" value="%d{Y-m-d H:i:s} [%p] %c: %m%n" /&gt;
        &lt;/layout&gt;
        &lt;filter class="LoggerFilterLevelRange"&gt;
            &lt;param name="LevelMin" value="info" /&gt;
            &lt;param name="LevelMax" value="info" /&gt;
        &lt;/filter&gt;
        &lt;filter class="LoggerFilterDenyAll" /&gt;
    &lt;/appender&gt;
    &lt;appender name="exampleErrorLog" class="LoggerAppenderDailyFile"&gt;
        &lt;param name="file" value="/var/www/example/logs/errors.%s.log" /&gt;
        &lt;param name="datePattern" value="Ymd" /&gt;
        &lt;layout class="LoggerLayoutPattern"&gt;
            &lt;param name="ConversionPattern" value="%d{Y-m-d H:i:s} [%p] %c: %m (at %F line %L)%n" /&gt;
        &lt;/layout&gt;
        &lt;filter class="LoggerFilterLevelRange"&gt;
            &lt;param name="LevelMin" value="error" /&gt;
            &lt;param name="LevelMax" value="fatal" /&gt;
        &lt;/filter&gt;
        &lt;filter class="LoggerFilterDenyAll" /&gt;
    &lt;/appender&gt;
    &lt;appender name="exampleErrorEmail" class="LoggerAppenderMail"&gt;
        &lt;param name="from" value="sys@example.com" /&gt;
        &lt;param name="to" value="support@example.com" /&gt;
        &lt;param name="subject" value="Error" /&gt;
        &lt;layout class="LoggerLayoutPattern"&gt;
            &lt;param name="ConversionPattern" value="%d{Y-m-d H:i:s} [%p] %c: %m (at %F line %L)%n" /&gt;
        &lt;/layout&gt;
        &lt;filter class="LoggerFilterLevelRange"&gt;
            &lt;param name="LevelMin" value="error" /&gt;
            &lt;param name="LevelMax" value="fatal" /&gt;
        &lt;/filter&gt;
        &lt;filter class="LoggerFilterDenyAll" /&gt;
    &lt;/appender&gt;
    &lt;root&gt;
        &lt;level value="DEBUG" /&gt;
        &lt;appender_ref ref="default" /&gt;
    &lt;/root&gt;
    &lt;logger name="example" additivity="false"&gt;
        &lt;level value="INFO" /&gt;
        &lt;appender_ref ref="exampleInfoLog" /&gt;
        &lt;appender_ref ref="exampleErrorLog" /&gt;
        &lt;appender_ref ref="exampleErrorEmail" /&gt;
    &lt;/logger&gt;
&lt;/log4php:configuration&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/using-log4php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling a .NET asmx web service over https from PHP</title>
		<link>http://www.rizalalmashoor.com/blog/calling-a-net-asmx-web-service-over-https-from-php/</link>
		<comments>http://www.rizalalmashoor.com/blog/calling-a-net-asmx-web-service-over-https-from-php/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 13:44:08 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/calling-a-net-asmx-web-service-over-https-from-php/</guid>
		<description><![CDATA[
Enable SOAP by uncommenting &#8220;extension=php_soap.dll&#8221; in php.ini
https should be included in &#8220;Registered PHP Streams&#8221; (phpinfo) &#8211; uncomment &#8220;extension=php_openssl.dll&#8221; in php.ini


// SOAP client

$wsdl = 'https://www.example.com/services/ProductManagement.asmx?wsdl';
$endpoint = array
(
	'location' =&#62; 'https://www.example.com/services/ProductManagement.asmx'
);
$soapClient = new SoapClient($wsdl, $endpoint);

// SOAP header

$soapHeaders = array();

$namespace = 'http://www.example.com/services/ProductManagement';
$elementName = 'Authentication';
$authenticationHeader = array
(
	'Username' =&#62; 'user9',
	'Password' =&#62; 'pass1234',
);
$soapHeader = new SoapHeader($namespace, $elementName, $authenticationHeader);
$soapHeaders[] = $soapHeader;

$soapClient-&#62;__setSoapHeaders($soapHeaders);

// SOAP call

$parameters->productCode [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Enable SOAP by uncommenting &#8220;extension=php_soap.dll&#8221; in php.ini</li>
<li>https should be included in &#8220;Registered PHP Streams&#8221; (phpinfo) &ndash; uncomment &#8220;extension=php_openssl.dll&#8221; in php.ini</li>
</ol>
<pre class="brush: php">
// SOAP client

$wsdl = 'https://www.example.com/services/ProductManagement.asmx?wsdl';
$endpoint = array
(
	'location' =&gt; 'https://www.example.com/services/ProductManagement.asmx'
);
$soapClient = new SoapClient($wsdl, $endpoint);

// SOAP header

$soapHeaders = array();

$namespace = 'http://www.example.com/services/ProductManagement';
$elementName = 'Authentication';
$authenticationHeader = array
(
	'Username' =&gt; 'user9',
	'Password' =&gt; 'pass1234',
);
$soapHeader = new SoapHeader($namespace, $elementName, $authenticationHeader);
$soapHeaders[] = $soapHeader;

$soapClient-&gt;__setSoapHeaders($soapHeaders);

// SOAP call

$parameters->productCode = '9555170408350';

try
{
	$result = $soapClient-&gt;GetProduct($parameters);
}
catch (SoapFault $fault)
{
	echo "Fault code: {$fault-&gt;faultcode}&lt;br /&gt;\n";
	echo "Fault string: {$fault-&gt;faultstring}&lt;br /&gt;\n";
	if ($soapClient != null)
	{
		$soapClient = null;
	}
	exit();
}
$soapClient = null;

//echo "&lt;pre&gt;\n";
//print_r($result);
//echo "&lt;/pre&gt;\n";

echo "Product code: {$result-&gt;GetProductResult-&gt;ProductCode}&lt;br /&gt;\n";
echo "Name: {$result-&gt;GetProductResult-&gt;Name}&lt;br /&gt;\n";
echo "Description: {$result-&gt;GetProductResult-&gt;Description}&lt;br /&gt;\n";
echo "Category: {$result-&gt;GetProductResult-&gt;Category}&lt;br /&gt;\n";
echo "SKU: {$result-&gt;GetProductResult-&gt;SKU}&lt;br /&gt;\n";
echo "Manufacturer: {$result-&gt;GetProductResult-&gt;Manufacturer}&lt;br /&gt;\n" ;
echo "Brand: {$result-&gt;GetProductResult-&gt;Brand}&lt;br /&gt;\n";
echo "In stock: ";
echo ($result-&gt;GetProductResult-&gt;IsInStock ? "Yes" : "No") . "&lt;br /&gt;\n";
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/calling-a-net-asmx-web-service-over-https-from-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Data Sanitizer</title>
		<link>http://www.rizalalmashoor.com/blog/data-sanitizer/</link>
		<comments>http://www.rizalalmashoor.com/blog/data-sanitizer/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 09:44:11 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/data-sanitizer/</guid>
		<description><![CDATA[I wrote a C# console app to sanitize CSV files. It replaces numbers with X&#8217;s so that social security number 123456 becomes XXXXXX and the address &#8220;49 Main St&#8221; becomes &#8220;XX Main St&#8221;. Both the input and the output are streamed to ensure that the program won&#8217;t run out of memory even with arbitrarily large [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a C# console app to sanitize CSV files. It replaces numbers with X&#8217;s so that social security number 123456 becomes XXXXXX and the address &#8220;49 Main St&#8221; becomes &#8220;XX Main St&#8221;. Both the input and the output are streamed to ensure that the program won&#8217;t run out of memory even with arbitrarily large files.</p>
<pre class="brush: csharp">
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace DataSanitizer
{
    class Program
    {
        private const string Delimiter = "|";
        private const string ReplacementCharacter = "X";
        private const int NumFields = 15;

        static void Main(string[] args)
        {
            if (args.Length &lt; 2)
            {
                Console.WriteLine("Usage: DataSanitizer.exe input_file output_file");
                return;
            }

            string inputFilePathAndName = args[0];
            string outputFilePathAndName = args[1];

            using (StreamReader sr = new StreamReader(inputFilePathAndName))
            using (StreamWriter sw = new StreamWriter(outputFilePathAndName, true))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] fields = line.Split(Delimiter.ToCharArray());
                    string ssn = fields[2];
                    string addressLine1 = fields[4];
                    string addressLine2 = fields[5];
                    string addressLine3 = fields[6];
                    string telHome = fields[9];
                    string telOffice = fields[10];
                    string telMobile = fields[11];
                    Regex alphanumeric = new Regex(@"&#92;w");
                    Regex numeric = new Regex(@"&#92;d");
                    string ssnSanitized = alphanumeric.Replace(ssn, ReplacementCharacter);
                    string addressLine1Sanitized = numeric.Replace(addressLine1, ReplacementCharacter);
                    string addressLine2Sanitized = numeric.Replace(addressLine2, ReplacementCharacter);
                    string addressLine3Sanitized = numeric.Replace(addressLine3, ReplacementCharacter);
                    string telHomeSanitized = alphanumeric.Replace(telHome, ReplacementCharacter);
                    string telOfficeSanitized = alphanumeric.Replace(telOffice, ReplacementCharacter);
                    string telMobileSanitized = alphanumeric.Replace(telMobile, ReplacementCharacter);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i &lt; NumFields; i++)
                    {
                        if (i &gt; 0)
                        {
                            sb.Append(Delimiter);
                        }
                        switch (i)
                        {
                            case 2:
                                sb.Append(ssnSanitized);
                                break;
                            case 4:
                                sb.Append(addressLine1Sanitized);
                                break;
                            case 5:
                                sb.Append(addressLine2Sanitized);
                                break;
                            case 6:
                                sb.Append(addressLine3Sanitized);
                                break;
                            case 9:
                                sb.Append(telHomeSanitized);
                                break;
                            case 10:
                                sb.Append(telOfficeSanitized);
                                break;
                            case 11:
                                sb.Append(telMobileSanitized);
                                break;
                            default:
                                sb.Append(fields[i]);
                                break;
                        }
                    }
                    sw.WriteLine(sb.ToString());
                }
            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/data-sanitizer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Urgent</title>
		<link>http://www.rizalalmashoor.com/blog/urgent/</link>
		<comments>http://www.rizalalmashoor.com/blog/urgent/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 11:59:02 +0000</pubDate>
		<dc:creator>Rizal Almashoor</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.rizalalmashoor.com/blog/urgent/</guid>
		<description><![CDATA[You don&#8217;t know the meaning of urgent until you&#8217;re stuck in a traffic jam with a small child who has just started potty training, who urgently needs to go &#8230;
]]></description>
			<content:encoded><![CDATA[<p>You don&#8217;t know the meaning of urgent until you&#8217;re stuck in a traffic jam with a small child who has just started potty training, who urgently needs to go &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rizalalmashoor.com/blog/urgent/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
