<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CoDaXe Blog</title>
	<atom:link href="http://blog.codaxe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codaxe.com</link>
	<description>Research notes</description>
	<lastBuildDate>Thu, 03 Nov 2011 23:37:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Implementing Code Igniter &#8220;Roll Back&#8221; System</title>
		<link>http://blog.codaxe.com/2011/06/implementing-code-igniter-roll-back-system/</link>
		<comments>http://blog.codaxe.com/2011/06/implementing-code-igniter-roll-back-system/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 23:59:14 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=248</guid>
		<description><![CDATA[If you need to ensure that your system or database does not have half complete executions which might have halted due to failures, you have two obvious solutions. One is to try and pre-verify everything before you start your execution but even that is not bulletproof. A more elegant approach is to push each equal [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to ensure that your system or database does not have half complete executions which might have halted due to failures, you have two obvious solutions. One is to try and pre-verify everything before you start your execution but even that is not bulletproof. A more elegant approach is to push each equal and opposite actions to a stack and cause the stack to pop and execute on any failure. Read on to see an implementation.</p>
<p><span id="more-248"></span></p>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>1. </strong></span><strong><span style="text-decoration: underline; color: #0000ff;">Add the lib_rollback.php class to your library folder</span><br />
</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* A class responsible for keeping tracking and rolling back actions
* It has an internal stack on which php actions gets executed. The pushed actions
* are equal opposites of action being performed this way if any error occurs the stack
* is poppped and actions are undone.
*/
class Lib_rollback
{
    /**
    * An array used as a stack to push changes to undo in case of failure
    *
    * @var array
    **/
    private $rollbackStack; 

    /**
    * An object reference to the ci object
    *
    * @var obj
    **/
    protected $ci;   

    /**
    * Constructor
    */
    function Lib_rollback()
    {
		// Initiliaze the CI Object as reference
        $this-&gt;ci =&amp;get_instance();
		// Reset the stack
        $this-&gt;resetStack();
    }

    /**
    * Reset the stack by emptying the array
    */
    function resetStack()
    {
        $this-&gt;rollbackStack = array();
    }

    /**
    * Push an action onto the stack. The action should be a valid php executable action
    * which will get evaluated
    *
    * @param string $inAction      The php action which will be evaluated
    * @return void
    */
    function pushAction($inAction)
    {
        array_push($this-&gt;rollbackStack, $inAction);
    }

    /**
    * This iniates the roll back action and evaluates and executes every action on the stack.
    * This is triggered if an error occurs to prevent partial runs
    *
    */
    function rollBackNow()
    {
          while(count($this-&gt;rollbackStack) &gt; 0)
          {
              $currentTask = array_pop($this-&gt;rollbackStack);
              eval($currentTask);
          }
    }
}
</pre>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>2. </strong></span><strong><span style="text-decoration: underline; color: #0000ff;">Autoload the library</span><br />
</strong></p>
<p>- Edit the file config &gt; autload.php and add &#8220;lib_rollback&#8221; to the $autoload['libraries']<br />
(i.e: $autoload['libraries'] = array(&#8216;database&#8217;, &#8216;session&#8217;, &#8216;lib_rollback&#8217;);)</p>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>3. </strong></span><strong><span style="text-decoration: underline; color: #0000ff;">Overload the exceptions to trigger the stack rollback</span><br />
</strong></p>
<p>Now that the stack is setup we need an automatic way for it to be called in case of errors. This can be done by overoading the Exceptions class of code igniter in particular two functions,  show_error() and show_php_error(). These are two functions which get called when something goes wrong.<br />
So create a file called MY_Exceptions.php inside the &#8220;application &gt; core&#8221; folder. In this file start it like so</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class  MY_Exceptions  extends  CI_Exceptions  {
    function show_error($heading, $message, $template = 'error_general', $status_code = 500)
    {
        $this-&gt;ci =&amp;get_instance();
        $this-&gt;ci-&gt;lib_rollback-&gt;rollBackNow();
        //....
    }

    function show_php_error($severity, $message, $filepath, $line)
    {
        $this-&gt;ci =&amp;get_instance();
        $this-&gt;ci-&gt;lib_rollback-&gt;rollBackNow();
        //....
    }
}
</pre>
<p>Inside this class copy paste the original show_error() and show_php_error() functions into it then at the top of each call your rollback function.</p>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>4. </strong></span><strong><span style="text-decoration: underline; color: #0000ff;">Example usage</span><br />
</strong></p>
<pre class="brush: php; title: ; notranslate">
        $tempFolder = &quot;C:/WebRoot/tmp/active&quot;
        mkdir($tempFolder );
        // Push the action to a stack to propery undo in case of mid failure
        $this-&gt;lib_rollback-&gt;pushAction(&quot;rmdir($tempFolder);&quot;);
</pre>
<p>That should do it! Don&#8217;t forget that what you push must be a valid php command with an ending semi colon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/06/implementing-code-igniter-roll-back-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bidirectional backup solution with unison on windows &#8211; Part 1</title>
		<link>http://blog.codaxe.com/2011/05/bidirectional-backup-solution-with-unison-part-1/</link>
		<comments>http://blog.codaxe.com/2011/05/bidirectional-backup-solution-with-unison-part-1/#comments</comments>
		<pubDate>Wed, 04 May 2011 04:14:25 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Systems]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bidirectional]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[unison]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=130</guid>
		<description><![CDATA[After much research into available backup solutions for windows I could not find one that could do what I wanted (essentially sync files and folders across machines and have changes replicated in all directions so if a change occurred on machine 1 and another on machine 2 both changes would be reflected in both machines [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/un3.jpg"><img class="alignright size-full wp-image-233" title="un3" src="http://blog.codaxe.com/wp-content/uploads/2011/05/un3.jpg" alt="" width="300" height="138" /></a>After much research into available backup solutions for windows I could not find one that could do what I wanted (essentially sync files and folders across machines and have changes replicated in all directions so if a change occurred on machine 1 and another on machine 2 both changes would be reflected in both machines instead of one change overwriting the other in a traditional one directional backup solutions). A popular service which serves this purpose is <a href="http://www.dropbox.com">Dropbox</a> but it runs on the cloud and that&#8217;s enough for you to look the other way. I&#8217;m not a fan of the cloud and neither should you, keep your files safe locally and encrypted. </p>
<p>A linux based command line utility called <strong><a href="http://www.samba.org/ftp/rsync/rsync.html">rsync</a></strong> was the first milestone in finding a solution in terms of efficiency as it is extremely fast in replicating updates across however the problem was this was also one directional.<br />
The final solution came when I discovered a tool called <strong><a href="http://www.cis.upenn.edu/~bcpierce/unison/">unison</a></strong> which is based on rsync but provides this bidirectional functionality. Unison and rsync are both unix based tool so we will use cygwin on windows to use them.</p>
<p><span id="more-130"></span></p>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>1. </strong></span><strong><span style="text-decoration: underline; color: #0000ff;">Install cygwin on Machine 1 and Machine 2</span><br />
</strong></p>
<p style="padding-left: 30px;">Download the installer from <a href="http://www.cygwin.com">http://www.cygwin.com</a>. Follow the instructions until you get to the &#8220;Select Packages&#8221; pages. On this page select specific packages listed below. Simply search for them in the search bar at the top and when they appear on the list click on &#8220;Skip&#8221; it will change it to &#8220;Keep&#8221; which will install them.</p>
<p style="padding-left: 30px;"><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/cygwin_install.png"><img class="alignnone size-thumbnail wp-image-147" title="cygwin_install" src="http://blog.codaxe.com/wp-content/uploads/2011/05/cygwin_install-150x150.png" alt="" width="150" height="150" /></a></p>
<p style="padding-left: 30px;"><strong>Step 1-5)</strong> Next</p>
<p style="padding-left: 30px;"><strong>Step 6) </strong>Select a proxy, any really</p>
<p style="padding-left: 30px;"><strong>Step 7)</strong> Wait for download</p>
<p style="padding-left: 30px;"><strong>Step 8 )</strong> Press OK</p>
<p style="padding-left: 30px;"><strong>Step 9)</strong> Select the following packages</p>
<p style="padding-left: 30px;">(required) net &gt; openssh<br />
(required) utils &gt; unison (2.40 or higher)<br />
(recommended) tools &gt; tcp_wrappers<br />
(recommended) editors &gt; vim<br />
(recommended)  net &gt; rsync</p>
<p style="padding-left: 30px;"><strong>Step 10)</strong> Next</p>
<p style="padding-left: 30px;"><strong>Step 11)</strong> Wait for install</p>
<p style="padding-left: 30px;"><strong>Step 12) </strong>Finish</p>
<p style="padding-left: 30px;">You might get a popup on Windows 7 like below. You may safely ignore it and press &#8220;This program installed correctly&#8221;. This is due to the nature of the cygwin installer which is in essence just an extractor with optional registry insertion features.</p>
<p style="padding-left: 30px;"><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/13.png"><img class="alignnone size-thumbnail wp-image-150" title="13" src="http://blog.codaxe.com/wp-content/uploads/2011/05/13-150x150.png" alt="" width="150" height="150" /></a></p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff;"><strong>2. Setup SSH Server on Machine 1 (pick machine 1 to be your server, pick the computer that is most reliable or on the most)<br />
</strong></span></span></p>
<p style="padding-left: 30px;"><strong>Step 1) </strong>Right click on the shortcut created by the installer and select &#8220;Run as administrator&#8221;</p>
<p style="padding-left: 30px;"><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/15.png"><img class="alignnone size-thumbnail wp-image-152" title="15" src="http://blog.codaxe.com/wp-content/uploads/2011/05/15-150x150.png" alt="" width="150" height="150" /></a></p>
<p style="padding-left: 30px;"><strong>Step 2) </strong>Type</p>
<pre class="brush: bash; title: ; notranslate">
$ mkdir /var/empty
$ chgrp Administrators /var/{run,log,empty}
$ chown Administrators /var/{run,log,empty}
$ chmod 775 /var/{run,log}
$ chmod 755 /var/empty
</pre>
<p style="padding-left: 30px;"><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/16.png"><img class="alignnone size-thumbnail wp-image-153" title="16" src="http://blog.codaxe.com/wp-content/uploads/2011/05/16-150x150.png" alt="" width="150" height="150" /></a></p>
<p style="padding-left: 30px;"><strong>Step 3) </strong>Type the following commands</p>
<pre class="brush: bash; title: ; notranslate">
$ ssh-host-config
$ Should privilege seperation be used? (yes/no) yes
$ new local account 'sshd'? (yes/no) yes
$ Do you want to install sshd as a service? (yes/no) yes
$ Enter the value of CYGWIN for the daemon: [] ntsec tty binmode server nodosfilewarning
$ Do you want to use a different name? (yes/no) no
$ Create new privileged user account 'cyg_server'? (yes/no)? yes
# type here any password you wish
$ Please enter the password: ______________
$ Reenter: ______________
</pre>
<p style="padding-left: 30px;"><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/19.png"><img class="alignnone size-thumbnail wp-image-154" title="19" src="http://blog.codaxe.com/wp-content/uploads/2011/05/19-150x150.png" alt="" width="150" height="150" /></a></p>
<p style="padding-left: 30px;"><strong>Step 4)</strong> Start the ssh server</p>
<pre class="brush: bash; title: ; notranslate">
$ net start sshd
# note as seen in the screenshot you will see the ssh try to start and automatically stop. This happens because you need to give proper permission to the user you specified during ssh-host-config which in our case was the default 'cyg_server' this is the user which needs to own the appropriate directories so it is fixed with chown cyg_server /var/empty'
$ chown cyg_server /var/empty
$ chmod 755 /var/empty
$ net start sshd
# At this point you should be all set and have a working up and running ssh server on windows.
</pre>
<p style="padding-left: 30px;"><a href="http://blog.codaxe.com/wp-content/uploads/2011/05/21.png"><img class="alignnone size-thumbnail wp-image-166" title="21" src="http://blog.codaxe.com/wp-content/uploads/2011/05/21-150x150.png" alt="" width="150" height="150" /></a><br />
<span style="text-decoration: underline;"> <span style="color: #0000ff;"><br />
<strong> </strong></span></span></p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff;"><strong>2. Configure SSH Key Authentification on Machine 2 and Machine 1</strong></span><br />
</span></p>
<p style="padding-left: 30px;"><strong>Step 1) </strong>On Machine 2 generate ssh keys</p>
<pre class="brush: bash; title: ; notranslate">
$ ssh-keygen -t rsa
  Generating public/private rsa key pair.
# type yes to select default location to store the keys
$ Enter file in which to save the key (/home/DX2/.ssh/id_rsa): yes
# when asked for a password press enter do not type in anything it will make your life easier
$ Enter passphrase (empty for no passphrase):
$ Enter same passphrase again:
 Your identification has been saved in yes.
 Your public key has been saved in yes.pub.
 The key fingerprint is:
 5e:cc:85:43:b5:08:6b:b7:5f:04:41:7e:4d:39:cb:93 DX@DX
 The key's randomart image is:
 +--[ RSA 2048]----+
|        . .o=.  o|
|         + + o = |
|        o = + + =|
|       . + + o E |
|        S =   . .|
|       . . . .   |
|        .   .    |
|                 |
|                 |
+-----------------+
</pre>
<p style="padding-left: 30px;"><strong>Step 2) </strong>Organize your ssh keys on Machine 2<strong><br />
</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ mkdir -p ~/.ssh/ids/192.168.1.110/DX
# 192.168..1.110 should be the hostname of your server / DX should be the username on the server&lt;/pre&gt;
$ touch ~/.ssh/config
$ vi ~/.ssh/config
# now press i (enters editing mode) then type in the following line by line (without the # sign)
# IdentityFile ~/.ssh/ids/%h/%r/id_rsa
# IdentityFile ~/.ssh/ids/%h/id_rsa
# IdentityFile ~/.ssh/id_rsa
# now press [escape] then : then wq then [enter]
# finally move the generated files earlier to this directory
# do this by running
$ mv ~/.ssh/id_* ~/.ssh/ids/192.168.1.110/DX/
</pre>
<p style="padding-left: 30px;"><strong>Step 3) </strong>Add your public key to Machine 1<strong><br />
</strong></p>
<p>Now copy the content from Machine 2 of ~/.ssh/ids/192.168.1.110/DX/id_rsa.pub(C:\cygwin\home\DX\.ssh\ids\192.168.1.110\DX\id_rsa.pub) and paste it on Machine 1 inside ~/.ssh/authorized_keys (C:\cygwin\home\DX\.ssh\authorized_keys)</p>
<p style="padding-left: 30px;"><strong>Step 4) </strong>Test your ssh connection<strong><br />
</strong></p>
<pre class="brush: bash; title: ; notranslate">

# you are now all set with your connection, to test this you can do an
$ ssh -v DX@192.168.1.110
# this should log you in to your remote server, if there is an error the -v option should tell you what's wrong
</pre>
<p><span style="text-decoration: underline;"><span style="color: #0000ff;"><strong>3. Before your first sync copy your files manually from Machine 2 to Machine 1<br />
</strong></span></span></p>
<p style="padding-left: 30px;"><strong>Step 1) </strong>You first want to copy the files before using the bidirectional unison tool as it will be quite slow otherwise. You can use scp command for that purpose.</p>
<pre class="brush: bash; title: ; notranslate">
# for instance if you want to sync (client) C:\myfolder to (client) C:\myfolder first perform the below command to quickly make an exact duplicate copy
$ scp -r /cygwin/c/myfolder DX@192.168.1.110:/cygwin/c/myfolder
</pre>
<p>You can otherwise duplicate the directory any other way most convenient for you.</p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff;"><strong>4. Write your first bidirectional unison script on Machine 2</strong></span></span><br />
<strong> </strong></p>
<p style="padding-left: 30px;"><strong>Step 1) </strong>Go to your home directory and create a .unison directory if it does not exist</p>
<pre class="brush: bash; title: ; notranslate">
$ mkdir ~/.unison
</pre>
<p style="padding-left: 30px;"><strong>Step 2) </strong>Create a file common.prf in your .unison directory</p>
<pre class="brush: bash; title: ; notranslate">
$ touch ~/.unison/base.prf
</pre>
<p style="padding-left: 30px;"><strong>Step 3) </strong>Edit base.prf either through vi in the terminal or in your favorite text editor and add the following lines</p>
<pre class="brush: bash; title: ; notranslate">
# helps out speed on Windows
fastcheck = true

# backup related
backup         = Name *
backuplocation = central
backupdir      = Backups
maxbackups     = 37

# log file
logfile        = unison.log

# don't synchronize permissions
perms = 0

# place new files at the top of the list
sortnewfirst = true

# turn on ssh compression
rshargs = -C
sshargs = -C

# ignore files from sync
ignore = Name Thumbs.db
ignore = Name *~
ignore = Name *.tmp
</pre>
<p style="padding-left: 30px;"><strong>Step 4) </strong>Create your sync script by creating a mysync.prf</p>
<pre class="brush: bash; title: ; notranslate">
$ touch ~/.unison/mysync.prf
</pre>
<p style="padding-left: 30px;"><strong>Then add the following lines to it</strong></p>
<pre class="brush: bash; title: ; notranslate">
include base.prf
# the local path to the directory to sync (/cygdrive/ needs to be there, just focus on the path after cygdrive)
root = /cygdrive/c/myfolder/
# the remote user, host and path to directory to do the bidirectional sync
root = ssh://DX@192.168.1.110//cygdrive/c/myfolder/
</pre>
<p style="padding-left: 30px;"><strong>Step 5) </strong>Congratulations! You are now all set to do your bidirectional sync. I would recommend the first time around to do a manual run by ommitting the flag -batch so it will prompt you to answer questions. Once you get comfortable with the process you can add -batch again</p>
<pre class="brush: bash; title: ; notranslate">
# the following command will update modified files in both directions, if you want no prompt add -batch at the end
$ unison mysync
Contacting server...
Connected [//DX//cygdrive/c/myfolder -&gt; //DX2//cygdrive/c/myfolder]
Looking for changes
Waiting for changes from server
No updates to propagate
</pre>
<p><span style="color: #0000ff;"><strong>Upcoming Subjects</strong></span><br />
- advanced unison configuration, specify merge application for unison to use<br />
- star topology network, sync it on all your machines<br />
- network connection triggered sync<br />
- ssh security</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/05/bidirectional-backup-solution-with-unison-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Cheatsheet</title>
		<link>http://blog.codaxe.com/2011/03/perl-cheatsheet-2/</link>
		<comments>http://blog.codaxe.com/2011/03/perl-cheatsheet-2/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 03:11:15 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Cheatsheets]]></category>
		<category><![CDATA[perl cheatsheet]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=54</guid>
		<description><![CDATA[Create directory if it doesn&#8217;t already exist For Debug output string representation of variable Delete all subdirectories and files from specified path Change current working directory Get all files in current directory Get all directories Get all files with specific keyword in name Check if file exists Delete file Get entire content of file to [...]]]></description>
			<content:encoded><![CDATA[<p><span id="more-54"></span></p>
<p><strong> Create directory if it doesn&#8217;t already exist</strong></p>
<pre class="brush: perl; title: ; notranslate">
my $createDir = &quot;C:\codaxe&quot;;
unless(-d $createDir){
	mkdir $createDir;
}
</pre>
<p><strong>For Debug output string representation of variable</strong></p>
<pre class="brush: perl; title: ; notranslate">
use Data::Dumper;
print Dumper($foo);
</pre>
<p><strong>Delete all  subdirectories and files from specified path</strong></p>
<pre class="brush: perl; title: ; notranslate">
sub DirectoryDelete {
	my $dirtodel = pop;
	my $sep = '\\';
	opendir(DIR, $dirtodel);
		my @files = readdir(DIR);
	closedir(DIR);

	@files = grep { !/^\.{1,2}/ } @files;
	@files = map { $_ = &quot;$dirtodel$sep$_&quot;} @files;
	@files = map { (-d $_)?DirectoryDelete($_):unlink($_) } @files;

	rmdir($dirtodel);
}
</pre>
<p><strong>Change current working directory</strong></p>
<pre class="brush: perl; title: ; notranslate">
my $setWorkingDir = &quot;C:\codaxe&quot;;
chdir( $setWorkingDir ) or die(&quot;Could change working directory to  $setWorkingDir&quot;);
</pre>
<p><strong>Get all files in current directory</strong></p>
<pre class="brush: perl; title: ; notranslate">
use File::Find;
use Cwd;
#Array which will contain all of the files in the current directory
my @allFilesCD;
#Extension of files to gather, if you want all use *
my $fileExtension = &quot;txt&quot;;
find(sub { if((-f($_)&amp;&amp;$_=~/.*.$fileExtension?$/i)) {
			push(@allFilesCD,$File::Find::name);
		 }
	}, cwd());
</pre>
<p><strong>Get all directories</strong></p>
<pre class="brush: perl; title: ; notranslate">
   #for first level down only
   my @dirs = grep { -d } glob 'C:\mydata\*';

  #for all levels down
  find(\&amp;dirs_all, &quot;C:\\mydata\\&quot;);
  sub dir_names {
    print &quot;$File::Find::dir\n&quot; if(-f $File::Find::dir,'/');
}
</pre>
<p><strong>Get all files with specific keyword in name</strong></p>
<pre class="brush: perl; title: ; notranslate">
my $keywordInFile = &quot;codaxe&quot;;
my @returnedFiles = grep {/.*$keywordInFile\.*/i} &lt;*&gt;;
</pre>
<p><strong>Check if file exists</strong></p>
<pre class="brush: perl; title: ; notranslate">
if(-e &quot;C:\codaxe.txt&quot;) {
	echo &quot;File Exists&quot;;
}
</pre>
<p><strong>Delete file</strong></p>
<pre class="brush: perl; title: ; notranslate">
my $fileToRemove = &quot;C:\codaxe.txt&quot;;
unlink($fileToRemove) or die( &quot;Couldnt not remove $fileToRemove.&quot;);
</pre>
<p><strong>Get entire content of file to scalar variable</strong></p>
<pre class="brush: perl; title: ; notranslate">
my $inputFile = &quot;C:\codaxe.txt&quot;;
open(FILE,&quot;$inputFile&quot;) or die;
# Fetch all content of current file to scalar allLines
my $allLines = do { local $/;  };
</pre>
<p><strong>Throw Catch Framework</strong></p>
<pre class="brush: perl; title: ; notranslate">
# throw class referenced from http://axkit.org/docs/presentations/tpc2002/exceptions.pdf
sub throw {
	my $mess = join('', @_);
	$mess =~ s/\n?$/\n/;
	my $i = 1;
	local $&quot; = &quot;', '&quot;;
	package DB;
	while (my @parts = caller($i++)) {
		my $q; $q = &quot;'&quot; if @DB::args;
		$mess .= &quot; -&gt; $parts[3](@DB::args)&quot; .
		&quot; at $parts[1] line $parts[2]\n&quot;;
	}
	die $mess;
}

# Setup your try catch structure and throw exceptions when needed
eval {
	if(defined($ARGV[0])) {

	}
	else {
		throw thrParamMissing;
	}

};
# Catch exceptions and execute different instructions based on them
if($@) {
	open (ERRORFILE, '&gt;errors.log');

	if ($@ =~ thrParamMissing) {
		echo thrParamMissing;
	}

	print ERRORFILE $@;
	die $@;
	close (ERRORFILE);
}

exit 0;
</pre>
<p><strong>Read file line by line and remove specific character</strong></p>
<pre class="brush: perl; title: ; notranslate">
my $inFile = &quot;C:\codaxeIN.txt&quot;;
my $outFile = &quot;C:\codaxeOUT.txt&quot;;
my $INFILE;
my $OUTFILE;

open($INFILE, $inFile) or die(&quot;Could not open $inFile&quot;);
open($OUTFILE, &quot;&gt;$outFile&quot;) or die(&quot;Could not open $outFile&quot;);
while (&lt;$INFILE&gt;) {
	# replace &amp; sign with &amp;amp
	s/\&amp;/\&amp;/g;
	print $OUTFILE &quot;$_&quot;;
}
close($INFILE);
close($OUTFILE);
</pre>
<p><strong>Generate Random String</strong></p>
<pre class="brush: perl; title: ; notranslate">
sub generate_random_string
{
	# the length of the random string to generate
	my $length_of_randomstring=shift;

	my @chars=('a'..'z','A'..'Z','0'..'9','_');
	my $random_string;
	foreach (1..$length_of_randomstring) {
		# rand @chars will generate a random
		# number between 0 and scalar @chars
		$random_string.=$chars[rand @chars];
	}
	return $random_string;
}
</pre>
<p><strong>Check if an executable is runnable in perl</strong></p>
<pre class="brush: perl; title: ; notranslate">
# The following allows to run myapp siliently from the terminal but capture the output in $myApp
# You can then do string comparison to check if the app is installed or runnable
my $myApp= `myapp 2&gt;&amp;1`;

if(!($myApp=~ m/getactivewindow/)) {
	print &quot;\nERROR: Application not found\n\n&quot;;
	exit 0;
}
</pre>
<p><strong>Replace string</strong></p>
<pre class="brush: perl; title: ; notranslate">
$myString=~ s/on/off/;
# this replaces &quot;on&quot; with &quot;off&quot; inside $myString
</pre>
<p><strong>Call a Perl script within another Perl script</strong></p>
<pre class="brush: perl; title: ; notranslate">
#Option 1:
system(&quot;/home/myScript.pl &quot;);
#Option 2 (note: these are back ticks not single quotes, this will give you the output from the script):
@myOutput = `/home/myScript.pl`
</pre>
<p><strong>Send email with attachment</strong></p>
<pre class="brush: perl; title: ; notranslate">
use MIME::Lite;
my $emailMsg= MIME::Lite-&gt;new(
	From    =&gt; 'from@email.com',
	To      =&gt; 'to@email.com',
	Cc      =&gt; 'to@email.com',
	Subject =&gt; 'Email Suject goes here',
	Type    =&gt; 'multipart/mixed',
);

$emailMsg-&gt;attach(
	Type     =&gt; 'TEXT',
	Data     =&gt; &quot;Body of messages goes here&quot;,
);

$emailMsg-&gt;attach(
	Type     =&gt; 'text/plain',
	Path     =&gt; 'filename.txt',
	Filename =&gt; 'filename.txt',
);

$emailMsg-&gt;send;
</pre>
<p><strong>Extract filename from path</strong><br />
<strong>Embed perl in bat file</strong><br />
<strong>Going through XML nodes</strong><br />
<strong>Call function through variable</strong><br />
<strong>Perform HTTP Request</strong><br />
<strong>Get Options</strong><br />
<strong>Run EXE</strong><br />
<strong>PerlLib</strong><br />
<strong>Extract zip to dir</strong><br />
<strong>Check error log for compilation errors</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/perl-cheatsheet-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CMD Cheatsheet</title>
		<link>http://blog.codaxe.com/2011/03/cmd-cheatsheet/</link>
		<comments>http://blog.codaxe.com/2011/03/cmd-cheatsheet/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 03:11:02 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Cheatsheets]]></category>
		<category><![CDATA[cmd cheatsheet]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=52</guid>
		<description><![CDATA[List all shared drives and folder they link to Delete directory and its subdirectories Map a drive letter to a path Remove a mapped drive letter Kill running task]]></description>
			<content:encoded><![CDATA[<p><span id="more-52"></span></p>
<p><strong>List all shared drives and folder they link to</strong></p>
<pre class="brush: bash; title: ; notranslate">wmic share get caption,name,path</pre>
<p><strong>Delete directory and its subdirectories</strong></p>
<pre class="brush: bash; title: ; notranslate">
REM (/S removes all files and directory and parent directory itself)
rmdir C:\codaxedir /S
REM (/Q quiet mode, don't ask if ok to remove directory tree)
rmdir c:\roxdevo /Q/S
REM or (shows files as they are deleted)
DEL /F /Q /S C:\codaxedir\*.*
</pre>
<p><strong>Map a drive letter to a path</strong></p>
<pre class="brush: bash; title: ; notranslate">
subst X: C:\codaxedir
</pre>
<p><strong>Remove a mapped drive letter</strong></p>
<pre class="brush: bash; title: ; notranslate">
subst /D X:
</pre>
<p><strong>Kill running task</strong></p>
<pre class="brush: bash; title: ; notranslate">
REM To view the list of running tasks:
tasklist
REM To kill a task:
taskkill /f /im /codaxe.exe
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/cmd-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Cheatsheet</title>
		<link>http://blog.codaxe.com/2011/03/shell-cheatsheet/</link>
		<comments>http://blog.codaxe.com/2011/03/shell-cheatsheet/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 03:10:43 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Cheatsheets]]></category>
		<category><![CDATA[shell cheatsheet]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=50</guid>
		<description><![CDATA[Change default editor Get ID of window Check if a process is already running Get current directory Check if file exists Check if directory eixsts In your bash script, set automatic non zero exit on error Run command over ssh without keeping connection open Converting scripts or files to proper unix equivalent (remove \r) Go [...]]]></description>
			<content:encoded><![CDATA[<p><span id="more-50"></span></p>
<p><strong>Change default editor</strong></p>
<pre class="brush: bash; title: ; notranslate">
sudo rc-update-alternatives --config editor
</pre>
<p><strong>Get ID of window</strong></p>
<pre class="brush: bash; title: ; notranslate">
pidgin_pid=`pgrep -x pidgin`
echo &quot;pidgin is running with PID $pidgin_pid&quot;

pidgin_window_id=`wmctrl -l -p | awk '{print $1, $3}' | grep &quot; $pidgin_pid&quot;`
echo &quot;pidgin is using window $pidgin_window_id&quot;
</pre>
<p><strong>Check if a process is already running</strong></p>
<pre class="brush: bash; title: ; notranslate">
pidgin_count=`pgrep -c -x pigin`
if [ &quot;$pidgin_count&quot; -ne 0 ]; then
    echo &quot;the app is already running.&quot; 1&gt;&amp;2
    echo &quot;Please close it before executing this command.&quot; 1&gt;&amp;2
    exit 1
fi
</pre>
<p><strong>Get current directory</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ pwd
</pre>
<p><strong>Check if file exists</strong></p>
<pre class="brush: bash; title: ; notranslate">
if [! -d &quot;/path&quot;]; then

fi
</pre>
<p><strong>Check if directory eixsts</strong></p>
<pre class="brush: bash; title: ; notranslate">
if [! -f &quot;/path&quot;]; then

fi
</pre>
<p><strong>In your bash script, set automatic non zero exit on error</strong></p>
<pre class="brush: bash; title: ; notranslate">
set -e
</pre>
<p><strong>Run command over ssh without keeping connection open</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ `ssh DX@192.168.1.110 'ls ~/'`
</pre>
<p><strong>Converting scripts or files to proper unix equivalent (remove \r)</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ dos2unix filename
</pre>
<p><strong>Go to previous directory</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ cd -
</pre>
</pre>
<p><strong>Get stack trace information from core dump file</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ gdb /usr/bin/myapp.binary coredumpfile
(gdb) bt
(gdb) bt full
(gdb) info threads
(gdb) thread apply all bt
(gdb) thread apply all bt full
</pre>
<p><strong>Save file permissions to file then restore</strong></p>
<pre class="brush: bash; title: ; notranslate">
# save file permission
$ getfacl -R dirname &gt; filname.perm
# restore file permission
$ setfacl --restore=filname.perm
#this is useful for instance if you are using svn which resets your file permissions
</pre>
<p><strong>Get list of modules loaded</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ module list
</pre>
<p><strong>View and save output to file at the same time</strong></p>
<pre class="brush: bash; title: ; notranslate">
# redirect in correct order
$ ./script.sh 2&gt;&amp;1 | tee mylog.log

# all error output followed by all normal output
$ ./script.sh | tee mylog.log 2&gt;&amp;1

# logs all normal and error output in correct order
$ ./script.sh &gt; mylog.log 2&gt;&amp;1

# log only normal output and display only error output
$ (./script.sh &gt; mylog.log) 2&gt;&amp;1

# log only normal output and display only error output
$ ./script.sh 2&gt;&amp;1 &gt; mylog.log

# log normal and error output in correct order but display nothing
$ (./script.sh 2&gt;&amp;1) &gt; mylog.log
</pre>
<p><strong>Concatenate string and variable in shell script</strong></p>
<pre class="brush: bash; title: ; notranslate">
MY_VARIABLE=&quot;myvalue&quot;
MY_SECOND_VARIABLE=${MY_VARIABLE}/add_text
</pre>
<p><strong>Forward system mails received</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ echo &quot;forwardtothisemail@email.com&quot; &gt; $HOME/.forward
$ chmod 644 $HOME/.forward
</pre>
<p><strong>Get PID of running process</strong></p>
<pre class="brush: bash; title: ; notranslate">
# (this might look through all processes for any user)
$ ps -ef | grep processname | grep -v grep | sed -e 's%^[a-z][a-z]*  *%%' -es% .*$%%'
# (to get it for a specific user and process name)
$ pgrep -u mrassi -f processname
</pre>
<p><strong>List running processes and kill specific</strong></p>
<pre class="brush: bash; title: ; notranslate">(this might look through all processes for any user)
$ps -ux
$kill -9 pid
</pre>
<p><strong>Check if specific application is in your path</strong></p>
<pre class="brush: bash; title: ; notranslate">
$ which app
</pre>
<p><strong>Add home library path to your environment</strong></p>
<pre class="brush: bash; title: ; notranslate">
# add line: export LD_LIBRARY_PATH=$(HOME)/lib to below file in the export section
$ vi ~/.env/user.bashrc
</pre>
<p><strong>Set permissions for all files in directory </strong></p>
<pre class="brush: bash; title: ; notranslate">
find /path/to/dir/ -type f -exec chmod 644 {} \;
</pre>
<p><strong>Find file</strong></p>
<pre class="brush: bash; title: ; notranslate">
# Find file with name myFilename.txt  starting from current directory down
$ find -name &quot;myFilename.txt&quot;

# Find any file with txt extension
$ find -name &quot;*.txt&quot;

# Find fileName with any extension
$ find -name &quot;fileName.*&quot;

# Find myFilename.txt starting in /home/mrassi
$ find /home/mrassi -name &quot;myFilename.txt&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/shell-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET C# Cheatsheet</title>
		<link>http://blog.codaxe.com/2011/03/net-c-cheatsheet/</link>
		<comments>http://blog.codaxe.com/2011/03/net-c-cheatsheet/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 03:10:21 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Cheatsheets]]></category>
		<category><![CDATA[.net c# cheatsheet]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=48</guid>
		<description><![CDATA[Retrieve data from Web.config .NET Retrieval Code Retrieve Host (must be within class deriving System.Web.UI.Page) Get name of user under which .net executes Create directory, delete it first if it already exists Save Image from post request (must be within class deriving System.Web.UI.Page) Return answer to request LDAP &#8211; Retrieve email from username Load string [...]]]></description>
			<content:encoded><![CDATA[<p><span id="more-48"></span></p>
<p><strong>Retrieve data from Web.config</strong></p>
<pre class="brush: csharp; title: ; notranslate">
</pre>
<p><strong>.NET Retrieval Code</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private string retrieveConfig(string inKey)
{
	if(ConfigurationSettings.AppSettings[inKey] != null)
		return ConfigurationSettings.AppSettings[&quot;inKey&quot;];
	else
		return &quot;Invalid key&quot;;
}
</pre>
<p><strong>Retrieve Host (must be within class deriving System.Web.UI.Page)</strong></p>
<pre class="brush: csharp; title: ; notranslate">
string host = Request.Url.Host.ToString();
</pre>
<p><strong>Get name of user under which .net executes</strong></p>
<pre class="brush: csharp; title: ; notranslate">
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
</pre>
<p><strong>Create directory, delete it first if it already exists</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private string createDirOW(string inPath)
{
	try {
		if (Directory.Exists(inPath))
			Directory.Delete(inPath, true);

		if (!Directory.Exists(inPath))
			createDirectory(inPath);
	}
	catch (Exception ex) { };
}
</pre>
<p><strong>Save Image from post request (must be within class deriving System.Web.UI.Page)</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private string saveImagePost(string destPath, string destFileName)
{
	if (Request.Files.Count &gt; 0) {
		HttpPostedFile httpPostedFile = Request.Files[0];
		try {
			httpPostedFile.SaveAs(destPath + destFileName);
		}
		catch (Exception ex) {
			return &quot;ERROR: Could not save file.&quot;
		}
	}
	else
		return &quot;ERROR: No files attached to request.&quot;;

	return &quot;SUCCESS: File was saved&quot;;
}
}
</pre>
<p><strong>Return answer to request</strong></p>
<pre class="brush: csharp; title: ; notranslate">
// use &quot;text/plain&quot; for contextType
public void returnHTTPContext(string outDataString, string contextType)
{
	// Prevent browser from caching answer
	Response.Expires = 0;
	Response.Cache.SetNoStore();
	Response.AppendHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);

	Response.ContentType = contextType;
	Response.Clear();
	Response.Write(outDataString);
	HttpContext.Current.ApplicationInstance.CompleteRequest();
}
</pre>
<p><strong>LDAP &#8211; Retrieve email from username</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private string getLDAPAttr(string inUser, string inPasword, string fetchAttr)
{
	string username = inUser;
	string password = inPasword;
	string ldapHost = &quot;10.10.10.10&quot;;
	string ldapDomain = &quot;DC=MYDOMAIN,DC=MYDOMAIN2,DC=MYDOMAIN3&quot;;

	try {
		string domainPath = &quot;LDAP://&quot; + ldapDomain + &quot;/&quot; + ldapDomain;
		DirectoryEntry searchRoot = new DirectoryEntry(domainPath, username, password);
		DirectorySearcher search = new DirectorySearcher(searchRoot);
		search.PropertiesToLoad.Add(fetchAttr);
		search.Filter = &quot;(&amp;amp;(anr=&quot; + username + &quot;)(objectCategory=person))&quot;;

		SearchResultCollection resultCol = search.FindOne();
		string currEmail = resultCol.Properties[fetchAttr][0].ToString();

		return &quot;ERROR: No emails found for user: &quot; + username;
	}
	catch (Exception ex) {
		return &quot;ERROR: Authentification problem&quot;;
	}
}
</pre>
<p><strong>Load string of XML to XmlDocument</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private XmlDocument strXMLtoXMLDoc(string inXML)
{
	XmlDocument xmlDoc = new XmlDocument();
	try {
		System.IO.MemoryStream memStream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(inXML));
		StreamReader stremReader = new StreamReader(memStream);

		xmlDoc = new XmlDocument();
		xmlDoc.LoadXml(stremReader.ReadToEnd());
	}
	catch { return new XmlDocument(); }

	return xmlDoc ;
}
</pre>
<p><strong>Remove XMLNode from XmlDocument</strong></p>
<pre class="brush: csharp; title: ; notranslate">
// this will remove the node under /test/subnode/subsub/  from xmlDoc
removeChildFromXMLDoc(&quot;/test/subnode/subsub/node[@&quot;, &quot;ID&quot;, &quot;myValue&quot;, ref xmlDoc);

private void removeChildFromXMLDoc(string prePath, string idName, string idValue, ref inXmlDoc)
{
	String xpathExpr = prePath+idName+&quot;='&quot;+idValue+&quot;']&quot;;
	XmlNodeList xmlNodes = inDoc.SelectNodes(xpathExpr);
	for (int i = 0; i &amp;lt; xmlNodes.Count; i++)
		xmlNodes[ i ].ParentNode.RemoveChild(xmlNodes[ i ]);
}
</pre>
<p><strong>Remove element from string array</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public string[] removeFromStrArr(string inTarget, string[] inArr)
{
	string[] newArr = { &quot;&quot; };
	ArrayList myList = new ArrayList();
	for (int i = 0; i &amp;lt; inArr.Length; i++) {
		if (!inArr[ i ].Contains(inTarget))
		myList.Add(inArr[ i ]);
	}

	return myList.ToArray(typeof(string)) as string[];
}
</pre>
<p><strong>Start a new process</strong></p>
<pre class="brush: csharp; title: ; notranslate">
// note i've had issues getting this working with .bat files, the only way it worked was if you set the RedirectStandard Output and Error to false
private string startProcess(string appPath, string appArg)
{
	string appStdOutput = &quot;&quot;;
	string appErrOutput = &quot;&quot;;

	try {
		Process myProcess = null;
		myProcess = new Process();

		ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(&quot;\&quot;&quot; + appPath + &quot;\&quot;&quot;);
		myProcessStartInfo.Arguments = appArg;
		myProcessStartInfo.UseShellExecute = false;
		myProcessStartInfo.RedirectStandardOutput = true;
		myProcessStartInfo.RedirectStandardError = true;
		myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
		myProcessStartInfo.CreateNoWindow = true;
		myProcess.StartInfo = myProcessStartInfo;
		myProcess.Start();
		appStdOutput = myProcess.StandardOutput.ReadToEnd();
		appErrOutput = myProcess.StandardError.ReadToEnd();
		myProcess.WaitForExit();

		if (appErrOutput != &quot;&quot;)
			return &quot;ERROR: &quot; + appErrOutput;

		myProcess.StartInfo.RedirectStandardOutput = false;
		myProcess.StartInfo.RedirectStandardError = false;
		myProcess.StandardOutput.Close();
		myProcess.Close();

		return appStdOutput;
	}
	catch (Exception ex) {  }
}
</pre>
<p><strong>Get file content to string</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private string getFileContents(string FileName)
{
	StreamReader streamR = null;
	string FileContents = null;
	try {
		FileStream fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
		streamR = new StreamReader(fileStream, true); FileContents = streamR.ReadToEnd();
	}
	catch(Exception ex) {
		return &quot;&quot;;
	}
	finally {
		if (sr != null) sr.Close();
	}

	return FileContents;
}
</pre>
<p><strong>Save string to file</strong></p>
<pre class="brush: csharp; title: ; notranslate">
private void saveToFile(string strInput, string inFileName, bool appendYN)
{
	try {
		using (StreamWriter stremWr = new StreamWriter(inFileName, appendYN, Encoding.Default)) {
			stremWr.Write(strInput);
			stremWr.Flush();
			stremWr.Close();
		}
	}
	catch (Exception e) {  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/net-c-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 2.0.1 Undefined property core/Model.php</title>
		<link>http://blog.codaxe.com/2011/03/codeigniter-2-0-1-giving-message-undefined-property-coremodel-php/</link>
		<comments>http://blog.codaxe.com/2011/03/codeigniter-2-0-1-giving-message-undefined-property-coremodel-php/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 02:55:21 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code igniter error undefined]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=42</guid>
		<description><![CDATA[If you upgraded to CodeIgniter 2.0.1 from 1.7.2 you might encounter on some pages the following error: This is easily fixed by editing the Model.php file in the system directory. Edit system &#62; core &#62; Model.php FROM: TO: The fix can be found here: https://bitbucket.org/ellislab/codeigniter/issue/252/undefined-method-error-produced-when-using ﻿]]></description>
			<content:encoded><![CDATA[<p>If you upgraded to CodeIgniter 2.0.1 from 1.7.2 you might encounter on some pages the following error:</p>
<pre class="brush: php; title: ; notranslate">
A PHP Error was encountered
Severity: NoticeMessage: Undefined property: MyStats::$db
Filename: core/Model.php
Line Number: 50
</pre>
<p>This is easily fixed by editing the Model.php file in the system directory.</p>
<p><span id="more-42"></span></p>
<p>Edit<strong> system &gt; core &gt; Model.php</strong></p>
<p>FROM:</p>
<pre class="brush: php; title: ; notranslate">
$key;
    }
?&gt;
</pre>
<p>TO:</p>
<pre class="brush: php; title: ; notranslate">
$key)) {
            return $CI-&gt;$key;
        }
    }
?&gt;
</pre>
<p>The fix can be found here: https://bitbucket.org/ellislab/codeigniter/issue/252/undefined-method-error-produced-when-using<br />
﻿</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/codeigniter-2-0-1-giving-message-undefined-property-coremodel-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form not submitted when pressing enter in input box</title>
		<link>http://blog.codaxe.com/2011/03/form-not-submitted-when-pressing-enter-in-input-box/</link>
		<comments>http://blog.codaxe.com/2011/03/form-not-submitted-when-pressing-enter-in-input-box/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 05:44:31 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[submit]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=23</guid>
		<description><![CDATA[To keep things clean it&#8217;s a great idea to make a common button style that can be reused across your site. But already there is a problem if you try to style an html submit button, that styled button can only be used within an html form which might not fit all your scenarios. Therefore [...]]]></description>
			<content:encoded><![CDATA[<p>To keep things clean it&#8217;s a great idea to make a common button style that can be reused across your site. But already there is a problem if you try to style an html submit button, that styled button can only be used within an html form which might not fit all your scenarios.</p>
<p>Therefore a common way around that is to instead style an anchor tag  which can be used in any context. Although this is great for style reuse  it creates problems such as the default html form submit behavior to  dissapear and the need of some extra javascript actions to submit the form action. Such behavior as hitting enter from an input box usually  submits the form but if no submit button is present in the form it won&#8217;t  get submitted.</p>
<p><a href="../wp-content/uploads/2011/03/style_btn.jpg"><img title="style_btn" src="../wp-content/uploads/2011/03/style_btn-150x39.jpg" alt="" width="150" height="39" /></a></p>
<p>&nbsp;</p>
<p><span id="more-23"></span>For instance it&#8217;s common to remove the submit button <strong> </strong></p>
<p><strong>&lt;input type=&#8221;submit&#8221; value=&#8221;Submit&#8221; /&gt;. </strong>To replace it with a fancy CSS styled anchor tag <strong>&lt;a href=&#8221;" /&gt;</strong></p>
<p><strong>From:</strong></p>
<blockquote><p>&lt;form name=&#8221;myForm&#8221;      action=&#8221;form_action.asp&#8221;     method=&#8221;get&#8221;&gt;<br />
First name: &lt;input type=&#8221;text&#8221; name=&#8221;fname&#8221;      /&gt;&lt;br /&gt;<br />
Last name:      &lt;input type=&#8221;text&#8221; name=&#8221;lname&#8221;      /&gt;&lt;br /&gt;<br />
<strong>&lt;input type=&#8221;submit&#8221; value=&#8221;Submit&#8221; /&gt;</strong><br />
&lt;/form&gt;</p></blockquote>
<p><strong>To:</strong></p>
<blockquote><p>&lt;form      name=&#8221;myForm&#8221; action=&#8221;form_action.asp&#8221;     method=&#8221;get&#8221;&gt;<br />
First name: &lt;input type=&#8221;text&#8221; name=&#8221;fname&#8221;      /&gt;&lt;br /&gt;<br />
Last name:      &lt;input type=&#8221;text&#8221; name=&#8221;lname&#8221;      /&gt;&lt;br /&gt;<br />
<strong>&lt;a href=&#8221;#&#8221; onClick=&#8221;document['myForm'].submit();&#8221;  class=&#8221;myStyle&#8221;&gt;</strong><br />
&lt;/form&gt;</p>
<p>&nbsp;</p></blockquote>
<p><strong>Solution:</strong></p>
<p>The solution is to add an invisible and collapsed submit button to bring back this behavior:</p>
<blockquote><p>&lt;form name=&#8221;myForm&#8221; action=&#8221;form_action.asp&#8221; method=&#8221;get&#8221;&gt;<br />
First name: &lt;input type=&#8221;text&#8221; name=&#8221;fname&#8221; /&gt;&lt;br /&gt;<br />
Last name: &lt;input type=&#8221;text&#8221; name=&#8221;lname&#8221; /&gt;&lt;br /&gt;<br />
<strong>&lt;input type=&#8221;submit&#8221; style=&#8221;display:none; height:0px; width:0px; border:0px;&#8221;&gt;</strong><br />
<strong> &lt;a href=&#8221;#&#8221; onClick=&#8221;document['myForm'].submit();&#8221; </strong><strong> </strong><strong>class=&#8221;myStyle&#8221;</strong><strong>&gt;</strong><br />
&lt;/form&gt;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/form-not-submitted-when-pressing-enter-in-input-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making an image seamlessly title in both x and y axis</title>
		<link>http://blog.codaxe.com/2011/03/making-a-picture-seamlessly-repeat-in-both-x-and-y-axis/</link>
		<comments>http://blog.codaxe.com/2011/03/making-a-picture-seamlessly-repeat-in-both-x-and-y-axis/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 05:19:03 +0000</pubDate>
		<dc:creator>codaxe</dc:creator>
				<category><![CDATA[GFX]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[repeat]]></category>
		<category><![CDATA[seamless]]></category>
		<category><![CDATA[tile]]></category>
		<category><![CDATA[x-axis]]></category>
		<category><![CDATA[y-axis]]></category>

		<guid isPermaLink="false">http://blog.codaxe.com/?p=8</guid>
		<description><![CDATA[When web designing it is quite common to require a picture to seamlessly tile in the x or y direction. The CSS feature repeat-x repeat-y could then be used on such image. This would allow for instance to have a reasonably small background image fill the entire background of the browser region as it repeats [...]]]></description>
			<content:encoded><![CDATA[<p>When web designing it is quite common to require a picture to seamlessly tile in the x or y direction. The CSS feature repeat-x repeat-y could then be used on such image. This would allow for instance to have a reasonably small background image fill the entire background of the browser region as it repeats with no apparent seam.</p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/tile-x.jpg"><img class="alignnone size-thumbnail wp-image-9" title="tile-x" src="http://blog.codaxe.com/wp-content/uploads/2011/03/tile-x-150x150.jpg" alt="" width="230" height="105" /></a> to <a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p1b.jpg"><img class="alignnone size-thumbnail wp-image-17" title="p1b" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p1b-150x150.jpg" alt="" width="215" height="104" /></a></p>
<p>This is easily achieved with the Adobe Photoshop Offset Feature.</p>
<p><span id="more-8"></span></p>
<p>1. Open your image in photoshop then go to <strong> Image &#8211;&gt; Image Size</strong> and note down the height and width of your image. If your dimensions do not come out even try to edit your original image to make it so by going to <strong>Image &gt; Canvas Size </strong>and then for example using the <strong>CTRL+T</strong> tool on your image to accommodate the extra space (if you increased the canvas size instead of reducing it)<strong>.<br />
</strong></p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p1a.jpg"><img class="alignnone size-thumbnail wp-image-10" title="p1a" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p1a-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>2. Then go to<strong> Filter &#8211;&gt; Other &#8211;&gt; Offset </strong></p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p2.jpg"><img class="alignnone size-thumbnail wp-image-11" title="p2" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p2-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>3. For the height and width dimensions enter half of the original width and height you found in step 1. You should see 4 equal square outlines.</p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p4.jpg"><img class="alignnone size-thumbnail wp-image-12" title="p4" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p4-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>4. Now start using common photoshop tools to make all seams dissapear between the 4 sections. Use tools such as &#8220;Clone Stamp Tool&#8221;, &#8220;Smudge Tool&#8221;, &#8220;Spot Heal Brush&#8221;. The &#8220;Spot Heal Brush&#8221; usually does a pretty nice job without much effort, just click and drag along the tile and fix any inconsistencies. One thing to be careful is to only work on the seam within the overall picture but not modify any of the sides of the overall image. In this screen shot below you can see that this would actually modify a bit of the top side of the overall image and could possibly create visible tiling problems.</p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p5.jpg"><img class="alignnone size-thumbnail wp-image-13" title="p5" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p5-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>5. Once you&#8217;ve fixed all the seams repeat the process of the offset <strong>Filter &#8211;&gt; Other &#8211;&gt; Offset. </strong></p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p21.jpg"><img class="alignnone size-thumbnail wp-image-14" title="p2" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p21-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>6.  You&#8217;re done, your final image should now tile seamlessly.</p>
<p><a href="http://blog.codaxe.com/wp-content/uploads/2011/03/p61.jpg"><img class="alignnone size-thumbnail wp-image-16" title="p6" src="http://blog.codaxe.com/wp-content/uploads/2011/03/p61-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p><em>note: photoshop cs5</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codaxe.com/2011/03/making-a-picture-seamlessly-repeat-in-both-x-and-y-axis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

