Category: Code

Using Git – the Basic Commands

Initialize a New Project in Git… git init git add . git commit #Add a file git add file.php git…

Remove empty directories

Remove all empty directories within the current directory find . -type d -empty -exec rmdir {} \; perl -MFile::Find -e”finddepth(sub{rmdir},’.’)”…

Scope and Binding in JavaScript

Function x executions in the scope of object y. var Car = function() { this.name = ‘car’; } var Truck…

Adding a Windows Entry to Grub

The code to add a Windows loading section in Grub title Windows rootnoverify (hd0,1) chainloader +1 [tags]grub,windows,linux,boot,loader[/tags]

Dynamic/Static/Strong/Weak Types

A dynamically typed language is a language where the type of a variable can be altered at any time. (It…

Replace \n with another String

The command to convert all \n in a file to another string – very useful for list code generation. perl…

Remove Extension in Shell Scripting

This command will list all the files a folder without their extensions. Comes handy when doing shell scripting perl -e…

HTTP Digest Authentication with PHP

The code for using HTTP Digest Authentication with PHP. <?php realm = ‘Restricted area’; if (empty(_SERVER[‘PHP_AUTH_DIGEST’])) { header(‘HTTP/1.1 401 Unauthorized’);…

Find Element’s Position using JavaScript

Find the position of an element using javascript function findPos(obj) { var curleft = curtop = 0; if (obj.offsetParent) {…

Searching text in a directory using find and grep

Use find and grep to search for a specific text in a directory. In this example, we search for files…