Skip to content

Instantly share code, notes, and snippets.

@melizeche
melizeche / upgrade_DO_django_to_python3.sh
Created December 17, 2018 22:46
Upgrade DigitalOcean's "One click apps" Django installation to Python3
apt install -y python3 python3-pip
pip3 install django==1.11.11 netifaces psycopg2-binary gunicorn==19.7.1 gevent
sed -i 's/python/python3.6/g' /usr/bin/gunicorn
sed -i 's/python/python3.6/g' /home/django/django_project/manage.py
/home/django/django_project/manage.py migrate
systemctl restart gunicorn.service
@melizeche
melizeche / get_licenses.py
Created February 9, 2018 21:28
Get licenses of all packages in use
import pkg_resources
import prettytable
def get_pkg_license(pkg):
try:
lines = pkg.get_metadata_lines('METADATA')
except:
lines = pkg.get_metadata_lines('PKG-INFO')
for line in lines:
@melizeche
melizeche / install_pgAdmin4.sh
Last active June 1, 2020 17:45
Easy pgAdmin4 2.0 Installer with python3 for Ubuntu
#!/bin/bash
SP_PATH=$(python3 -m site --user-site)
URL="https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v2.0/pip/pgadmin4-2.0-py2.py3-none-any.whl"
ICON="https://www.postgresql.org/message-id/attachment/1139/pgAdmin.svg"
FILE=$(echo $URL | sed 's/.*\///')
#Install pip3
echo "Installing python3-pip if not installed..."
sudo apt install -y python3-pip
#Get pgAdmin4 Python Wheel
echo "Downloading pgAdmin4..."
@melizeche
melizeche / git_backs.sh
Created November 30, 2017 21:31
Backup/clone several git repositories with all the branches, cronjob prepared
#!/bin/bash
BACKUP_DIR=~/backups/git_backups/
REPOS="[email protected]:melizeche/listaHu.git [email protected]:melizeche/dolarPy.git"
for repo in $REPOS;do
repo_dir=$(echo $repo | sed 's/.*\///')
repo_name=$(echo $repo_dir | sed 's/\.[^.]*$//')
FINAL_BACKUP_DIR=$BACKUP_DIR"`date +\%Y-\%m-\%d`/"
FINAL_REPO_DIR=$FINAL_BACKUP_DIR$repo_name
echo "Backing up "$repo_name in $FINAL_REPO_DIR
@melizeche
melizeche / bot.py
Created February 9, 2016 21:19
sample tweepy bot
#!/usr/bin/env python3
import json
import tweepy
STRING_TO_CHECK = "El texto que queres que este 'escuchando', en el caso del comentabot es su usuario"
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
@melizeche
melizeche / remove_remote_branches.sh
Last active February 5, 2016 00:16
Remove all git branches except 'master'
git for-each-ref --format '%(refname:short)' | grep -v master | sed 's/^origin\///' | sed 's/^/ git push origin :/' | bash
@melizeche
melizeche / kick_user.py
Created July 20, 2015 14:23
How to ban/kick a logged in user in django
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User
# grab the user in question
user = User.objects.get(username='johndoe')
[s.delete() for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == user.id]
user.is_active = False
user.save()
@melizeche
melizeche / kaybase.md
Created July 15, 2015 14:34
kaybase.md

Keybase proof

I hereby claim:

  • I am melizeche on github.
  • I am melizeche (https://keybase.io/melizeche) on keybase.
  • I have a public key whose fingerprint is E0BB F42A 8DB6 0C44 C823 6D78 D19B 0BC8 F7A3 4709

To claim this, I am signing this object:

@melizeche
melizeche / diputados.json
Created April 23, 2014 15:08
diputados.json
[
{
"contact_details": [
{
"type": "email",
"value": "[email protected]",
"label": "email"
}
],
"name": "Acosta Alcaráz, Edgar",
#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select