Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
'''
BeautifulSoup is required:
http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.2.1.tar.gz
'''
from BeautifulSoup import BeautifulSoup as soup
from urllib import urlopen as uopen, urlretrieve
import re, os, errno, subprocess as sp, threading
from time import sleep
from urlparse import urljoin
class AssignOnce:
''' Descriptor, which prevents accidential overwriting of attributes:
>>> class T:
... a = AssignOnce('a')
...
>>> t = T()
>>> t.a
>>> t.a = 3
>>> t.a = 4
Traceback (most recent call last):
@Sorseg
Sorseg / file_count.py
Created May 18, 2013 02:06
Count all files in . and subfolders of .
import os; print sum(len(f) for _,_,f in os.walk("."))
#!/usr/bin/python3
#Grabbing pics from nightmaresfearfactory galleries
import re, sys, os
import concurrent.futures
import urllib.request
sfolder = 'pics'
os.makedirs(sfolder,exist_ok=True)
os.chdir(sfolder)
# параметр сглаживания
a = 1/100
# аппроксимация модуля
ma = (a + x^2)^(1/2)
# выражение максимума через модуль
var('xm1 xm2')
xmax=1/2*(ma(xm1-xm2) + xm1 + xm2)
var_names = 'x1 x2 x3 x4'
args = var(var_names)
@Sorseg
Sorseg / chat.py
Last active December 29, 2015 10:39
#!/usr/bin/env python3
import tkinter as tk
import tkinter.ttk as ttk
from threading import Thread
import socket
PORT=1235
root = tk.Tk()
root.title('QIP 0.0')
def conc(text):
return ''.join(c.split('(')[0]+c.split('(')[1][::-1]
if '(' in c
else c
for c in text.split(')'))
print(conc('(ur)ss(ai)(edocn)c(pu)'))
from queue import Empty, Queue
import subprocess
import sys
import threading
if sys.version[0] > '2':
import tkinter
else:
import Tkinter as tkinter
img = gimp.image_list()[0]
n = len(img.layers)
for i, l in enumerate(img.layers):
l.opacity = 100.0/(n-i)
""" Thanks to http://speakrus.ru/dict/ """
import random
f = open('pldf-win.txt', encoding='cp1251')
words = f.read().split('\n')
def gen():
message = ' '.join(random.choice(words) for _ in range(random.randint(2, 6)))
message = message[0].upper()+message[1:]