Sunday, December 16, 2012

Emacs cheatsheet



emacs customization files
--------------------------------------

.emacs.d  (customizations)
init.el      (loaded everytime)

Starter Kit
----------------
emacs-starter-kit (github)

Frames
-----------
M-x make-frame
M-x make-frame-on-display

Misc
--------
M-x man
C-x h (select all text of current buffer)
M-x untabify (to replace tabs with spaces)

Region
----------
Mark region then
C-x C-i (to indent the region)

Open Lines Like vi
The ‘o’ and ‘O’ commands of vi are closely equivalent to ‘C-a C-M-o’ and ‘C-e C-j’ 

Switching between buffers
---------------------------------------
C-x b    <----> C-x b  (switch buffers)
C-x C-b    D - Delete , U - undo , X - when done.

Help
------
C-h k  key
C-h i   (info page)
C-h f   (describe function)
C-h a (apropos)
C-h t  (tutorial)

CUA MODE
----------------
M-x cua-mode

C-space (mark) then C-ENTER then move cursor to select region
press C-enter again.
Now start editing anywhere in the block. The effect will be that
the text will appear on all lines of the region.
M-n (to start line numbering within the region)

Commenting
------------------
M-;  (acts on a region or when no region then single line)

Completion
----------------
M-/

?  send buffer to end of  list.

TAGS
--------
ctags -a -e -f TAGS *
find ... | xargs ctags -a -e -f TAGS
M-.  (find the tag for the text at cursor)
M-x visit-tags-table

Modes
----------
M-x whitespace-mode ( colors - yellow - mixed
                                                      black  - too long
                                                      red - trailing white spaces)
M-x follow-mode

M-x whitespace-report
C-h a whitespace

M-x fly-spell-mode (spell checking)
   - to see the suggestions for spelling fix , middle mouse click on word
     or Esc-\t  in text mode

M-x flymake-mode (to check syntax for the lang as u type)

Hooks?

M-x eval-buffer ?

Version Control
-----------------------
M-x vc-mode
C-x v (diff against HEAD)
C-x vn  revision ??
C-x vl   (view commit log)
C-x vi  (add file)

magit -- git extension for emacs

SHELL
---------
M-x shell
M-x shell-command
M-x shell-command-on-region

M-x eshell

$ ls > # (creates a buffer with the command output)


ELPA (Emacs Lisp Package Archive)
--------
M-x package-list-packages
i (mark package)
x (install marked packages)


download to .emacs.d
color-theme.el
yasnippet.el (textmate)


M-x irc
M-x tetris


Good Websites for Emacs

www.emacswiki.com
planet.emacsen.org



Monday, September 10, 2012

calculating running total with Oracle SQL

-Analytical functions in Oracle.

SELECT rownum ,
  SUM(rownum) over (order by rownum rows BETWEEN unbounded preceding AND CURRENT row) AS running_total , (rownum * (rownum+1))/2 as formula
FROM dual
  CONNECT BY rownum < 11;

The above can be used with a real table. The order by can be any columns that you wish to order the rows by and sum() can be on a column that you wish to calculate running total on.


Friday, August 17, 2012

PL/SQL function to create insert script for a table

-- The following function  will create an insert script for a given table.

-- Usage : select get_insert_script('EMP') from dual;
-- This will output to stdout the insert script.
-- Now you may later change the where clause to select a subset of rows from the table.

-- Where its userful:
-- I dont have export priv on production database. I can't really use export the table.
-- This provides an easy way to pull data and then insert into DEV environment to REFRESH the table

--Another alternative way is to select the data as delimited by say comma and then
-- write a sqlloader control file to load the data. This will be faster.

create or replace
FUNCTION GET_INSERT_SCRIPT (V_TABLE_NAME VARCHAR2)
  RETURN VARCHAR2 AS
  B_FOUND  BOOLEAN         := FALSE;
  V_TEMPA  VARCHAR2 (8000);
  V_TEMPB  VARCHAR2 (8000);
  V_TEMPC  VARCHAR2 (255);
BEGIN
  FOR TAB_REC IN (SELECT TABLE_NAME
                    FROM ALL_TABLES
                   WHERE TABLE_NAME = UPPER (V_TABLE_NAME)) LOOP
    B_FOUND := TRUE;
    V_TEMPA := 'select ''insert into ' || TAB_REC.TABLE_NAME || ' (';

    FOR COL_REC IN (SELECT   *
                        FROM ALL_TAB_COLUMNS
                       WHERE TABLE_NAME = TAB_REC.TABLE_NAME
                    ORDER BY COLUMN_ID) LOOP
      IF COL_REC.COLUMN_ID = 1 THEN
        --V_TEMPA := V_TEMPA || '''||chr(10)||''';
        null;
      ELSE
        V_TEMPA := V_TEMPA || ',';
        V_TEMPB := V_TEMPB || ',';
      END IF;

      V_TEMPA := V_TEMPA || COL_REC.COLUMN_NAME;

      IF INSTR (COL_REC.DATA_TYPE, 'CHAR') > 0 THEN
        V_TEMPC := '''''''''||' || COL_REC.COLUMN_NAME || '||''''''''';
      ELSIF INSTR (COL_REC.DATA_TYPE, 'DATE') > 0 THEN
        V_TEMPC :=
             '''to_date(''''''||to_char('
          || COL_REC.COLUMN_NAME
          || ',''mm/dd/yyyy hh24:mi:ss'')||'''''',''''mm/dd/yyyy hh24:mi:ss'''')''';
          ELSIF INSTR (COL_REC.DATA_TYPE, 'TIMESTAMP') > 0 THEN
          V_TEMPC :=
             '''to_timestamp(''''''||to_char('
          || COL_REC.COLUMN_NAME
          || ',''mm/dd/yyyy hh24:mi:ss.ff'')||'''''',''''mm/dd/yyyy hh24:mi:ss.ff'''')''';
      ELSE
        V_TEMPC := COL_REC.COLUMN_NAME;
      END IF;

      V_TEMPB :=
           V_TEMPB
        || '''||decode('
        || COL_REC.COLUMN_NAME
        || ',Null,''Null'','
        || V_TEMPC
        || ')||''';
    END LOOP;

    V_TEMPA :=
         V_TEMPA
      || ') values ('
      || V_TEMPB
      || ');'' from '
      || TAB_REC.TABLE_NAME
      || ';';
  END LOOP;

  IF NOT B_FOUND THEN
    V_TEMPA := '-- Table ' || V_TABLE_NAME || ' not found';
  ELSE
    V_TEMPA := V_TEMPA || CHR (10) || 'select '' commit;'' from dual;';
  END IF;

  RETURN V_TEMPA;
END;

Saturday, August 11, 2012

perl one liners

Social Engineering, Cooperating with Command Interpreters - Very good chapter in Programming Perl book.



To print the last field in a tab delimited text

ls -al | perl -ane 'print pop(@F), "\n"'
-- The main thing to take away here is the -an flag and the @F list.
-- different delimiter can be provided with -F flag.


or in awk.
ls -al | awk '{print $NF}'



Wednesday, July 25, 2012

ssh problems after installtion of Centos 6.3 x64

Centos 6.3 was installed sucessfully.

eth0 ip was 192.168.1.46

I edited the sshd_config file and changed port from 22 to 22421
disabled password authentication

I was not able to ssh to this server @ 192.168.1.46

I was not seeing any errors/messages in /var/log/secure

after some debugging I did the following to fix the issue
- Disabled SELinux

This still did not fix the issue of ssh login but at least it logged messages in /var/log/secure.

looked at /var/log/secure and found that
 the error was
Authentication refused: bad ownership or modes for file /home/wb003c/.ssh/authorized_keys

checked the perms on file and it was
664

changed it to 600 and Viola , ssh started working.


-- Not sure if disabling SELinux also helped me fix the issue. Will research this at another time.


Thursday, July 12, 2012

saving stdout to a different server via ssh

exec_sql.pl -s pd.sql | zip -9 | ssh login@$DEVIP "cat >> /home/user/data.zip"

zip -9 acts as a filter and zips the stdout on the fly.

and on the target machine to unzip do the following

unzip -p data.zip

compare / diff files over ssh - remote file vs local file

ssh remote_user@remote_ip "cat remote_file.ks" | diff  - localfile.ks

This logs into the remote server , concatenates the file and pipes it to diff.
Diff treats the remote file as stdin and compares with localfile

- having ssh key authentication helps as no need to enter the password of the remote server.

Monday, March 19, 2012

debugging pl/sql procedure

This requires "DEBUG CONNECT SESSION" system privilege. (Debugging using PL/SQL developer).

Sunday, March 18, 2012

cannot run set autotrace on statistics;

The sqlplus command set autotrace on statistics; gave SQL> set autotrace on statistics SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled SP2-0611: Error enabling STATISTICS report SQL> connect / as sysdba Connected. SQL> grant plustrace to aarav; grant plustrace to aarav * ERROR at line 1: ORA-01919: role 'PLUSTRACE' does not exist executed $ORACLE_HOME/sqlplus/admin/plustrce.sql as sys user then "grant PLUSTRACE to aarav" then autotrace worked fine.

Monday, March 12, 2012

Error in adding datafile to users tablespace

alter tablespace users add datafile '/opt/oracle/app/oradata/aarav/users02.dbf' size 16G autoextend on next 1G maxsize 32G

Error report: SQL Error: ORA-03206: maximum file size of (4194304) blocks in AUTOEXTEND clause is out of range 03206. 00000 - "maximum file size of (%s) blocks in AUTOEXTEND clause is out of range" *Cause: The maximum file size for an autoextendable file has exceeded the maximum number of blocks allowed. *Action: Reduce the size and retry.


I users01.dbf was at 32G so I could not create any more data segments in it so had to add a new datafile to the tablespace above. Got the error so I modified the statement to alter tablespace users add datafile '/opt/oracle/app/oradata/aarav/users02.dbf' size 16G autoextend on next 1G;

Friday, March 9, 2012

Things I need to do/learn well. 1. Install subversion with individual logins and webpage to view the repository. 2. Perl one liners 3. Awk one liners 4. sed one liners 5. Java Certification - core java and more JVM internals Effective Java book Patterns in Java Datastructures in Java 6. Oracle 11G OCP Tuning RMAN 7. PHP 8. Essential computer mathematics 9. Perl 10. Python 11. MySQL 12. Postgres 13. LPIC - Linux

Followers

About Me

Torrance, CA, United States