Skip to content

Instantly share code, notes, and snippets.

View flavianmissi's full-sized avatar

Flavian Missi flavianmissi

View GitHub Profile
@flavianmissi
flavianmissi / foo.sql
Created May 23, 2017 12:52
kill psql connection to a database
-- show
SELECT * from pg_stat_activity;
-- Get the pid from the above query. Then:
-- kill
SELECT
pg_terminate_backend(pid) -- this is your pid
FROM
pg_stat_activity
@flavianmissi
flavianmissi / k8s_helper.sh
Created March 22, 2017 16:11
Remove kubernetes services that do not have any deployment with the same name
for svc in $(kubectl get svc -o jsonpath='{.items[*].metadata.name}')
do
kubectl get deploy $svc -o jsonpath='{.items[*].metadata.name}'
failed_to_find=$?
if [ "$failed_to_find" -eq "1" ]
then
echo "Could not find deploy for service " $svc ", deleting the service..."
kubectl delete svc $svc
else
echo "Found deploy for svc " $svc # ", look!"
@flavianmissi
flavianmissi / redshift
Created February 25, 2016 17:12
Redshift (adjusts the color temperature of your screen according to your location) initialization scripts for my current location
#!/bin/sh
#/etc/init.d/redshift
set -e
. /lib/lsb/init-functions
BASE=$(basename $0)
REDSHIFT=/usr/bin/$BASE
REDSHIFT_PIDFILE=/var/run/$BASE.pid
@flavianmissi
flavianmissi / drop-south.sh
Created August 11, 2015 14:45
Delete all migration files (but not __init__.py) from a Django project
find -E . -iregex '.*/[0-9].*\.py' #-delete
@flavianmissi
flavianmissi / postgresql.conf
Created April 14, 2015 09:48
postgresql sample edited conf
shared_buffers = 512MB
work_mem = 16MB
fsync = off
synchronous_commit = off
wal_buffers = 64MB
checkpoint_segments = 36
checkpoint_timeout = 10min
random_page_cost = 2.0
effective_cache_size = 1024MB
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.31.tar.gz
workon myvenv # or you venv name
pip uninstall setuptools # needs confirmation (y)
tar -xvf distribute-0.6.31.tar.gz
cd distribute-0.6.31
@flavianmissi
flavianmissi / tasks.py
Created February 8, 2015 15:47
my celery task
from celery.task import task
@task
def prerender_obj(obj_id):
try:
myobj = MyModel.objects.get(pk=obj_id)
myobj.prerender()
except MyModel.DoesNotExist:
# do stuff
return True
@flavianmissi
flavianmissi / find_replace_sed.sh
Last active August 3, 2016 11:30
find and replace with sed
find . -name *.py -type f -print0 -exec sed -i '' 's/pattern/new_pattern/g' {} +
# the above code seems to be bugged, instead:
for p in ` find . -name "*.html" -type f`;do sed -i '' 's/slug/tobase64/g' $p;done
# if you're not on OS X there is no need to pass -i '' to sed, just run:
find . -name *.py -type f -print0 -exec sed -i 's/pattern/new_pattern/g' {} +
# this avoids the "invalid command code ." error (on OS X)
@flavianmissi
flavianmissi / awk-pid-filter.sh
Created November 16, 2014 18:12
awk: filter processes ids based on pattern and writes to file
ps -ef |grep "python challange" | awk '{print $2;}' > tmp
# to kill them:
kill -9 $(cat tmp)