Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
from boto.s3.connection import S3Connection
conn = S3Connection('awskey', 'awssecret')
bucket = conn.get_bucket('awsbucket')
@arthuralvim
arthuralvim / Vagrantfile
Last active August 29, 2015 13:58
Playing with Docker.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$script = <<-SCRIPT
apt-get update
locale-gen en_US en_US.UTF-8 pt_BR pt_BR.utf8 pt_PT.utf8
dpkg-reconfigure locales
apt-get install -y --force-yes curl git
@arthuralvim
arthuralvim / provyfile-2.py
Last active August 29, 2015 13:58
Examples of Provyfile.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import AptitudeRole
from provy.more.debian import NginxRole
from provy.more.debian import SupervisorRole
from provy.more.debian import TornadoRole
from provy.more.debian import UserRole
@arthuralvim
arthuralvim / breakpoint.less
Last active August 29, 2015 14:03
Bootstrap 3 Media Queries for Breakpoints.
// Custom Iphone screen (MIN)
@screen-iphone-min: 320px !default;
// Extra small screen / phone (MIN)
@screen-xs-min: 480px !default;
// Small screen / tablet (MIN)
@screen-sm-min: 768px !default;
// Medium screen / desktop (MIN)
@screen-md-min: 992px !default;
// Large screen / wide desktop (MIN)
@screen-lg-min: 1200px !default;
@arthuralvim
arthuralvim / email_send_check.py
Created August 28, 2014 09:24
Fast check if your SMTP settings are ok.
# Enter python manage.py shell
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Message', to=['example@example.com'])
email.send()
# It should return 1 if everything is ok.
@arthuralvim
arthuralvim / serializers.py
Created September 7, 2014 22:10
[Django Rest Framework] Serializer for a PrimaryKeyRelatedField where we use a unique key instead of the primary key.
class ModelA(models.Model):
attr1 = models.Charfield()
attr2 = models.Charfield(unique=True)
class ModelB(models.Model):
foreign = models.ForeignKey(ModelA)
class OtherFieldUniqueSerializer(serializers.PrimaryKeyRelatedField):
@arthuralvim
arthuralvim / pre-commit
Created February 4, 2015 02:18
Git pre-commit hook to check if there's any debugger breakpoint inside your python files.
#!/bin/bash
pdb_check=$(git grep pdb -- '*.py')
if [ ${#pdb_check} -gt 0 ]
then
echo "COMMIT REJECTED: commit contains code with break points. Please remove before commiting."
echo $pdb_check
exit 1
else
echo "Code contains no break points"
@arthuralvim
arthuralvim / enc_example.py
Last active August 29, 2015 14:15
Encryption example.
# -*- coding: utf-8 -*-
from Crypto.Cipher import XOR
import base64
import functools
import hashlib
def func_encrypt(key, plaintext):
cipher = XOR.new(key)
@arthuralvim
arthuralvim / testing_postgres_conn.py
Created February 24, 2015 17:21
Testing Postgres Connection
#!/usr/bin/python
import psycopg2
import sys
host = ''
dbname = ''
user = ''
password = ''
port = 5432
@arthuralvim
arthuralvim / goc-2010.py
Created March 14, 2015 14:45
Google Developer Day 2010: Na pacata vila campestre de Ponteironuloville, todos os telefones têm 6 dígitos. A companhia telefônica estabelece as seguintes regras sobre os números: Não pode haver dois dígitos consecutivos idênticos, porque isso é chato; A soma dos dígitos tem que ser par, porque isso é legal; O último dígito não pode ser igual ao…
# -*- coding: utf-8 -*-
from itertools import tee
class ListaTelefones(object):
def __init__(self, lista_de_telefones):
self.telefones = lista_de_telefones.split()
self.telefones_validos = []