Skip to content

Instantly share code, notes, and snippets.

View rbrito's full-sized 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

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
# -*- coding: utf-8 -*-
import string
import re
INPUT_FILE = 'balanced_smileystxt.txt'
input = open(INPUT_FILE, 'r')
@rbrito
rbrito / brightness.py
Created February 11, 2013 07:44
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
import os
import platform
import sys
print platform.system()
print sys.platform
print os.name
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')
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()
@rbrito
rbrito / 0001-lisp-custom-faces-.el-Partial-revert-of-commit-aac2b.patch
Created November 24, 2014 21:45
lisp/{custom,faces}.el: Partial revert of commit aac2b67
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.
---
@rbrito
rbrito / funny.py
Created April 30, 2015 12:50
Doubly encoded URLs in coursera.
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 / gist:59736ed280e569619e84
Created June 4, 2015 02:55
Output from tox on edx-downloader
$ tox
GLOB sdist-make: /home/rbrito/Desktop/cursos/edx-downloader/setup.py
py27 inst-nodeps: /home/rbrito/Desktop/cursos/edx-downloader/.tox/dist/edx-dl-0.0.zip
py27 runtests: PYTHONHASHSEED='3787261654'
py27 runtests: commands[0] | py.test -v --junitxml=/home/rbrito/Desktop/cursos/edx-downloader/.tox/py27/log/result.xml .
======================================================= test session starts ========================================================
platform linux2 -- Python 2.7.10 -- py-1.4.28 -- pytest-2.7.1 -- /home/rbrito/Desktop/cursos/edx-downloader/.tox/py27/bin/python2.7
rootdir: /home/rbrito/Desktop/cursos/edx-downloader, inifile:
collected 7 items
@rbrito
rbrito / README.md
Last active November 2, 2015 16:18 — forked from hubgit/README.md
Remove metadata from a PDF file, using exiftool and qpdf. Note that embedded objects may still contain metadata.

Anonymising PDFs

PDF metadata

Metadata in PDF files can be stored in at least two places:

  • the Info Dictionary, a limited set of key/value pairs
  • XMP packets, which contain RDF statements expressed as XML

PDF files