Skip to content

Instantly share code, notes, and snippets.

@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)
# ~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')
#!/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()
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
class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise Singleton.__single
Singleton.__single = self
def Handle(x = Singleton):
try:
single = x()
import unittest
class myTest(unittest.TestCase):
def testTest(self):
self.assertTrue(True)
self.assertFalse(False)
self.assertEquals(1,1)
tests = unittest.TestSuite()
tests.addTest(unittest.makeSuite(myTest))
@tanelpuhu
tanelpuhu / get_filename.py
Created February 14, 2011 07:01
kas on piisav?
import os
#Nii funkab ka
def get_filename(value):
if isinstance(value, basestring):
i = max(value.rfind('/'), value.rfind('\\'))
if i > 0:
value = value[i+1:]
return value
limit_arguments = {
'peer-limit': int(config.get('peer-limit', 30)),
'uploadLimit': int(config.get('uploadLimit', 25)),
'uploadLimited': [False,True][int(config.get('uploadLimit', 25)) > 0],
'seedRatioLimit':float(config.get('seedRatioLimit', 1.5)),
'seedRatioMode':[0,1][float(config.get('seedRatioLimit', 1.5)) > 0],
'seedRatioLimited':[False,True][float(config.get('seedRatioLimit', 1.5)) > 0],
'ids':[]
}
...
a = """
tekst
%s
tekst
%s
""" % (1,2)
#or
a = """
Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
document.write((123456.78).formatMoney(2, ',', ' ')) //123 456,78