Skip to content

Instantly share code, notes, and snippets.

@michaelkarrer81
michaelkarrer81 / phantom.py
Created May 25, 2018 08:37 — forked from jsok/phantom.py
Use PhantomJS and Python Selenium bindings to take screenshots of websites.
import StringIO
from selenium import webdriver
from PIL import Image
# Install instructions
#
# npm install phantomjs
# sudo apt-get install libjpeg-dev
# pip install selenium pillow
@michaelkarrer81
michaelkarrer81 / postgres-cheatsheet.md
Last active February 26, 2024 21:21 — forked from Kartones/postgres-cheatsheet.md
[PostgreSQL command line cheatsheet] #database #postgresql

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@michaelkarrer81
michaelkarrer81 / postgresql_tuning.sh
Last active September 6, 2023 09:37
[postgresql tuning] How to analyze and tune the postgresql database #database #postgresql
# RESOURCES
# https://blog.codeship.com/tuning-postgresql-with-pgbench/
# http://www.linux-magazin.de/ausgaben/2013/07/postgresql-tuning/5/
# https://blog.timescale.com/timescaledb-vs-6a696248104e
# https://heapanalytics.com/blog/engineering/analyzing-performance-millions-sql-queries-one-special-snowflake
# https://www.citusdata.com/blog/2018/02/15/when-postgresql-blocks/
# https://amplitude.engineering/how-a-single-postgresql-config-change-improved-slow-query-performance-by-50x-85593b8991b0
# https://devcenter.heroku.com/articles/postgresql-indexes
# http://www.craigkerstiens.com/2013/01/10/more-on-postgres-performance/
@michaelkarrer81
michaelkarrer81 / update_instances.sh
Last active October 21, 2021 13:34
[Update instances.sh] #odoo #update #saltstack
# Get a list of all instances of a server
grep -l /srv/saltstack/pillar/instances/*.sls -e 'online1' | awk '$0=$2' FS=_ RS=. ORS=","
grep -l /srv/saltstack/pillar/instances/*.sls -e 'online2' | awk '$0=$2' FS=_ RS=. ORS=","
grep -l /srv/saltstack/pillar/instances/*.sls -e 'online3' | awk '$0=$2' FS=_ RS=. ORS=","
grep -l /srv/saltstack/pillar/instances/*.sls -e 'online4' | awk '$0=$2' FS=_ RS=. ORS=","
# all instances
grep -l /srv/saltstack/pillar/instances/*.sls -e 'online*' | awk '$0=$2' FS=_ RS=. ORS=","
# Check Release Tag of Online Core
@michaelkarrer81
michaelkarrer81 / PostgreSQL
Last active February 25, 2019 14:16
[Postgresql Cheat Sheet] #database #postgresql
# Fix PGADMIN on MAC OS X
pg_ctl -D /Users/mkarrer/Library/Application\ Support/Postgres/var-9.6 -l /Users/mkarrer/Library/Application\ Support/Postgres/var-9.6/postgresql.log restart
# Show database sizes on disk
psql
\l+
# https://wiki.postgresql.org/wiki/Index_Maintenance
# Index and table size
SELECT
import datetime
import pytz
# http://pytz.sourceforge.net/
# HINT: Do not use tzinfo on datetimes or pelace on datetimes because the pytz lib will randomly choose
# a daylight saving time offset. For vienne this would be in most cases 5 minutes off :(
# Instead us .localize() and .astimezone()
# Create timezone object with Europe/Vienna as the timzone (the timzone that your naive datetime is really ment for)
@michaelkarrer81
michaelkarrer81 / xpath_examples.xml
Last active April 20, 2023 17:36
[XPATH Examples] #xpath #odoo
<!-- Attribute contains string(s) -->
<xpath expr="//div[contains(@class, 'oe_right oe_button_box')]" position="inside">...</xpath>
<!-- Last element -->
<xpath expr="//ul/li[last()]" position="after">...</xpath>
<xpath expr="//ul/li[@class='nav'][last()]" position="after">...</xpath>
<!-- First element -->
<xpath expr="//ul[1]]" position="after">...</xpath>
If you have a huge repository (in size and in history) and want to add a subfolder
to your project as a submodule you can follow this example to save time and space
using git's shallow clone and shallow checkout feature. It is a bit more complicated
in this example because I assume that you want your submodule to track a non-default
branch, called `mybranch`, instead of the `master` branch. Things could probably get
a lot simpler when using the default branch. After following the commands in these
examples you can use `git submodule update` and `git submodule update --remote` as normal.
@michaelkarrer81
michaelkarrer81 / happy_git_on_osx.md
Created December 13, 2016 08:26 — forked from trey/happy_git_on_osx.md
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "[email protected]"

@michaelkarrer81
michaelkarrer81 / retain.conf
Last active November 9, 2016 12:54
Nginx retain query!
location /some/location {
# check, if any query strings are available
if( $args = '' ) {
# no query found, so...
return 301 /destination/url/;
}
# if it reaches here, then query is found, so...
return 301 /destination/url/?$args;
}