Skip to content

Instantly share code, notes, and snippets.

View rturowicz's full-sized avatar

Rafal Turowicz rturowicz

  • Poland
View GitHub Profile
(r'^articles/(?P<year>\d{4}/?$, 'main.views.year'),
# When a use case comes up that a month needs to be involved as
# well, you add an argument in your regex:
(r'^articles/(?P<year>\d{4}/(?P<month>\d{2})/?$, 'main.views.year_month'),
# That works fine, unless of course you want to show something
# different for just the year, in which case the following case can be
# used, making separate views based on the arguments as djangoproject
MessageDigest digest;
byte[] hash;
String name = "http://test.com/d0d5689be9f9c8b5.jpg";
try {
digest = java.security.MessageDigest.getInstance("MD5");
digest.update(name.getBytes("UTF-8"));
hash = digest.digest();
BigInteger bigInt = new BigInteger(1, hash);
String hashtext = bigInt.toString(16);
while(hashtext.length() < 32 ){
import hashlib
m = hashlib.md5()
m.update("http://test.com/d0d5689be9f9c8b5.jpg")
print m.hexdigest()
@rturowicz
rturowicz / sitemap.py
Created March 23, 2013 13:07
django - sitemap
# urls.py
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
info_dict = {
'queryset': Entry.objects.all(),
'date_field': 'pub_date',
}
sitemaps = {
import os
import zipfile
zf = zipfile.ZipFile("myzipfile.zip", "w")
for dirname, subdirs, files in os.walk("mydirectory"):
zf.write(dirname)
for filename in files:
zf.write(os.path.join(dirname, filename))
zf.close()
@rturowicz
rturowicz / ajax.js
Last active December 15, 2015 07:59
JQuery ajax
$.post('/faq/next/',
{'zmienna':'wartosc'},
function(data) {
alert(data.question);
},
"json"
);
$.ajax({
type: "POST",
@rturowicz
rturowicz / jquery_forms.js
Last active December 15, 2015 07:59
JQuery forms
// basic
$(document).ready(function() {
$('#contact').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
<form action="/" method="post" id="contact">
</form>
@rturowicz
rturowicz / apache_zf.conf
Last active December 15, 2015 07:59
apache2 zend framework application vhost
#application:
<VirtualHost *:80>user
DocumentRoot "/home/user/WorkspacePHP/zftemplate/public"
ServerAdmin user@post.pl
ServerName zftemplate.desktop
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/home/user/WorkspacePHP/zftemplate/public">
# send to rabbitmq (celery task)
import pika
import simplejson
credentials = pika.credentials.PlainCredentials('user', 'pass')
connection = pika.BlockingConnection(
pika.ConnectionParameters(
host='localhost',
virtual_host='/vhost_name',
credentials=credentials
@rturowicz
rturowicz / des.py
Last active December 15, 2015 07:59
data ecryption (des)
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):