Skip to content

Instantly share code, notes, and snippets.

Having (YET another) kidney stone surgery in a few days...

Rogério Brito rbrito

Having (YET another) kidney stone surgery in a few days...
View GitHub Profile
rbrito /
Created Apr 30, 2015
Doubly encoded URLs in coursera.
import urllib
# Some silly people put invalid URLs like this:
# ''
# as resources for students to download. We work around incompetence
# because, well, we are not like them.
s = ''
rbrito / 0001-lisp-custom-faces-.el-Partial-revert-of-commit-aac2b.patch
Created Nov 24, 2014
lisp/{custom,faces}.el: Partial revert of commit aac2b67
View 0001-lisp-custom-faces-.el-Partial-revert-of-commit-aac2b.patch
From 124b8da812896eee004d9243122781118298f627 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rog=C3=A9rio=20Brito?= <>
Date: Sun, 23 Nov 2014 16:45:12 -0200
Subject: [PATCH] lisp/{custom,faces}.el: Partial revert of commit aac2b67.
There were conflicts and I resolved them in the simplest (and most
naive) way, which is probably quite incorrect.
Still, this makes Emacs from master work back again for me.
import mutagen
tags = mutagen.File('foo.m4a')
tags # {'\xa9too': [u'Lavf55.33.100']}
tags[''] = ['-10.44 dB']
tags # {'\xa9too': [u'Lavf55.33.100'], '': ['-10.44 dB']}
import daap
client = daap.DAAPClient()
session = client.login()
db = session.library()
tracks = db.tracks()
#!/usr/bin/env python
import os
import platform
import sys
print platform.system()
print sys.platform
rbrito /
Created Feb 11, 2013
Script to control monitor brightness
#!/usr/bin/env python
Python script to essentially perform the same as:
gdbus call \
--session \
--dest org.gnome.SettingsDaemon \
--object-path /org/gnome/SettingsDaemon/Power \
--method org.gnome.SettingsDaemon.Power.Screen.SetPercentage 75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
import re
INPUT_FILE = 'balanced_smileystxt.txt'
input = open(INPUT_FILE, 'r')
View Facebook Hackercup

Disclaimer: I have no idea if this are indeed the correct answers. I just solved the exercises like this. I think that they are right though.

I have added my own code to this gist. It is ugly as hell, just like you can expect from code created in a contest like this.

Beautiful Strings

Difficulty: easy

It is simple to see that a greedy solution is good enough.

#!/usr/bin/env python
import re
def is_balanced(text):
"""Given text containing only braces ((, ), {, }), returns `True`
if they can be balanced. Returns `False` otherwise.
Curly braces ({ and }) are treated as optional.
View Evolution of a Python
#Newbie programmer
def factorial(x):
if x == 0:
return 1
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal