Skip to content

Instantly share code, notes, and snippets.

View henriquebastos's full-sized avatar
😏

Henrique Bastos henriquebastos

😏
View GitHub Profile
@henriquebastos
henriquebastos / postfix.sh
Created March 19, 2014 17:13
Postfix installed and basic setup
#################
# Validate Args #
#################
if [ "$#" -ne 2 ]; then
echo "Usage: $0 FQDN EMAIL"
exit 1
fi
# Postfix
@henriquebastos
henriquebastos / gist:9b491152ffc35790dd1a
Last active August 29, 2015 14:05
CSV helper for python-decouple
"""
Example:
>>> csv = Csv()
>>> csv('127.0.0.1, .localhost, .herokuapp.com')
['127.0.0.1', '.localhost', '.herokuapp.com']
>>> csv = Csv(int)
>>> csv('1,2,3,4,5')
[1, 2, 3, 4, 5]
"""
Generate PDF reports from data included in several Pandas DataFrames
From pbpython.com
"""
from __future__ import print_function
import pandas as pd
import numpy as np
import argparse
from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
@henriquebastos
henriquebastos / mf2gnc.py
Created March 27, 2015 22:36
MyFinance to GNUCash Sample Script
# coding: utf-8
"""
Hackish Script to import MyFinance data into GNUCash
The order of things:
1) Load and Fix the MyFinance dataset
2) Separete the data into intermediary parts.
3) Define GNUCash helper function.
4) Define conversion highlevel functions.
@henriquebastos
henriquebastos / large.py
Last active August 29, 2015 14:18
HappyNumbers in Python
def happy(number):
string = str(number)
digits = [int(char) for char in string]
squares = [digit**2 for digit in digits]
n = sum(squares)
if n >= 10:
return happy(n)
if n in (1, 7):
# Exemplo com closure
def crazy_sum():
acc = 0
def wrapped(t):
nonlocal acc
sum_with_acc = sum(t) + acc
acc = max(0, sum_with_acc - 9)
def main():
deck = Deck()
assert deck
assert len(deck) == 52
assert Card(rank='2', suit='spades') == Card(rank='2', suit='spades')
assert deck[0] == Card(rank='2', suit='spades')
assert deck[:2] == [Card('2', 'spades'), Card('3', 'spades')]
assert deck[12::13] == [Card('A', 'spades'), Card('A', 'diamonds'),
def main():
assert Vector(2, 4)
assert (Vector(2, 4).x, Vector(2, 4).y) == (2, 4)
assert repr(Vector(2, 4)) == 'Vector(2, 4)'
assert str(Vector(2, 4)) == '(2, 4)'
assert Vector(2, 4) == Vector(2, 4)
assert Vector(2, 4) + Vector(1, 2) == Vector(3, 6)
assert Vector(2, 4) * 2 == Vector(4, 8)
#!/usr/bin/python -tt
import argparse
from collections import Counter
import re
def purge(word):
if not word.isalpha():
word = ''.join(ch for ch in word if ch.isalpha())
return word
@henriquebastos
henriquebastos / redmine-issue-inspire_on.patch
Created March 26, 2009 03:31
Patch for Redmine to persist form state when adding multiple issues
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index cba8e59..af53ec2 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -139,6 +139,7 @@ class IssuesController < ApplicationController
if request.get? || request.xhr?
@issue.start_date ||= Date.today
+ @issue.inspire_on(params[:inspire_on]) if params[:inspire_on]
else