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
@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

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')
#!/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.
"""
@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

#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
--- a/example-clients/transport.c
+++ b/example-clients/transport.c
@@ -300,11 +300,11 @@
/* Isolate the command word. */
i = 0;
- while (line[i] && whitespace(line[i]))
+ while (line[i] && isspace(line[i]))
i++;
word = line + i;
@rbrito
rbrito / LICENSE.txt
Created February 20, 2012 01:31 — forked from aemkei/LICENSE.txt
Binary Tetris - 140byt.es
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@rbrito
rbrito / Javascript.js
Created February 16, 2012 10:55
Proposal of changes for Javascript.js
/*
* iTunes Javascript Class, added to the displayed pages.
* Catches iTunes-api calls from pages, such as
* http://r.mzstatic.com/htmlResources/6018/dt-storefront-base.jsz
*/
/*global window */
iTunes = { // All called from the page js:
getMachineID: function () {
@rbrito
rbrito / gist:1793354
Created February 10, 2012 22:03
Unittests before changes
# -*- coding: utf-8 -*-
import sys
import unittest
sys.path.append('src')
sys.path.append('../src')
from common import *