Skip to content

Instantly share code, notes, and snippets.

class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise Singleton.__single
Singleton.__single = self
def Handle(x = Singleton):
try:
single = x()
tanel@mave:~$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation 82G33/G31 Express Integrated Graphics Controller (rev 0a)
tanel@mave:~$ sudo lshw -C video
[sudo] password for tanel:
*-display:0
description: VGA compatible controller
product: 82G33/G31 Express Integrated Graphics Controller
vendor: Intel Corporation
physical id: 2
bus info: pci@0000:00:02.0
#!/usr/bin/env python
'Downloads tumblr images from dashboard'
import urllib
import os
from time import sleep
import simplejson as json
from threading import Thread
from Queue import Queue
MY_QUEUE = Queue()
# ~n === -(n+1)
#~-1 === 0
def in_string(text, search):
return not ( not ( ~text.find(search) ))
assert in_string('abcde', 'e')
assert in_string('abcde', 'cde')
assert not in_string('abcde', 'x')
@tanelpuhu
tanelpuhu / heederid
Created October 27, 2011 15:18
kolm faili ühte... umbes nii?
self.response.headers['Content-Type'] = 'application/zip'
self.response.headers['Content-Disposition'] = 'attachment; filename="example.zip"'
self.response.headers['Content-Length'] = len(text)
self.response.headers['Content-Transfer-Encoding'] = 'binary'
self.response.out.write(text)
def render(view, data = None):
current_dir = os.path.dirname(__file__)
path = os.path.abspath(
os.path.join(current_dir, '..', 'views', '%s.html' % view)
)
if not os.path.exists(path):
return '404 - view not found!'
if data is None:
data = {}
return template.render(path, data)
@tanelpuhu
tanelpuhu / gist:1482536
Created December 15, 2011 19:46
has_falsy
def has_falsy(lst):
def is_falsy(val):
return not val
return not not len(filter(is_falsy, lst))
assert not has_falsy([])
assert not has_falsy([1,2,3])
assert not has_falsy(['0'])
assert not has_falsy(['None'])
assert has_falsy([None])
gsettings set com.canonical.Unity.Panel systray-whitelist "['all']"
@tanelpuhu
tanelpuhu / prereindent.py
Created January 23, 2013 07:47
reindent.py replaces tabs in litterals
#!/usr/bin/env python
import sys
import os
if len(sys.argv) < 2:
print os.path.basename(sys.argv[0]), 'path'
sys.exit()
def handle_file(directory, file):
fullpath = os.path.join(directory, file)
@tanelpuhu
tanelpuhu / dotjs.py
Created February 26, 2013 17:59
~/.js (python)
#!/usr/bin/env python
# github.com/kasun/YapDi.git
import yapdi
from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
import ssl
import sys
import os