Archive for the ‘Uncategorized’ Category

atime, mtime, and ctime

7. March 2010

No Comments »

On traditional Unix-style file systems three timestamps are associated with each file. These timestamps are atime, ctime, and mtime. Most people understand atime as “access time.” A file is accessed when its content is viewed or is executed. ctime and mtime generate confusion since “change time” and “modification time” seem synonymous. However, what you need to focus on is what is being changed. The mtime value is updated when the actual contents of the file are changed. However, updating mtime, also updates ctime. This does not mean an update to ctime will cause an update to mtime. The ctime value is updated when the files inode or change to the files content are made. For example:

# cat foo
Hello, World

Will update the files atime, but it will not effect the ctime or mtime.

# chmod 777 foo

Will update the files ctime but not the files atime or mtime.

# echo “Goodbye, World!” > foo

Will update the files ctime and mtime but not the files atime.

SEF URLs with out mod_rewrite

29. November 2009

3 Comments »

If you have done any web development, passing requests becomes an integral part of your code. Whether it is a session id, data to validate, or a view file to load you will most definitely end up passing one request or another. While working on my framework (which uses the model-view-controller design pattern), I decided to pass the controller, which the framework will load, through the URL. Since the controller’s primary purpose is to handle incoming http requests, I also passed a “view” parameter through the URL (which the controller will delegate accordingly). At this point, my URLs became unattractive index.php?module=Blog&view=index, which in todays world, of Web 2.0 sex appeal and search engine optimization, is just unacceptable. To circumvent the unsightly link, many developers choose to use mod_rewrite and define expressions in a .htaccess file. This is a perfectly legitimate practice for those of you who have mod_rewrite enabled on their server (and actually understand the rules). As an alternative, PHP’s $_SERVER['REQUEST_URI'] provides a cleaver solution.

What does $_SERVER['REQUEST_URI'] provide us with? Essentially, everything after the domain name. So if our URL is http://www.example.com/index.php?module=Blog&view=index, our URI is index.php?module=Blog&view=index. Moreover, if our URL is http://www.example.com/index.php/Blog/index, our URI is index.php/Blog/index. Using this, we can simply manipulate the URI to process incoming requests. First, we want to explode the URI at the file name, in my case it is index.php.

[code]$requests = explode("/index.php/", $_SERVER['REQUEST_URI']);[/code]

$request is now an array whose first element is everything before and including index.php, and whose second element is everything after index.php. By manipulating $requests[1] we can use that data as our data.

[code]$requests = explode("/index.php/", $_SERVER['REQUEST_URI']);
$uri = explode('/', $requests[1]);[/code]

The $uri array now contains all our disguised requests, which we can use in the same way as a $_GET request (with the exception of a sexier URL).

With three lines of code we have transformed a ugly looking URL http://www.example.com/index.php?module=Blog&view=index to http://www.example.com/index.php/Blog/index (a URL the most avid Web 2.0 gurus would find acceptable).

The Laplace Transform

27. November 2009

No Comments »

Pierre-Simon De Laplace (23 March 1749 – 5 March 1827) was a French mathematician and astronomer. In 1796 he formulated a nebular hypothesis of cosmic origin and was one of the first scientists to postulate the existence of black holes. He later proposed a solution to irregularities in Newton’s calculations and presented them in a work called Mécanique céleste. According to legend, when asked by Napoleon why God did not appear in his discussion, Laplace replied “I had no need of that hypothesis.” Among many discoveries, Laplace is most notable for the Laplace Transform which aids in solving differential equations by allowing for the transformation of an equation from the time domain to the frequency domain.

For a signal x(t), its Laplace transform X(s) is defined by
\mathrm{X(s)=}\int\limits_{-\infty}^{\infty}\mathrm{x(t)}e^{-st}dt

Example: For a signal x(t) = e-atu(t) find the Laplace transform X(s).

By definition
\mathrm{X(s)=}\int\limits_{-\infty}^{\infty}e^{-at}u(t)e^{-st}dt

Since u(t) = 0 for t < 0 and u(t) = 1 for t ≥ 0,
\mathrm{X(s)=}\int\limits_{0}^{\infty}e^{-at}e^{-st}dt = \mathrm{X(s)=}\int\limits_{0}^{\infty}e^{-(s+a)t}dt = -\frac{1}{s+1}e^{-(s+a)t}\big|_{0}^{\infty}

Thus we can conclude
\mathrm{X(s)=}\frac{1}{s + a} \mathrm{for Re(s + a) > 0}