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);