Friday, January 27, 2012

pushd and popd

pushd saves the current working directory in memory.
popd returns to the path at the top of the directory stack.

Example
[sputnik@localhost html]$ pushd . # push current directory to memory
/var/www/html /var/www/html

[sputnik@localhost etc]$ cd /var/games/ # change directory

[mshnaydman@localhost games]$ popd # returns from directory
/var/www/html
[sputnik@imagick-test html]$

For more information, read the Wiki Page

Resize & write data into image

I had task to resize image and add unique identifier. See below handful utilities.

- Exiv2 (manage image metadata. Supports IPTC, Efix, XMP and others formats)
Example: Add the field to IPTC
[sputnik@test_hires] iptc -M"add Iptc.Application2.SpecialInstructions blah blah" myfile.jpg

- Imagemagick (resize, edit, view images or more)
Example: Resize image to 200x200 pixels
[sputnik@test_hires] convert -resize 200x200 myfile_input.jpg myfile_output.jpg

- Identify (image characteristics. is a member of the ImageMagick suite of tools)
Example: Get image size
[sputnik@test_hires] identify -format '%w:%h' $source

- File (determine file type)
Example: Get Filename information. For more 'man file'
file -i $filename | cut -d':' -f 2

Sunday, January 8, 2012

Astronomy Lectures

I start getting into Astronomy for last few weeks and find the subject very interested.
Here are 3 lectures by professor David Helfand that I find interesting:

Astronomy Lecture 1: What Is a Star?
Astronomy Lecture 2: Lives of the Stars
Astronomy Lecture 3: Planets Everywhere


There lectures still available in Google Videos.

Thursday, December 15, 2011

cd command

Few most useful b commands
cd - # move back to the previous directory
cd ~ # move into your home directory
cd .. # move up one directory

Wednesday, December 14, 2011

Umask

umask is a set of setting default permissions for files or directories that you create on your system.
umask tells the system what permissions to remove from the normal default setting.
umask value can be a three or four digit value.

Global umask value can be change in /etc/bashrc (default value is 0022 or 022).
The extra 0 at the beginning just means that the number is in octal format.
umask can be set temporary using umask command

Example:
umask 077 (Owner - read, write and execute, Group - No Permissions, Others - No Permissions)

How to calculate umasks?
The octal umasks are calculated using bitwise AND of the unary complement of the argument using bitwise NOT. The octal notations are as follows:
Ocatal Value | Permission
0 - read, write and execute
1 - read, write
2 - read, execute
3 - read only
4 - write and execute
5 - write only
6 - execute only
7 - no permissions

Note: Directories must be executable (X) in order to browse them.

Tuesday, December 13, 2011

Scraping

LXML is useful Python library for scraping. Here is an example of scraping script

pip install requests
pip install lxml

#! /usr/bin/python
import requests
import lxml
from lxml import html

r = requests.get('https://www.google.com/')
tree = lxml.html.fromstring(r.content)
elements = tree.get_element_by_id("prm")
for el in elements:
print el.text_content()

Note: It works with Python 2.6.1 (did not work with Python 4). LXML specs

Tuesday, November 22, 2011

Studio 60


The show reminds me of Saturday Night Live. Good show, actors and plot. Another great show written by Aaron Sorkin.

Monday, November 21, 2011

MAC Screenshot Command


  1. command+shift+3 // Full Screenshot

  2. command+shift+4 // Crosshair to allow selection of screenshot area

  3. command+shif+4(then spacebar) // Camera to capture specific screen object. Similar to Digital Camera

Chelsea Piers GYM (Pier 60)

Almost 3 years ago I stopped going to GYM and slowly gained weight. After some consideration I choose Chelsea Piers that is located 15 min walk from my work. I am planning to go to the gym at least 3 times per week (morning hours before work).

The gym would cost me $55 per paycheck.

I woke up at 5:45AM today and exercise for 45 minutes. I feel better and refreshed.

Tuesday, November 1, 2011

Import CSV file into MYSQL


LOAD DATA INFILE 'myfile' INTO TABLE table FIELDS TERMINATED BY ',';