Skip to content

Instantly share code, notes, and snippets.

View elhoyos's full-sized avatar

Juan Hoyos elhoyos

View GitHub Profile
@elhoyos
elhoyos / display_resolution.sh
Last active May 12, 2020 14:11
OS X El Capitan in VirtualBox
# Adjust the display resolution
# Use with:
# 128MB of video memory
# Graphics Controller: VBoxVGA
# 3D acceleration enabled
VBoxManage setextradata "Mac OS X El Capitan" VBoxInternal2/EfiGraphicsResolution 1920x1080
-- Count the number of rows for all tables in a schema
-- From: https://stackoverflow.com/a/38684225/638425
select table_schema,
table_name,
(xpath('/row/cnt/text()', xml_count))[1]::text::bigint as row_count
from (
select table_name, table_schema,
query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), false, true, '') as xml_count
from information_schema.tables
@elhoyos
elhoyos / quick-load.sql
Last active March 3, 2019 01:38
Load data, quickly
UPDATE pg_index SET indisready = false WHERE indrelid = 'my_table'::regclass::oid;
\copy my_table(column1, column2, ...) FROM 'my_table.csv' CSV HEADER;
UPDATE pg_index SET indisready = true WHERE indrelid = 'my_table'::regclass::oid;
@elhoyos
elhoyos / number_of_hotels_links.sh
Created March 27, 2018 22:38
Print the number of hotel links on a bunch of sitemap xmls
@elhoyos
elhoyos / export_import_redis.sh
Created January 4, 2018 21:02
Export/Import remote redis data
$ ssh redis-server "redis-cli -h redis.host.com --csv hgetall {s0m3key}" | \
awk -F, '{ gsub(/","/,"\" \"",$0); print "HMSET", "{s0m3key}", $0 }' - | redis-cli --pipe
@elhoyos
elhoyos / .bash_profile
Last active December 13, 2017 16:34
Load environment variables
function loadenv() {
. "$1" ; export $(cut -d= -f1 "$1")
}
export -f loadenv
$ echo '{"apps": [{"name": "app1"}, {"name": "app2"}]}' | pm2 restart -
@elhoyos
elhoyos / seo_info_from_logfile.sh
Last active May 6, 2017 16:49
Print useful SEO info from webserver logs
# Given a log file with entries of the following form:
# 2017-05-06T16:42:54.392Z 66.249.64.58 200 GET /path/to-somewhere 27.020 ms - - "-"
# Print all slow Google bot requests
tail -f web-server.log | awk '{ip=$2; status=$3; time=$6; path=$5; if (ip ~ /66\.249\.64/ && time > 150) print time " (" status ") " path}'
@elhoyos
elhoyos / top-truncate.sh
Created January 25, 2017 20:42
Remove first 10 lines from a file
sed -i '1,10d' myfile
# As per http://superuser.com/a/405314
@elhoyos
elhoyos / tips.md
Created December 19, 2016 16:38
cronjob tips

If you get these in your syslog:

Dec 19 05:07:01 ip-10-0-2-194 cron[9036]: (*system*aws-crawnchers) WRONG FILE OWNER (/etc/cron.d/some-cronjob)
Dec 19 05:08:01 ip-10-0-2-194 cron[9036]: (*system*web-server) INSECURE MODE (group/other writable) (/etc/cron.d/some-cronjob)

You need to: