Here’s a quick way of configuring your (Linux-based) Git installation to use the excellent Meld program by default for displaying/editing the outputs of the git diff and git merge commands (e.g. git diff «filename»). Install Meld …if you haven’t already (note that we assume Git to be present): # on Debian-based distros (ymmv) sudo apt-get install meld Viewing/editing file diffs via Meld Configure Git to use Meld as the default
Continue readingCategory: Command line tools
Command-line option parser in JavaScript.
Here’s a small but very effective command-line option parser written in JavaScript (uses NodeJs). You can get the up-to-date source code at http://gist.github.com/982499. I wrote this because I needed it for a project and I did not think it was worth it to install some npm package just for this. The comment should explain most things you will need but ask me if you don’t understand something. Note that this
Continue readingLua2C, an updated version
I know I have been “missing in action” lately but I am working furiously, and I seem to have too little time for my blog (very sad face). But, just for a breath of fresh air, I thought I’d share something with the world. Entering lua2c.lua Lately I became quite interested in Lua (a lot actually). It has phenomenal speed, exceptional interfacing with C and some features and libraries that
Continue readingURI parsing using Bash built-in features
A bit of background A while ago I posted an article describing how one could parse complete URIs in Bash using the sed program. Since then, I have realized that there is a better way to do it, a much better way: via Bash built-in pattern matching! Here are some benefits of this improvement: It no longer executes external programs (i.e. sed) for pattern matching. This translates to higher speed
Continue readingRecursive chmod distinguishing files from folders
Version 3 An even better method is: find “$target” -type f -exec chmod -c “$mode_files” {} \; \ -or -type d -exec chmod -c “$mode_dir” {} \; A true one-liner! 😀 Version 2 A better method is this: find “$target” -type f -exec chmod -c “$mode_files” {} \; find “$target” -type d -exec chmod -c “$mode_dir” {} \; This one can also be used from the command line. Version 1
Continue readingBash URI parser using SED
Warning! This version is now obsolete! Check out the new and improved version (using only Bash built-ins) here! Here is a command-line (bash) script that uses sed to split the segments of an URI into usable variables. It also validates the given URI since malformed strings produce the text “ERROR” which can be handled accordingly: # Assembling a sample URI (including an injection attack) uri_1=’http://user:pass@www.example.com:19741/dir1/dir2/file.php’ uri_2=’?param=some_value&array[0]=123¶m2=\`cat /etc/passwd\`’ uri_3=’#bottom-left’ uri=”$uri_1$uri_2$uri_3″ #
Continue readingRecursive file/directory change-detection
Disclaimer This article explores a way in which an approximate “fingerprint” of a file tree can be created! If all you want is to detect file changes a much more appropriate method would be to use inotify/incron. Version 2 (update) Another, much faster method would be to use ls -lR to browse over the filesystem. On a newly installed Debian virtual machine (on Xen) hashing the entire filesystem (the root
Continue readingDetect number of CPUs on a machine
UPDATE: Steven pointed out (very nicely) that there’s no need for cat in this picture, grep would do just fine on its own. So, thanks Steven! Detect how many CPU cores are present on the running machine: grep -c processor /proc/cpuinfo This can be very useful when writing multi-threaded programs to properly match the number of threads with the number of CPU cores.
Continue reading