Skip to content

Instantly share code, notes, and snippets.

View ivanrvpereira's full-sized avatar

Ivan Pereira ivanrvpereira

  • Promptly Health Analytics
  • Portugal
View GitHub Profile
@ivanrvpereira
ivanrvpereira / b64tojson.py
Created May 16, 2016 14:46
Converts base64 application/x-python-serialize in rabbitmq to human readable json for easier debug
import click
import base64
import pickle
import pprint
@click.command()
@click.argument('b64body')
@click.option('--indent', default=2, type=int)
def unserialize(b64body, indent):
@ivanrvpereira
ivanrvpereira / range.sh
Created April 17, 2015 15:12
Simple script to iterate over range of dates
#!/bin/bash
read -p "From: " from
read -p "To: " to
command='echo'
start=`date +"%Y-%m-%d" -d $from`
end=`date +"%Y-%m-%d" -d $to`
while [ "$start" != "$end" ] ;

Mac OS X 10.10 Yosemite

Custom recipe to get OS X 10.10 Yosemite running from scratch, setup applications and developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

Install Software

@ivanrvpereira
ivanrvpereira / createapp.sh
Last active August 29, 2015 14:08
Simple script to automate debian + nginx + uwsgi emperor vassals + mysql
#!/bin/sh
# Author: Ivan Pereira
# Useful guide: http://bradenmacdonald.com/blog/2013/hosting-django-apps-ubuntu-nginx-uwsgi
# Mysql: needs to have .my.cnf on home folder with credentials
read -p "name of app? " APPNAME
echo $APPNAME
useradd -d /home/$APPNAME -G www-data -m -U -s /bin/bash $APPNAME
H="/home/$APPNAME"
]
2014-10-15 23:25:02 INFO 21303 Reconnecting after 10 seconds ...
2014-10-15 23:30:20 INFO 21398 Establishing TCP connection to smpp.clickatell.com:2775
2014-10-15 23:30:20 INFO 21398 Connecting to IPv4Address(TCP, 'smpp.clickatell.com', 2775) ...
2014-10-15 23:30:21 WARNING 21398 Connection established
2014-10-15 23:30:21 INFO 21398 Connection made to smpp.clickatell.com:2775
2014-10-15 23:30:21 WARNING 21398 Requesting bind as transceiver
2014-10-15 23:30:21 WARNING 21398 Bind succeeded...now in state BOUND_TRX
2014-10-15 23:38:00 ERROR 21398 Optional Parameter not allowed: Optional param network_error_code unknown
Traceback (most recent call last):
@ivanrvpereira
ivanrvpereira / www.conf
Created August 19, 2014 09:51
nginx drupal 7 conf
server {
server_name _;
root /path/to/www; ## <-- Your only path reference.
# Enable compression, this will help if you have for instance advagg‎ module
# by serving Gzip versions of the files.
gzip_static on;
location = /favicon.ico {
log_not_found off;
@ivanrvpereira
ivanrvpereira / booklet.py
Created July 19, 2014 11:15
Generates booklets
def gen_booklet(pages):
# se nao for multiplo de 4
if (len(pages) % 4 != 0):
# extende a lista ate ser multiplo de 4
# 'E' significa Empty page
pages += ['E'] * (4 - len(pages) % 4)
res = []
for i, v in enumerate(pages):
class ValidateModelMixin(object):
"""Make :meth:`save` call :meth:`full_clean`.
.. warning:
This should be the left-most mixin/super-class of a model.
Do you think Django models ``save`` method will validate all fields
(i.e. call ``full_clean``) before saving or any time at all? Wrong!
@ivanrvpereira
ivanrvpereira / my.cnf
Last active August 29, 2015 14:03
Percona Mysql configurantion for a 4GB VPS
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysql]
# CLIENT #
port = 3306
socket = /var/run/mysqld/mysqld.sock

Writing better python code


Swapping variables

Bad code