Skip to content

Instantly share code, notes, and snippets.

Avatar
☹️
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
rbrito / funny.py
Created Apr 30, 2015
Doubly encoded URLs in coursera.
View funny.py
import urllib
# Some silly people put invalid URLs like this:
#
# 'https://d396qusza40orc.cloudfront.net/webapplications/https%3A//d396qusza40orc.cloudfront.net/webapplications/lecture_slides/M6-L8-Ajax-Handout.pdf'
#
# as resources for students to download. We work around incompetence
# because, well, we are not like them.
s = 'https://d396qusza40orc.cloudfront.net/webapplications/https%3A//d396qusza40orc.cloudfront.net/webapplications/lecture_slides/M6-L8-Ajax-Handout.pdf'
@rbrito
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?= <rbrito@ime.usp.br>
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.
---
View create_m4a_tags.py
import mutagen
tags = mutagen.File('foo.m4a')
tags # {'\xa9too': [u'Lavf55.33.100']}
tags['----:com.apple.iTunes:replaygain_track_gain'] = ['-10.44 dB']
tags # {'\xa9too': [u'Lavf55.33.100'], '----:com.apple.iTunes:replaygain_track_gain': ['-10.44 dB']}
tags.save()
View daap.py
import daap
client = daap.DAAPClient()
client.connect('192.168.1.100')
session = client.login()
db = session.library()
tracks = db.tracks()
tracks[0].save('/tmp/foo.mp3')
View system_detector.py
#!/usr/bin/env python
import os
import platform
import sys
print platform.system()
print sys.platform
print os.name
@rbrito
rbrito / brightness.py
Created Feb 11, 2013
Script to control monitor brightness
View brightness.py
#!/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
View balanced_smileys.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
import re
INPUT_FILE = 'balanced_smileystxt.txt'
input = open(INPUT_FILE, 'r')
View Facebook Hackercup Solutions.md

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.

View smileys.py
#!/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 programmer.py
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal