Skip to content

Instantly share code, notes, and snippets.

View brenolf's full-sized avatar
🦆

Breno Freitas brenolf

🦆
View GitHub Profile
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
from itertools import combinations
from itertools import product
from sqlalchemy.types import *
# Conexao para o BD
engine = create_engine('postgres://breno@127.0.0.1:5432/dw')
@brenolf
brenolf / deploy.sh
Last active October 31, 2016 23:28
Script for deploying yeoman projects to either staging or production environment on Heroku
#!/bin/bash
PROJECT=name;
if [[ "$1" == "staging" || "$1" == "production" ]]; then
TARGET=`echo "$1" | tr '[:lower:]' '[:upper:]'`;
read -p "Do you really wish to deploy to $TARGET? [yn] " yn;
if [[ "$yn" != "y" ]]; then
@brenolf
brenolf / crawler.js
Last active August 25, 2016 20:23
SPOJ Crawler
'use strict';
// user=brenolf password='xxxxx' node crawler.js
const USER = process.env.user;
const PASSWORD = process.env.password;
const co = require('co');
const rp = require('request-promise');
@brenolf
brenolf / retirement.py
Created February 14, 2016 21:50
Calculation for retirement/investment
monthly_investment = 2 # x1000
savings = 0
years = 0
while savings < 1000:
savings = (savings + 12 * monthly_investment) * 1.05
years += 1
print years, savings
@brenolf
brenolf / HomeController.js
Last active December 16, 2015 18:37
ES6 + co express example
'use strict'
// using bookshelf.js
const Model = require('../models/Model')
module.exports = class Controller {
static *read (request, response) {
const count = yield Model.org(request.organization).count()
response.ok()
let lines = [];
export default class Grid {
constructor (game, rows, columns) {
if (game === undefined || columns === undefined || rows === undefined) {
throw new TypeError();
}
let w = Math.floor(game.width / columns);
let h = Math.floor(game.height / rows);
@brenolf
brenolf / sum.c
Last active November 13, 2015 01:26
Finds whether or not it is possible to find three elements from three arrays such that they sum up to a given value
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int a[MAX], b[MAX], c[MAX], n;
int cmp (const void *a, const void *b) {
return *((int*) a) - *((int*) b);
}
MAX = 1500
def stringfy(number)
text = ''
begin
remainder = number % 26
text += (remainder + 'a'.ord).chr
number = number / 26
end while number > 0
@brenolf
brenolf / babel.js
Last active August 29, 2015 14:20
Private attributes and attribute accessors using decorators
import * from './privatize.js';
let token = Symbol(); // this is a class secret!
export class Babel {
@attr_accessor // <- create getters and setters
@privatize(token) // <- private attributes turns into functions `fun (token, ...args)`
lang;
@attr_accessor
@brenolf
brenolf / MoveAll.py
Last active August 29, 2015 14:11
Batch rename files in a folder (used for renaming shows in folder)
#!/usr/bin/python
import sys
from os import listdir, rename
from os.path import isfile, join, splitext
import re
import argparse
########################################################################################################################
########################################################################################################################