azmfaridee / blog

Collection of Random Tips and Code Snippets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recent Posts

Mac OSX Alternative of Linux IPTraf (2013-06-25)

While working in Linux, I tend to use the software iptraf to monitor network speed. In Mac OSX, of course that software is not available, even in macports or homebrew. But there is an alternative, it's called iftop.

If you have macports you can install that with:

sudo port -v install iptop

After installing the software, you can monitor your specific interface with it. Assume that en1 is your Wifi card's designator. Then you should run this command:

sudo iftop -i en1

The software's interface is not as pretty as iptraf, but it does the job for me :)

Cleaning up Unnecessary Files of Macports (2013-06-25)

Macports need cleanup of it's old downloaded and installed ports from time to time. Today morning I checked my macports folder and found out that it's taking a whooping 9.1 Gigabytes of space in my hard drive.

$ du -sh /opt
9.1G	/opt

I ran these two commands to clean up the mess.

sudo port clean --all installed
sudo port -f uninstall inactive

After running the commands, here is the result.

$ du -sh /opt
6.2G	/opt

Almost 3 Gigabytes saved. Not bad, huh?

Use Vim as a Pager with Syntax Highlighting (2013-06-24)

This tip will use Vim as a pager instead of more or less command that we use normally. The benefit is that, you can have syntax highlighting that comes with Vim when you are using more or less commands from the shell.

If you are using macports, run the command:

sudo port -v install vimpager

Then add these lines into your .bashrc file

export PAGER=vimpager
alias less=$PAGER
alias zless=$PAGER

Done

Get Public IP From Command Line (2013-06-24)

Use this code snippet to find out public ip from your command line whenever you are trying to do it in bash scripts:

curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+' 

This also works:

curl ifconfig.me

Tips For Easy JS Debug in Netbeans (2013-06-23)

If you love (or have to) code in Netbeans and in JavaScript, here is a nice tip for instantly dumping (and pretty print) a variable in browser console (and save some keystrokes).

Create a macro in Netbeans and assign a keyboard shortcut like Ctrl+Alt+D to that macro.

select-identifier copy-to-clipboard caret-end-line insert-break 
"console.log(\"" paste-from-clipboard " = \" 
+ JSON.stringify(" paste-from-clipboard ", null, 2));"

Next time you cursor is on top a JS variable, just press the shortcut key, a line like following will be automatically inserted after the line you are working on:

console.log(JSON.stringify(myVariable, null, 2));

Github Powered Blogging Experiment with Automaic TOC Generation (2013-06-23)

Hey Guys,

I've been experimenting with the idea of writhing down my code snippets and other stuffs as a micro-blog for a while. I used to write a blog in blogspot but these days I don't find writing there very entertaining, since they redesigned the whole system (I'm a bit old fashioned :( ).

Like everyone else I've been a fan of Github Wikis and Markdown, so I thought why not give this a try. Github's code highlight and markdown syntax is all I need for a programming centric blog, I don't need any fancy CSS and whatever, do I?

But maintaining an index all by yourself would be really painful (as you keep adding more and more blog posts), so I did two things for that.

  • Maintained a very easy folder structure so that the folders can be sorted lexicographically without much regex parsing, the name of the file is also used to create the label in the index, so there is a simple naming convention.
  • Created as simple shell script as pre-commit git-hook that automatically updates the homepage (README.md file) with two most recent posts and a table of contents.

To install the pre-commit hook, just copy it to the hooks folder.

$ cp pre-commit-hook.sh .git/hooks/pre-commit 

So far it's looking good. In fact if you are reading this post from the homepage, then it's generated by the pre-commit hook :). I'm going to update the scripts incrementally with more and more features if I manage to get some free time. As as proof-of-concept as of now, it works, that's the good part :)

Table of Contents

About

Collection of Random Tips and Code Snippets


Languages

Language:Shell 100.0%