Skip to content

Instantly share code, notes, and snippets.

@denitram
denitram / ssh-handy
Last active October 3, 2018 12:07
ssh-handy
#---To change the passphrase on your default rsa key:
$ ssh-keygen -p -f ~/.ssh/id_rsa
#---Keep alive
~/.ssh/config
Host *
ServerAliveInternal 30
TCKeepAlive yes
# List installed packages
# List all services
systemctl list-unit-files
@denitram
denitram / bash_handy
Last active December 28, 2017 12:02
bash handy tips
#--- Commandline history substitution
* Replace old by new in prevous command
^old^new
^old^new is equivalent to !!:s/old/new
* Replace globally
!!:gs/old/new
#--- Batch renaming file
@denitram
denitram / rename_files_lc.txt
Last active November 17, 2015 12:35
rename files to lowercase
* quick and dirty
for i in `ls` ; do mv "$i" "$(echo $i | tr A-Z a-z)"; done
* beter version
for i in $(find . -type f -name "*[A-Z]*"); do mv "$i" "$(echo $i | tr A-Z a-z)"; done
-name "*[A-Z]*" ensures that only files with capital letters are found. For example, if files with only lowercase letters are found and moved to the same file, mv will display the are the same file error.
Thanks to Steve see: http://stackoverflow.com/questions/13051871/change-filenames-to-lowercase-in-ubuntu-in-all-subdirectories
@denitram
denitram / sed-handy
Last active August 29, 2015 14:24
sed
# Add the first line of file1 at the top of file2
$ h=head -n 1 file2
$ sed -i "1s/^/$h \n/" file2
@denitram
denitram / testing-hsql
Created May 7, 2014 14:23
HSQL database manager
java -cp ~/.m2/repository/org/hsqldb/hsqldb/2.2.8/hsqldb-2.2.8.jar org.hsqldb.util.DatabaseManager
@denitram
denitram / proxy-settings
Last active March 7, 2016 19:02
Proxy settings
#!/bin/bash
# Set proxy settings in Ubuntu for eclipse, maven and apt
#### variables
ECLIPSE_SETTINGS_DIR="/home/martine/apps/springsource/sts-3.4.0.M1/configuration/.settings/"
ECLIPSE_SETTINGS_FILE="org.eclipse.core.net.prefs"
ECLIPSE_SETTINGS_PROXY="org.eclipse.core.net.prefs-PROXY"
ECLIPSE_SETTINGS_NOPROXY="org.eclipse.core.net.prefs-NOPROXY"
ECLIPSE_SETTINGS=$ECLIPSE_SETTINGS_DIR$ECLIPSE_SETTINGS_FILE
@denitram
denitram / BU-restore functions in postgresql
Last active July 10, 2023 11:09
Postgresql: backup and restore functions
# First, make a dump of the database without data (-s)
$ pg_dump -h localhost -U username -Fc -s -f db_dump dbName
# Create a list of the functions
$ pg_restore -l db_dump | grep FUNCTION > function_list
# Restore the functions in an other database
$ pg_restore -h localhost -U username -d other-dbName -L function_list db_dump
@denitram
denitram / PostgreSQL handy commands
Last active May 20, 2020 12:57
Potsgresql: handy commands
-- Viewing current PostgreSQL queries
-- source: http://chrismiles.info/systemsadmin/databases/articles/viewing-current-postgresql-queries/
SELECT datname,pid,query,query_start FROM pg_stat_activity ORDER BY query_start ASC;
-- top-like view of current queries, grouped by how many of the same query are running at that instant and the usernames belonging to each connection.
SELECT count(*) as cnt, usename, current_query FROM pg_stat_activity GROUP BY usename,current_query ORDER BY cnt DESC;
-- List databases creation dates
SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database ORDER BY modification;
SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database ORDER BY datname;
@denitram
denitram / regex
Last active August 28, 2016 22:47
8 Regular Expressions You Should Know
http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
# insert a new line with '<null\>' as content every 6th line between lines 100 and 2000
100,2000s/\v(.*\n){6}/\0\<null\/\>\r/g
see http://stackoverflow.com/questions/10413906/how-to-add-a-line-after-every-few-lines-in-vim
# delete blank lines
:g/^$/d
# join all lines