Skip to content

Instantly share code, notes, and snippets.

View sporsh's full-sized avatar

Geir Sporsheim sporsh

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sporsh on github.
  • I am sporsh (https://keybase.io/sporsh) on keybase.
  • I have a public key whose fingerprint is 2657 83C9 C0CD A7D3 00FA 9114 8A18 E5D2 F087 D6B5

To claim this, I am signing this object:

@sporsh
sporsh / tally.rb
Created February 7, 2012 13:55 — forked from jimweirich/presentation.rb
Vital Ruby Lab 4
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)
@sporsh
sporsh / read_only_proxy.py
Created February 8, 2012 08:44 — forked from jimweirich/read_only_proxy.rb
Vital Ruby Lab 5
class ReadOnlyProxy(object):
def __init__(self, target):
self._target = target
def __getattribute__(self, name):
target = object.__getattribute__(self, '_target')
return getattr(target, name)
@sporsh
sporsh / url_fetcher.rb
Created February 9, 2012 10:27 — forked from jimweirich/url_fetcher.rb
Vital Ruby Advanced Lab 1
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
@sporsh
sporsh / html_parser.rb
Created February 9, 2012 12:54 — forked from jimweirich/html_parser.rb
Vital Ruby Advance Lab 2
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
@sporsh
sporsh / .gitconfig
Last active October 12, 2015 01:47
git changes - Alias to get a quick overview of local and remote changes in current branch
[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---------------';\
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.
"""
@sporsh
sporsh / backend.py
Created October 16, 2012 22:34
twisted interactive shell
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)
from twisted.internet.protocol import Protocol
import re
class ShellProtocol(Protocol):
"""Define a generic shell-like protocol:
[login-prompt [input-echo]]
[password-prompt] [input-echo]]
[greeting]
[prompt]
[input-echo]
@sporsh
sporsh / index.html
Last active March 25, 2016 14:40
Astigmatism eye test (see live: https://goo.gl/TVVnVO)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Astigmatism eye test</title>
<style>
canvas {
position: fixed;
top: 0;