This file contains 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
CREATE TABLE users ( | |
id int not null, | |
email varchar(255) NOT NULL, | |
pass varchar(255) NOT NULL, | |
nick varchar(128) NOT NULL, | |
PRIMARY KEY(id) | |
); | |
CREATE OR REPLACE FUNCTION dodaj_usr (int, varchar) RETURNS boolean AS | |
' |
This file contains 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
-- query with stored plan | |
CREATE or replace FUNCTION pybench1(id int) RETURNS text AS ' | |
if (SD.has_key("plan")): | |
plan = SD["plan"] | |
else: | |
plan = plpy.prepare("SELECT * FROM pagetimer pt, pagebrowser pb WHERE pt.idtimer = $1 and pt.idtimer = pb.idtimer", ["int4"]) | |
SD["plan"] = plan | |
rec = plpy.execute(plan, [id]) | |
if (rec.nrows() > 0): |
This file contains 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
alter table towar add ftssubnpelna tsvector; | |
CREATE INDEX towar_ftssubnpelna_idx ON towar USING gin(ftssubnpelna); | |
CREATE or replace FUNCTION text_to_substrings(tekst text) RETURNS text AS $$ | |
substrings = [] | |
for tmp in tekst.split(): | |
for i in range(len(tmp)): | |
if i >= 3: | |
substrings.append(tmp[0:i]) | |
return ' '.join(substrings) |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import nntplib | |
import string | |
from email.parser import Parser | |
SERVER = "news.home.net.pl" | |
GROUP = "pl.comp.lang.python" |
This file contains 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
# appserver | |
server { | |
listen 80; | |
server_name zftemplate.desktop; | |
access_log /var/log/nginx/zftemplate.desktop.access.log; | |
error_log /var/log/nginx/zftemplate.desktop.error.log; | |
root /home/user/WorkspacePHP/zftemplate/public; | |
rewrite ^/([0-9]*)/css/(.*) /css/$2; | |
rewrite ^/([0-9]*)/js/(.*) /js/$2; |
This file contains 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 django.http import HttpResponse | |
from django.core.mail import send_mail | |
from django.template import Context | |
from django.template import loader | |
from socket import error as SocketError | |
subject = 'subject' | |
c = Context({ | |
'from': 'user@host.com', |
This file contains 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 django.utils.encoding import smart_str | |
import trml2pdf | |
filename = "advert-%s.pdf" % id | |
response = HttpResponse(mimetype='application/pdf') | |
response['Content-Disposition'] = 'attachment; filename=%s' % filename | |
t = loader.get_template('print/pdf/advert.rml') |
This file contains 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
# managers.py | |
class ModelClassApprovedOnlyManager(models.Manager): | |
def get_query_set(): | |
self.get_query_set().filter(is_approved=True) | |
# models.py | |
class ModelClass(models.Model): | |
# ... | |
all_objects = models.Manager() # first manager used in admin | |
objects = ModelClassApprovedOnlyManager() # second manager used by "objects" |
This file contains 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
# settings.py | |
MIDDLEWARE_CLASSES = ( | |
'django.contrib.messages.middleware.MessageMiddleware', | |
) | |
TEMPLATE_CONTEXT_PROCESSORS = ( | |
'django.contrib.messages.context_processors.messages', | |
) | |
INSTALLED_APPS = ( |
This file contains 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 Crypto.Cipher import DES | |
crypt_key = 'secret' | |
def crypt(what): | |
k = DES.new(crypt_key, DES.MODE_ECB) | |
return k.encrypt(what.zfill(32)) | |
def decrypt(what): |