Skip to content

Instantly share code, notes, and snippets.

View ekinertac's full-sized avatar
🥳

Ekin Ertaç ekinertac

🥳
View GitHub Profile
@ekinertac
ekinertac / validate.py
Last active December 16, 2015 23:29
Django: Validate Model Instance Count
def validate_count(obj):
model = obj.__class__
if model.objects.count() >= 8:
raise ValidationError('You can add only 8 slider objects %s' % model.__name__)
class Slider(models.Model):
# Model fields
def clean(self):
validate_count(self)
@miohtama
miohtama / gist:5389146
Created April 15, 2013 15:56
Decoding emails in Python e.g. for GMail and imapclient lib
import email
def get_decoded_email_body(message_body):
""" Decode email body.
Detect character set if the header is not set.
We try to get text/plain, but if there is not one then fallback to text/html.
:param message_body: Raw 7-bit message body input e.g. from imaplib. Double encoded in quoted-printable and latin-1
@vigo
vigo / shell-tips.md
Created November 5, 2012 00:17
Shell Tips

Shell Tips

Yazım Kuralları / Style Guide

if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi # tek satırda if

Renkler

@evildmp
evildmp / gist:3094281
Last active June 30, 2023 10:55
Set up Django, nginx and uwsgi

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

@canwe
canwe / inception-javascript.js
Created May 23, 2012 14:15 — forked from fcalderan/inception-javascript.js
inception explained as a 4 nested javascript closures
/*
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
*
* Activate javascript console =)
*/
<script>
console.group("inception movie");
@TimFletcher
TimFletcher / gunicorn_startup.sh
Created August 20, 2011 14:45
Gunicorn Startup Script
#!/bin/sh
# http://nathanvangheem.com/news/gunicorn-startup-script-for-django
# Place the script in the file - /etc/init.d/gunicorn or whatever you'd like to call it
# make it executable - chmod +x /etc/init.d/gunicorn
# And finally, wire it up - update-rc.d gunicorn defaults
ADDRESS='127.0.0.1'
PYTHON="/opt/django/bin/python"
GUNICORN="/opt/django/bin/gunicorn_django"
@brianewing
brianewing / remotemd5.py
Created May 26, 2011 23:02
Python MD5 of remote file (URL)
import os, hashlib, urllib2, optparse
def get_remote_md5_sum(url, max_file_size=100*1024*1024):
remote = urllib2.urlopen(url)
hash = hashlib.md5()
total_read = 0
while True:
data = remote.read(4096)
total_read += 4096