2014년 5월 29일 목요일

Conversion between Uri and file path

1. Conversion of Uri to file path
public String getPathFromUri(Uri uri){
Cursor cursor = getContentResolver().query(uri, null, null, null, null );
cursor.moveToNext(); 
String path = cursor.getString( cursor.getColumnIndex( "_data" ) );
cursor.close();

return path;
}

2. Conversion of file path to Uri
public Uri getUriFromPath(String path)
String fileName= "file:///sdcard/DCIM/Camera/2013_07_07_12345.jpg";
Uri fileUri = Uri.parse( fileName );
String filePath = fileUri.getPath();
Cursor c = getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
null, "_data = '" + filePath + "'", null, null );
cursor.moveToNext()
int id = cursor.getInt( cursor.getColumnIndex( "_id" ) );
Uri uri = ContentUris.withAppendedId( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id );

return uri;
}

2014년 5월 7일 수요일

vi Commands

General Startup
 To use vi: vi filename
 To exit vi and save changes: ZZ   or  :wq
 To exit vi without saving changes: :q!
 To enter vi command mode: [esc]

Counts
  A number preceding any vi command tells vi to repeat that command
 that many times.

Cursor Movement
  h   move left (backspace)
  j   move down
  k   move up
  l   move right (spacebar)
  [return]   move to the beginning of the next line
  $   last column on the current line
  0   move cursor to the first column on the current line
  ^   move cursor to first nonblank column on the current line
  w   move to the beginning of the next word or punctuation mark
  W   move past the next space
  b   move to the beginning of the previous word or punctuation mark
  B   move to the beginning of the previous word, ignores punctuation
  e   end of next word or punctuation mark
  E   end of next word, ignoring punctuation
  H   move cursor to the top of the screen
  M   move cursor to the middle of the screen
  L   move cursor to the bottom of the screen

Screen Movement
  G   move to the last line in the file
  xG  move to line x
  z+  move current line to top of screen
  z   move current line to the middle of screen
  z-  move current line to the bottom of screen
  ^F  move forward one screen
  ^B  move backward one line
  ^D  move forward one half screen
  ^U  move backward one half screen
  ^R  redraw screen (does not work with VT100 type terminals)
  ^L  redraw screen (does not work with Televideo terminals)

Inserting
  r   replace character under cursor with next character typed
  R   keep replacing character until [esc] is hit
  i   insert before cursor
  a   append after cursor
  A   append at end of line
  O   open line above cursor and enter append mode

Deleting
  x   delete character under cursor
  dd  delete line under cursor
  dw  delete word under cursor
  db  delete word before cursor

Copying Code
  yy  (yank)'copies' line which may then be put by the p(put)
     command. Precede with a count for multiple lines.

Put Command
  brings back previous deletion or yank of lines, words, or
 characters
  P   bring back before cursor
  p   bring back after cursor

Find Commands
  ?   finds a word going backwards
  /   finds a word going forwards
  f   finds a character on the line under the cursor going forward
  F   finds a character on the line under the cursor going backwards
  t   find a character on the current line going forward and stop one
     character before it
  T   find a character on the current line going backward and stop
     one character before it
  ;   repeat last f, F, t, T

Miscellaneous Commands
  .   repeat last command
  u   undoes last command issued
  U   undoes all commands on one line
  xp  deletes first character and inserts after second (swap)
  J   join current line with the next line
  ^G  display current line number
  %   if at one parenthesis, will jump to its mate
  mx  mark current line with character x
  'x  find line marked with character x
  NOTE: Marks are internal and not written to the file.

Line Editor Mode
  Any commands form the line editor ex can be issued upon entering
 line mode.
  To enter: type ':'
  To exit: press[return] or [esc]

ex Commands
  For a complete list consult the UNIX Programmer's Manual

READING FILES
  copies (reads) filename after cursor in file currently editing
  :r  filename

WRITE FILE
  :w  saves the current file without quitting

MOVING
  :#  move to line #
  :$  move to last line of file

SHELL ESCAPE
  executes 'cmd' as a shell command.
  :!'cmd'

Installing MySQL on Mac

ref: http://hoyanet.pe.kr/1942

2014년 5월 6일 화요일

Installing Tomcat on Mac OS

Step 1: Download a binary distribution of the core module: apache-tomcat-7.0.53.tar.gz (or apache-tomcat-7.0.53.zip) from here.

Step 2: Opening or Unarchiving the tar.gz (or zip) file will create a folder something like this in your Downloads folder ~/Downloads/apache-tomcat-7.0.53

Step 3: Move the unarchived distribution to /usr/local:
sudo mkdir /usr/local sudo mv ~/Downloads/apache-tomcat-7.0.53  /usr/local

Step 4: To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat:
sudo ln -s /usr/local/apache-tomcat-7.0.53  /Library/Tomcat

Step 5: Change ownership of the /Library/Tomcat folder hierarchy:
sudo chown -R /Library/Tomcat

Step 6: Make all scripts executable:
sudo chmod +x /Library/Tomcat/bin/*.sh

Step 7: Now executes the startup.sh and open your Web Browser and goto http://localhost:8080. You should see the following window.

You can use the very simple app Tomcat Controller.