Category Archives: Cheat sheets - Page 5

My SVN cheat sheet

Here is my “Cheat sheet” for the Subversion version system

Create repository

svnadmin create <project1>

This will create a repository at your current location named “project1”

Import a project locally

svn import /path/to/files/to/import file:///path/to/repository -m "Initial import"

Import a project into remote server (running svnserve on server)

svn import /path/to/files/to/import svn:///path/to/repository -m "Initial import"

Checkout locally

svn co file://<path to repository> <foldername>

<foldername> will be created if it does not exists. NOTE If you are using branches/tags/trunk structure don’t forget to include it in the path (eq. /path/to/repository/trunk).

Checkout remote (with svnserve running on server)

svn co svn://<host/path/to/repository>/<foldername>

Checkout remote (svnserve and authentication)

svn co --username=<user>  svn://<host/path/to/repository>/<folder>

List svn directory (to look at directory contents)

svn list file://<path to repository>/<foldername>

Use ‘svn://…’ for remote ‘look’ in the same way as with checkout. This will display thew latest revision. To see another revision use @revision (at the end of the path)

Commit changes (all files)

svn commit -m"<commit message>"

Commit one file

svn commit -m"<commit message>" filename

To commit more then one file just place their path after the first ‘filename’

Check status of your working copy

svn status

NOTE You have to stand inside the working directory for the command to work

Get info about a repository (eg. URL, root)

svn info

Conflict resolving
Resolvetypes:

  • mine-full: use your version only
  • theirs-full: use the latest version in the repository
  • base: use the version you used before making any changes
  • working: this is the option if you want to do a manual merge of the file. Removing the changes you don’t want and keeping the ones that you want on a row by row basis

Resolve command:

svn resolve --accept resolvetype filename

Ignore files and folders globally
In the section [miscellany] in your subversion conf file (OS X: /User/<username>/.subversion/conf) there is a setting called global-ignores
Example:

global-ignores = .* old *.gz tmp

This ignores hidden files/folders (all which name starts with a dot (.)), all files/folders called old or tmp and all files ending with .gz

Ignore files and folders locally
Run this command from the folder above the files/folders that should be ignored:

svn propedit svn:ignore . #NOTE the last dot!

This opens up your chosen editor (ENV variable EDITOR=editor) so you can add your ignore files/folders. One ignore per line.
Example:

.*
old
*.gz
tmp

When you save and exit the properties are written to that folder

Add folder non recursive
By default svn add is recursive so all files and folders in the folder you add will be added automatically. To just add the one folder and not the content of that folder use the –non-recursive option

svn add --non-recursive foldername

This will only add the folder foldername and not any files or folders inside foldername

My Tmux “cheat sheet”

I work a lot in terminal windows and sometimes from different locations. Starting new sessions and logging in to every server (sometimes up to 10 servers with different users) can be quite tiresome. In the beginning I was a fan of the GNU Screen program but after I found Tmux I never looked back. Now dont get me wrong, GNU Screen is a great program but I believe that Tmux handles splits, windows and commands a little better. Here are my most used commands i Tmux

Start tmux

tmux

Start saved session

tmux attach

Display sessions

tmux ls

Start a new shared session

tmux -S /tmp/shared_session
chmod 777 /tmp/shared_session #Anyone can now join your session

Attach to a shared session

tmux -S /tmp/shared_session attach

Command mode

ctrl + b

All commands below start with this key combination. It makes Tmux waiting for a command to run

Exit session (session is automatically saved)

ctrl + b + d

Help screen

ctrl + b + ?

This will show you alla commands available. If you make changes to command in the configuration file you will also see them here. To exit the help press q

Create new window command

ctrl + b + c

Rename window you are currently in

crtl + b + , (comma)

Switch between windows (You can see all created windows in the bottom list of Tmux window)

ctrl + b + 0-9 #eg ctrl + b + 1 will take you to window number 1 

Switch between panes (ctrl + b + arrow keys)
* Key Up to switch to pane above
* Key Down to switch to pane below
* Key Right to switch to pane to the right
* Key Left to switch to pane to the left

If you stand in the pane the most to the right and press to go right the cursor will move to the leftmost pane. Same goes for all directions.

Scroll mode (this let you scroll window/pane by using Page Up/Page Down and the Up and Down keys)

ctrl + b + PageUp

Exit scroll mode

Esc or q key

The following commands depend om my config (default options are found in the help menu if you are not using my config)

Split window horizontal

ctrl + b + h

Split window vertically

ctrl + b + v

Grow pane horizontally

ctrl +b + + (plus)

Shrink pane horizontally

ctrl + b + - (minus)

Grow pane vertically

ctrl + b + *

Shrink pane vertically

ctrl + b + /

My Tmux configuration file (place it in your home directory named .tmux.conf to use it)

# Splitting windows into panes with h and v 
bind-key h split-window -v
bind-key v split-window -h

# Set up resize-pane keys
bind-key + resize-pane -D 3
bind-key / resize-pane -L 3
bind-key - resize-pane -U 3
bind-key * resize-pane -R 3

NEW! For all you spanish speaking people out there, my friend Stephen Chow has translated this post in his blog: stephenchow.es

Oracle DB syntax cheat sheet

When working with many different databases in CLI mode a “cheat sheet” for each is really necessary to keep you from going bonkers. Here is mine for Oracle 10g (from inside SQLPlus):

Show table
Tables you own

select table_name from user_tables;

Tables you own and tables you have been granted select rights on

select table_name from all_tables;

To list all tables you are granted to see

select table_name from dba_tables;

Show primary key of table

SELECT cols.column_name, cols.position, cons.status
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'YOUR_TABLE_NAME'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;

This will show you the name of the key/s, order (if more then one) and status of the key/s

Create tables

create table tablename ( columnname type, columnname type …, primary key(keycolumn,keycolumn,...));

Get table information

DESCRIBE tablename

Alter table
Add column

alter table tablename add(  columnname datatype, ...);

Change datatype of column

alter table tablename modify ( column newdatatype);

Drop column

alter table drop column columnname;

Delete table

drop table tablename;

INSERT

INSERT INTO tablename (column1, column2,... ) VALUES (1, 2,...');

SELECT

SELECT column1, column2,... FROM tablename WHERE column1 = 1 AND column2 = 2 ORDER BY column1, column2,...;

UPDATE

UPDATE tablename SET column1 = 1, column2 = 2,... WHERE column1 = 1 AND column2 = 2 AND ...;

DELETE
Delete all rows

DELETE FROM tablename;

Delete rows

DELETE FROM tablename WHERE column1 = 1 AND column2 = 2, ...

Write query result to file
From inside SQLPlus:

SQL>SPOOL /path/to/file
SQL>SELECT * FROM users;
SQL>SPOOL OFF

The result from the query will now be in the file specified on the fist line