Monday, June 28, 2010

Encrypt Documents easily

You don't need all those password manager software and applications for text files encryption/protection. It is very easy in linux or in mac.
Put your rarely and tough passwords in a text file then encrypt it. Anyway it's bad idea not because of encryption but because you may open it while someone is around and he sees all your password. Encryption is DES which is considered good so don't worry about encrypted thing.
Now if you have a file named text.txt and you want to encrytpt it simply run following command in terminal.

openssl des3 -salt -in text.txt -out text_encrypted

This will ask you for a password two times last one is for confirmation. That's all your file is password protected. Now you can safely delete your text.txt.
For decrypting the command is

openssl des3 -d -in text_encrypted

oho! everything inside the encrypted file is decrypted and printed on terminal(std output). You can even specify the out file name but then you have to delete the file after you have read it in plain text. If you forget to delete or leave the terminal open while you have use it for displaying :( sad anyone can see it now. So, use this thing with caution.
For creating the file back( for putting things in a file and not on std output)
type this in terminal:
openssl des3 -d -in text_encrypted -out text.txt

Here is a simple bash script which will do all this with one command and is user friendly way.


#!/bin/bash
#for locking
echo "Enter file to encrypt"
read "in_file"
out_file=`basename "$in_file"`
out_file="$out_file.encrypt"
echo encrypted file will be: $out_file
openssl des3 -salt -in "$in_file" -out "$out_file"
echo "Do you want to delete original file y/n?"
read "resp"
true="y"
if [ "$resp" = "$true" ]; then
rm "$in_file"
fi



For unlocking:
#!/bin/bash
#for unlocking
echo "Enter file to decrypt"
read "in_file"
echo "Do you want to write the output on std out(y) or in file(n) enter y/n"
read "resp"
true="y"
if [ "$resp" != "$true" ]; then
out_file=`basename "$in_file"`
openssl des3 -d -in "$in_file" -out "$out_file.unecrypted"
echo "Remember to delete the unencrypted file afterward"
else
openssl des3 -d -in "$in_file"
fi

Friday, June 25, 2010

No need for simple calculator if you have bc

Also do some advance stuff like power. very simple to use. obvious commands.
run bc then give inputs on standard input you can even write your calculation in a file then give that file as input to bc command.

Some Commands for audio files

May be not so useful :)

who wants to play song from terminal? I guess no one but if you want to do it for some reason for some audio file in mac try this
afplay file.mp3
afplay for playing audio file

want information about audio file use
afinfo filename

for getting information bat an audio file

sample info result:
Nandan-Dubeys-MacBook:Watermark nandan$ afinfo 03\ On\ Your\ Shore.mp3
File: 03 On Your Shore.mp3
File type ID: MPG3
Data format: 2 ch, 44100 Hz, '.mp3' (0x00000000) 0 bits/channel, 0 bytes/packet, 1152 frames/packet, 0 bytes/frame
no channel layout.
estimated duration: 240.222 sec
audio bytes: 2237152
audio packets: 9196
bit rate: 74000 bits per second
packet size upper bound: 1052
maximum packet size: 731
audio data file offset: 15678
optimized
----

Friday, June 18, 2010

MacOS opening applications from terminal

Do you use terminal most of the time?
For opening applications form Terminal I have added /Applications/app/Contents/MacOS/ for all applicatons so for TextEdit I have /Applications/TextEdit.app/Contents/MacOS/ in my path. This has made my .bash_profile long. Then I got this command
open -a application_name
-a for application For using this command you don't need to add anything in PATH. application_name is not case sensitive so you can write
open -a teXeDiT or open -a textedit or open -a preview . So this make things easy.
To open files from any folder you can write
open file.txt or open path/file.pdf etc this will directly open a file with corresponding application but it will not create a new file so file must exists.
You can even use open http://www.blogger.com to open blogger in safari.
cool!!
So just remeber
open for opening file and open -a for opening applications

Monday, June 14, 2010

Enable php on mac

This one of the many great good things which I like in mac. Mac already comes with apache configured so you can just start building your own site. I use this to check the pages before uploading to server and also for sharing things blogging privately among wing mates locally.
By default php is not enabled when you configure apache to any computer so here is the way to make it work on mac.

Open file /private/etc/apache2/httpd.conf for edit for this you may use
sudo vi /private/etc/apache2/httpd.conf

Uncomment the line which read something like 
LoadModule php5_module libexec/apache2/libphp5.so
you can search this line on vi

Now restart your Web Sharing
Open System Preferences and go to Sharing
Stop and then restart Web Sharing
That’s it!

Saturday, June 5, 2010

Beamer themes

Beamer themes I generally use

\usetheme{Madrid} % good one!
\usetheme{Boadilla} % Pretty neat, soft color.
\usetheme{Warsaw} % This one is my favorite
\usetheme{Bergen} % This one has navigation on the left
\usecolortheme{seahorse} % Simple and clean template

Mac switch b/w options

I was too worried about this. I was really not able to understand the intention why they have made touchpad or mouse use compulsory. For almost one and half year I have touched my touchpad whenever I got option buttons(dialogue buttons) i.e. cancel, ok, save, quit,restart, sleep etc. Then suddenly I realize that I am wrong all the time there is option to switch the keyboard buttons in action for these petty but all the time used things also. I don't able to figure out why they have disabled this option by default that really is wrong.
So here is the way to enable keyboard tab button to switch between options in dialogue box.

Go to System Preferences -> Keyboard -> Keyboard Shortcuts and then check mark the option "All Controls" at the bottom.