This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "presentation" | |
| p_file = ARGV[0] || "presentations.txt" | |
| v_file = ARGV[1] || "votes.txt" | |
| def load_presentations(filename) | |
| result = {} | |
| open(filename) { |file| | |
| while entry = file.gets | |
| m_obj = /^(\d+):([^:]+):([^:]+)/.match(entry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ReadOnlyProxy(object): | |
| def __init__(self, target): | |
| self._target = target | |
| def __getattribute__(self, name): | |
| target = object.__getattribute__(self, '_target') | |
| return getattr(target, name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'open-uri' | |
| class UrlFetcher | |
| def fetch(url) | |
| begin | |
| open(url) { |stream| stream.read } | |
| rescue SocketError, OpenURI::HTTPError, URI::InvalidURIError, Errno::ENOENT | |
| nil | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "nokogiri" | |
| require "uri" | |
| class HtmlParser | |
| def parse(source, html_string) | |
| uri = URI.parse(source) | |
| html_doc = Nokogiri::HTML(html_string) | |
| anchors = html_doc.xpath('//a[@href!="" and not(starts-with(@href, "#"))]') | |
| links = anchors.map { |elem| | |
| elem.attribute('href').value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from threading import Thread, Event | |
| class Backend(object): | |
| reactor_started = Event() | |
| def start(self, timeout=None): | |
| print "Starting backend..." | |
| self._thread = Thread(target=self._start_reactor) | |
| self._thread.start() | |
| self.reactor_started.wait(timeout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from twisted.python import failure | |
| from twisted.internet import reactor, defer, task | |
| from twisted.internet.protocol import Protocol | |
| # Define some messages for our protocol | |
| MSG_REQUEST = '>' | |
| MSG_REQ_ACK = ':' | |
| MSG_REQ_SUCCEEDED = '=' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [alias] | |
| ci = commit | |
| lg = log --abbrev-commit --format='%C(yellow)%h %Cblue%aN %Cgreen%ar %Creset%s' | |
| co = checkout | |
| st = status | |
| loglocal = log --abbrev-commit --format='%Cgreen* %C(yellow)%h %Cblue%aN %Cgreen%ar %Creset%s' FETCH_HEAD.. | |
| logremote = "!f() { git fetch&&\ | |
| git log --abbrev-commit --format='%Cred* %C(yellow)%h %Cblue%aN %Cgreen%ar %Creset%s' ..FETCH_HEAD;\ | |
| }; f" | |
| changes = "!f() { echo 'REMOTE CHANGES:\n---------------';\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from twisted.internet import defer | |
| import threading | |
| import Queue | |
| from twisted.python import failure | |
| def blocking_call_from_thread(reactor, f, *args, **kwargs): | |
| """Calls a twisted function from a thread and blocks until | |
| the deferred has called back. | |
| If the function did not return a deferred, raise an exception. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from adb import protocol | |
| data = ( | |
| '\x4f\x50\x45\x4e\x02\x00\x00\x00' | |
| '\x00\x00\x00\x00\x09\x00\x00\x00' | |
| '\x31\x03\x00\x00\xb0\xaf\xba\xb1' | |
| '\x73\x68\x65\x6c\x6c\x3a\x6c\x73' | |
| '\x00' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CacheCallable(object): | |
| """Callable that cache results based on given arguments | |
| """ | |
| def __init__(self, func): | |
| self.func = func | |
| self.cache = {} | |
| def __call__(self, *args): | |
| try: | |
| return self.cache[args] |
OlderNewer