Skip to content

Instantly share code, notes, and snippets.

View luiscape's full-sized avatar
🤿

Luis Capelo luiscape

🤿
View GitHub Profile
@luiscape
luiscape / close_all_postgres_connections.sql
Created July 26, 2016 19:38
Closes all PostgreSQL connections except for the one sending this query.
#
# The following statement closes
# all PostgreSQL connections except
# for the one currently open (i.e.
# the one sending the query).
#
# Original solution by: http://goo.gl/znBpH
#
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
#
# This file contains a shell script
# that will add a header to a TXT file
# without a header. Headers make it easier
# to navigate files. We like them.
#
# Original solution by: http://stackoverflow.com/questions/13402809/insert-a-line-in-csv-file
#
FILE=file_without_header.txt
sed -i.bak 1i"HEADER1,HEADER2,HEADER3" \
@luiscape
luiscape / config
Created June 28, 2016 12:43
Example SSH config file.
Host intermediary
User foobar
Hostname 100.100.121.33
Port 14500
ServerAliveInterval 60
ServerAliveCountMax 30
Host target
User foobar
Hostname 100.100.232.44
@luiscape
luiscape / merge_csv_files.sh
Created June 27, 2016 15:37
Merges all CSV files into a single one.
#!/bin/bash
#
# Assuming files contain the same headers
# and that they are organized in the same
# way, this script merges all files from
# a given directory into a single file.
#
cat *.csv | grep -v ^Pool > merged.csv
#!/bin/bash
#
# The following script finds the
# latest (edited or created) 10 files
# on a Linux system. It runs quite
# quickly.
#
find . -type f -printf "%C@ %p\n" | sort -rn | head -n 10
#
### Keybase proof
I hereby claim:
* I am luiscape on github.
* I am luiscape (https://keybase.io/luiscape) on keybase.
* I have a public key whose fingerprint is 9EA2 6BE7 45D5 E250 E1B7 F274 CAC3 B9C0 7E2B 4271
To claim this, I am signing this object: