Skip to content

Instantly share code, notes, and snippets.

View viniciusban's full-sized avatar

Vinicius Assef viniciusban

  • Rio de Janeiro, Brazil
View GitHub Profile
@viniciusban
viniciusban / adjust_mp3_tags.py
Created March 31, 2013 11:50
How to easily adjust tags of your MP3 files
import glob
# Uses Mutagen package (http://code.google.com/p/mutagen)
# Followed this simple tutorial: http://code.google.com/p/mutagen/wiki/Tutorial
from mutagen.easyid3 import EasyID3
# en: adjust title and tracknumber based on filenames like
# this: "001 My Beautiful Music.mp3"
# pt: ajusta titulo e numero da musica a partir do nome
# do arquivo assim: "001 Minha Música Preferida.mp3"
@viniciusban
viniciusban / bind_function_to_instance.py
Last active December 16, 2015 21:09
Make a function be a new member of an instance object
# create the tables
db.define_table('person',
Field('name'),
Field('gender'),
Field('birthdate', 'date'))
db.define_table('animal',
Field('name'),
Field('gender'),
@viniciusban
viniciusban / sed-recursive-in-place-substitution.sh
Last active December 24, 2015 10:39
Makes a recursive sed in place substitution.
#!/usr/bin/env bash
# Makes sed a recursive in place substitution and
# create backup of original files with .bkp extension.
old=$1
new=$2
sed -i.bkp "s/${old}/${new}/g" $(grep -ril "${old}" .)
@viniciusban
viniciusban / sou_eu.py
Created January 10, 2014 10:22
How to customize object's equality test in Python
class Pessoa(object):
def __init__(self, nome, endereco):
self.nome = nome
self.endereco = endereco
def __eq__(self, outra):
if self.nome == outra.nome:
return True
else:
return False
@viniciusban
viniciusban / aws_eb_tuto.md
Created March 19, 2014 15:14
AWS EB tuto

AWS Elastic Beanstalk

This document is divided into 2 main parts:


@viniciusban
viniciusban / root-and-inside-vm.sh
Last active August 29, 2015 13:57
Do I have root privileges? Am I inside the Vagrant VM?
# Do I have root privileges?
# Also known as: Am I running with sudo?
if [ $EUID -ne 0 ]; then
echo "You must run the script as root or using sudo"
exit 1
fi
# Am I inside the Vagrant VM?
@viniciusban
viniciusban / tira_acentos.py
Last active August 29, 2015 14:03
tirar acentos de uma string
from unicodedata import normalize
def tira_acentos(s):
return normalize("NFKD", s.decode("utf-8")).encode("ASCII", "ignore")
@viniciusban
viniciusban / map_which_fields_are_filled_or_not.js
Last active August 29, 2015 14:04
[javascript] Which fields are filled or empty in my form?
var map_which_fields_are_filled_or_not = function (form_id) {
/* for each field on form, recognize if it's filled or not.
Returns:
- {
"field_a": true, // filled
"field_b": false // empty (not filled)
}
*/
@viniciusban
viniciusban / tira_acentos_do_form.py
Last active August 29, 2015 14:06
Transforma um dicionario unicode em json e tira os acentos de tudo.
# -*- coding: utf-8 -*-
'''Transforma um dicionario unicode em json e tira os acentos de tudo.'''
import json
from unicodedata import normalize
dados_em_utf8 = {u'texto': u'n\xe3o sei de nada.'}
print '- Dados que vieram do form em utf-8:', dados_em_utf8
@viniciusban
viniciusban / data_eh_valida.js
Last active August 29, 2015 14:06
Valida data no formato dd/mm/aaaa
/*
* Exemplos de como usar e resultados:
* - data_eh_valida("25/01/2014") => true
* - data_eh_valida("25/01/14") => false - ano precisa ter 4 digitos
* - data_eh_valida("29/02/2015") => false - 29/02 em ano nao bisexto
* - data_eh_valida("32/07/2014") => false - dia invalido
* - data_eh_valida("25/13/2014") => false - mes invalido
*/
var data_eh_valida = function (data_str) {