Saturday, January 8, 2011

Mac OSX Utils

1) To Change the hostname

 
sudo scutil --set HostName newhostname.local


2) Move windows between Spaces via drag Desktop
you can move a window from a space to another by just dragging the window to the limit of the screen. If you wait a few seconds, the window slides (and the screen also!) from the original space to the other one.

3) Page Up/Page Down,Home and End in MacBook

fn + Up Arrow = Page Up
fn + Down Arrow = Page Down
Command + fn + Left Arrow = Home
Command + fn + Down Arrow = End

4) Switching between workspaces

control + (up,left,down,right)

References
http://blog.psyrendust.com/2008/05/23/change-the-hostname-in-mac-os-x-osx/
http://hints.macworld.com/article.php?story=20071025140916203
http://www.mountainvistatech.com/2009/01/26/page-uppage-down-on-macbook-pro-and-vista/
http://pcmcourseware.com/blog/2009/02/23/home-and-end-keys-on-the-macbook-pro/

Tuesday, November 23, 2010

find command

To find all files modified in the last x days in the given directory(dirName) and its sub-directories:

find dirName -mtime -x -print


To find all files modified more than x days in the given directory(dirName) and its sub-directories:

find dirName -mtime +x -print


For finding only regular files(not the directories) use

find dirName -type f -mtime -x -print


For finding files by name we can use -type f

find dirName -type f -name 'filename'

filename can be regular expression like *.mp3
Case insensitive searches can be achieved by using the -iname flag instead of name

Further we can narrow down the searches by adding more filter like size and modified times
To find .avi files bigger than 700M and modified in the last 15 days:

find dirName -name '*.avi' -a -size +700M -mtime -15


References
http://www.debuntu.org/how-to-find-files-on-your-computer-with-find

Thursday, November 18, 2010

Difference between jsp:include and include directive

<jsp:include>

included jsp page will be compiled separately and the output will replace its position in the main jsp

<%@include% flie="header.jsp">
Contents of the header.jsp gets replaced in the main jsp even before the page compilation

Friday, November 12, 2010

Useful Linux Commands

pushd and popd
For easy directory traversal(good link)

bg, fg and jobs
To run the process in background, foreground and to see what are the current jobs running

file
Give the information about the file format

strings
Outputs all the readable characters in the given file

zgrep
Handy for searching the zip files

pgrep
Handy for searching the process list

pstree

The pstree command is another variation of the PS command. it gives a quick peek at the different programs that are running, and what processes stem from other processes

apropos
apropos is a very powerful command, as it knows every command you can use for a specific item.If you're looking for a certain command to run on, say, directories, but you can't quite remember what it's called, then running apropos dir will yield a list of possible commands.

touch
the touch command is for updating the access / modified date of a file; it’s just a nice side-effect that if the file doesn’t exist, it will create it.

curl
curl -O http://www.domain.com/path/to/download.tar.gz
The -O flag tells curl to write the downloaded content to a file with the same name as the remote file. If you don’t supply this parameter, curl will probably just display the file in the commmand line

patch
patch will be handy with diff

pgrep
pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria.

!!
This will execute the last command you used on the command line.

!...
Execute The Last Command Starting With ...

!ls:p
This will display the command instead of running it.


!$
You can use the last argument from the last command by refering to it as !$

!$:p
Instead of running the last word of the previous command this will print it out.

!*
This bang command will run the previous command without the first word. This one is also only really useful for substitutions as we see in the examples that follow.

!*:p
This will print the previous command without the first word.

$_
You can use the last argument from the last command by refering to it as $_

watch
watch runs a command repeatedly, displaying its output. This allows you to watch the program output change over time. By default, the program is run every 2 seconds. watch is very similar to tail.

Make Parent Directories the Smart Way
mkdir -p /home/adam/make/all/of/these/directories/ will create all directories as needed even if they do not exist.


Ctrl +
CTRL+U deletes whatever is to the left of the cursor and CTRL+K deletes what is to the right.
CTRL+C, which discards the current typed command, and gives you a new line.
CTRL+L will clear the screen.
CTRL+D logout of a terminal session


Resetting your session

Instead of killing and re-starting your terminal session, you can merely type the command reset. This will reset your terminal back to its defaults, clear the screen, and everything will be as it was before.

dmesg

wget
http://www.unixmen.com/linux-tutorials/484-wget-command-line-cheatsheet

lsof
Check for open file descriptors

Other Links
http://www.thegeekstuff.com/2010/11/50-linux-commands/
find command examples
http://blog.urfix.com/25-linux-commands/

Vi
http://www.catswhocode.com/blog/100-vim-commands-every-programmer-should-know
http://www.atoztoa.com/2008/07/effective-use-of-vim-part-1.html

References:-
http://laptoplogic.com/resources/ten-powerful-linux-commands
http://net.tutsplus.com/articles/web-roundups/10-terminal-commands-that-will-boost-your-productivity/
http://blogs.techrepublic.com.com/10things/?p=452
http://www.atoztoa.com/2008/06/linux-commands-i-hardly-knew.html
http://codytaylor.org/2009/09/linux-bang-commands.html
http://www.canoo.com/blog/2010/12/22/beginner-bash-must-know-bash-commands/

Wednesday, September 15, 2010

Javascript and CSS Presentation

I have prepared a presentation which covers javascript basics, functions, classes, closures, AJAX, Minification, CDN, CSS selectors, JSONP and best practices.

Below is the link

https://dl.dropbox.com/u/4970006/blog/static/presentations/webapps.html

Demos are also part of the presentation.
When you run the demos, a div will popup, click on the same div to hide it.

Use up and down arrows with browser maximized.

Friday, September 10, 2010

Remove ^M (Ctrl-M) character from the end of file

Sometimes you see ^M character at the end of the file, when you copy the file from windows.
Use below command in vi editor to remove them


:%s/^V^M//g


In UNIX, you can escape a control character by preceeding it with a CONTROL-V.

So what use see when you type the above commad, will be

:%s/^M//g


References: http://www.tech-recipes.com/rx/150/remove-m-characters-at-end-of-lines-in-vi/

Tuesday, August 17, 2010

zip(or tar) and copy to remote machine in one command

Below is the command


tar cfpsP - DIRNAME OR FILENAME | ssh DEST_IP -C "cd DEST_DIR ; tar xf - "

If someone wants to do gunzip on the tar,then command would be

tar zcfpsP - DIRNAME OR FILENAME | ssh DEST_IP -C "cd DEST_DIR ; tar zxf - "