Skip to content

Instantly share code, notes, and snippets.

View rturowicz's full-sized avatar

Rafal Turowicz rturowicz

  • Poland
View GitHub Profile
from django.core.mail import send_mail
import os
def sendMyAppEmail(toList, template, toType=None, subject="", templateDict={}):
# Load the image you want to send at bytes
img_data = open(os.path.join(settings.MEDIA_ROOT, 'bumblebee.jpeg'), 'rb').read()
# Create a "related" message container that will hold the HTML
#!/usr/bin/env python
"""
Recipe for creating and updating security groups programmatically.
"""
import collections
import boto
(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">