Wednesday, July 31, 2013

Ubuntu 14.04: configure dev env right after install


I hate some Ubuntu Unity (and, sure, Windows 8) UI 'innovations'.
Wishing best for programmers who write such unusable UI, but always configuring Ubuntu UI to be more usable (without using Compiz as it as a double trouble for all Ubuntu users). Here are my favourite kinds of such improvements:

1. Move all window controls (minimize,maximize,close) to the right:

gsettings set org.gnome.desktop.wm.preferences button-layout ":minimize,maximize,close"

2. Disable Unity global menu.

I didn`t found any option to make Unity global menu to stay visible
without mouse hovering on it. So, my suggestion is to disable Unity global menu and use more default and habitual menus location.

sudo apt-get remove indicator-appmenu

This will disable global menu for all apps except Firefox (Usually I don`t disable global menu for Firefox, but you can do this using this StackOverflow answer).

3. Add some app shortcuts (launchers) to Ubuntu desktop:

In previous Ubuntu versions user was able to add shortcuts to Desktop using built-in 'gnome-panel' application. But 'gnome-panel' package was excluded from default Ubuntu packages list for some weird reason.

So, we should to install it manually and call from terminal every time we need to create a new Desktop shortcut:

sudo apt-get install gnome-panel
gnome-desktop-item-edit ~/Desktop/ --create-new

But: be careful with icon sizes for you shortcuts. If you will use 512x512 or greater icon to your shortcut, it will be displayed as real-size, without fit.

4. Add 'open in terminal' option to folder context menus by installing 'nautilus-open-terminal' package (it works perfectly with Ubuntu 8 and higher, not only in 12.04 / 12.10).

sudo apt-get install nautilus-open-terminal

5 [optional] install some common dev tools:

        sudo apt-get install skype htop iotop mtr geany python python-pip awscli meld ssh wget curl openvpn network-manager-openvpn git gitk jq expect vagrant virtualbox virtualbox-dkms ec2-api-tools unzip
        sudo pip install ansible==1.9.4 boto keyring keyrings.alt
      
6 [optional] setup git aliases:

git config --global alias.br branch
git config --global alias.sts "status -sb"
git config --global alias.sts "diff --name-status -r"
git config --global alias.st "status"
git config --global alias.who "shortlog -s --"
git config --global alias.l "log --graph --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %s %Cgreen(%cr)' --abbrev-commit --date=relative"
git config --global alias.g "grep --break --heading --line-number"
git config --global alias.c "commit" 
git config --global alias.cia "commit --amend"


Thursday, July 4, 2013

Search through the GIT history like a ninja

To search for regexp through the whole GIT history you should to execute:

git grep <regexp> $(git rev-list --all)

 This will grep through all your commit text for regexp.

Here are some other useful ways of searching your source:

- Search working tree for text matching regular expression regexp:

git grep <regexp>

- Search working tree for lines of text matching regular expression regexp1 or regexp2:

git grep -e <regexp1> [--or] -e <regexp2>

- Search working tree for lines of text matching regular expression regexp1 and regexp2, reporting file paths only:

git grep -e <regexp1> --and -e <regexp2>

-Search working tree for files that have lines of text matching regular expression regexp1 and lines of text matching regular expression regexp2:

git grep -l --all-match -e <regexp1> -e <regexp2>

-Search all revisions for text matching regular expression regexp:

git grep <regexp> $(git rev-list --all)


-Search all revisions between rev1 and rev2 for text matching regular expression regexp:

git grep <regexp> $(git rev-list <rev1>..<rev2>)

If you have a git l alias to pretty log output, you can run this to search for commits whose changes include your regexp:

git l -G <regexp>
 

Friday, June 14, 2013

Oracle: get info about active running sessions with their queries


select t.sql_text, t.disk_reads,t.rows_processed,
t.elapsed_time,t.runtime_mem, t.executions, t.users_executing,
t.cpu_time, t.first_load_time, t.last_active_time, s.osuser, s.machine, s.status, to_char( logon_time, 'Mon dd@hh24:mi') logon_time
, rtrim (s.module)||decode( nvl(length( rtrim(s.module)),0),0,'',' ')|| upper(s.program) running_from,
'alter system kill session ''' || s.sid || ',' || s.serial# || ''';' AS command_to_kill,
'-- This will kill ' || s.schemaname || ' session, is occupied by ' || s.osuser || ', ''' || s.program
|| ''', started from '''|| machine || ''' at ' || first_load_time as notes
from v$session s, v$process p, v$sql t
where ( p.addr = s.paddr ) and s.type!='BACKGROUND'
and upper(s.program) not like '%CJQ0%' and s.program is not null and s.username is not null
and t.address =s.sql_address
and t.hash_value = s.sql_hash_value
and s.username <> 'SYSTEM'
and s.SID NOT IN (SELECT sys_context('USERENV','SID') FROM dual)
--and s.status = 'ACTIVE'
--and t.parsing_schema_name = '<SCHEMA_NAME>'
order by s.username;

Monday, April 15, 2013

GIT history cleanup

# 1. Remove temp files of Maven-release-plugin from overall GIT history:
git filter-branch --tree-filter 'find . \( -name "pom.xml.releaseBackup" -o -name "release.properties" \) -exec rm -rf {} \;'

# 2. Remove Java *.class files from overall GIT history:
git filter-branch --tree-filter 'find . \( -name "*.class" \) -exec rm -rf {} \;'

# 3. Remove Java Checkstyle .checkstyle files and Eclipse .settings files from overall GIT history:
git filter-branch --tree-filter 'find . \( -name ".checkstyle" -o -name ".settings" \) -exec rm -rf {} \;'


# 4. Change user nickname to 'First Name Last name' in overall GIT history
git filter-branch --env-filter \
'
if [ "$GIT_AUTHOR_NAME" = "dyaroslavtsev" ];
then
  export GIT_AUTHOR_NAME="Daniil Yaroslavtsev"
fi
'

# After 1,2,3, or 4 you should to delete the backup reflogs to reclaim the space (although now the operation is destructive):
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# You also should to clean repo with all reflogs with 'git gc' command using its 'aggressive' mode
git reflog expire --expire=now --all
git gc --aggressive --prune=now

Wednesday, April 3, 2013

Oracle: find out / kill connected non-system users


SELECT 'alter system kill session ''' || sid || ',' || serial# || ''';' AS RESULT,
'-- This will kill ' || schemaname || ' session, is occupied by ' || osuser || ', ''' || program
|| ''', started from '''|| machine || ''' at ' || first_load_time as notes
FROM (
  SELECT sid, serial#, schemaname, program, osuser, machine, logon_time, sql_hash_value FROM v$session
  WHERE SCHEMANAME NOT IN ('SYS', 'SYSTEM', 'ORACLE')
  AND STATUS ='ACTIVE'
  AND SID NOT IN (SELECT sys_context('USERENV','SID') FROM dual)
) sel
join v$sql v on (sel.sql_hash_value = v.hash_value);

Sunday, March 31, 2013

Useful Linux search / replace commands



Search for a text string against all *.log files of current folder:

1. List files of given type w/given string:

find . -name "*.log" -exec grep -l "<search_text>" {} \;

2. Print all matches in files of given type:

find . -name "*.log" -exec grep -A 3 -B 3 "<search_text>" {} \;

where -A and -B indicates the number of lines to print after and before found matches.

3. Replace strings in files:

replace 'windows' --> 'linux' in all files of current dir

grep -rl 'windows' . | xargs sed -i 's/windows/linux/g'

And, sure, you can use the UI tools for simple search/replace actions.
Example: regexxer search tool.