Skip to content

Instantly share code, notes, and snippets.

View guilhermebr's full-sized avatar
🇧🇷
Working from home

Guilherme Rezende guilhermebr

🇧🇷
Working from home
View GitHub Profile
@guilhermebr
guilhermebr / contador.py
Created December 11, 2012 02:11
OOPY3 Exercicio1
# coding: utf-8
"""
Código inicial usado na Lista de Exercícios 1 do curso
"Objetos Pythonicos" de Luciano Ramalho, Oficinas Turing.
"""
class Contador(object):
def __init__(self):
self.ocorrencias = {}
@guilhermebr
guilhermebr / beautifulString.md
Last active December 11, 2015 21:09
Facebook Hackercup 2013

Beautiful Strings

When John was a little kid he didn't have much to do. There was no internet, no Facebook, and no programs to hack on. So he did the only thing he could... he evaluated the beauty of strings in a quest to discover the most beautiful string in the world.

Given a string s, little Johnny defined the beauty of the string as the sum of the beauty of the letters in it.

The beauty of each letter is an integer between 1 and 26, inclusive, and no two letters have the same beauty. Johnny doesn't care about whether letters are uppercase or lowercase, so that doesn't affect the beauty of a letter. (Uppercase 'F' is exactly as beautiful as lowercase 'f', for example.)

You're a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible beauty of this string?

@guilhermebr
guilhermebr / balancedSmileys.md
Last active December 11, 2015 21:09
Facebook Hackercup 2013

Balanced Smileys

Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through emoticons, he hates unbalanced parenthesis so much that it makes him go :(

Sometimes he puts emoticons within parentheses, and you find it hard to tell if a parenthesis really is a parenthesis or part of an emoticon.

A message has balanced parentheses if it consists of one of the following:

  • An empty string ""

Find the Min

After sending smileys, John decided to play with arrays. Did you know that hackers enjoy playing with arrays? John has a zero-based index array, m, which contains n non-negative integers. However, only the first k values of the array are known to him, and he wants to figure out the rest.

John knows the following: for each index i, where k <= i < n, m[i] is the minimum non-negative integer which is not contained in the previous k values of m.

For example, if k = 3, n = 4 and the known values of m are [2, 3, 0], he can figure out that m[3] = 1.

John is very busy making the world more open and connected, as such, he doesn't have time to figure out the rest of the array. It is your task to help him.

# coding: utf-8
u"""
Redimensionamento proporcional de imagem, com base na altura, feito com um simples cálculo de proporção.
Ex:
+------+ 10 15 (altura desejada para a nova imagem)
| | -- x --
| 10x5 | 5 x (largura proporcional a nova altura)
| |
+------+ (10 x x) = (5 x 15)
10x = 75
@guilhermebr
guilhermebr / PySorteio.py
Created August 27, 2013 01:25
Codigo para sorteio de entradas no evento http://www.joincommunity.com.br
'''
Codigo para sorteio de entradas no evento http://www.joincommunity.com.br
@guilhermebr - Guilherme Rezende <guilhermebr@gmail.com>
'''
import urllib
import json
from random import shuffle, choice
#token temporario(1h) obtido em https://developers.facebook.com/tools/explorer
// This systemd runs iptables-restore on boot:
[Unit]
Description=Packet Filtering Framework
DefaultDependencies=no
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/iptables-restore /opt/docker/scripts/iptables/iptables.rules
package main
import (
"os"
"runtime"
"syscall"
"time"
"github.com/Sirupsen/logrus"
"github.com/opencontainers/runc/libcontainer"
package main
import (
"os"
"runtime"
"syscall"
"time"
"github.com/Sirupsen/logrus"
"github.com/opencontainers/runc/libcontainer"
package main
import (
"os"
"runtime"
"syscall"
"time"
"github.com/Sirupsen/logrus"
"github.com/opencontainers/runc/libcontainer"