Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import email
import sys
def walk(stdin_data):
"""Prepend alert to all parts of the message."""
root_message = email.message_from_string(stdin_data)
f = open('/tmp/ids_logs.txt', 'a')
$(function () {
$.fn.exchangePositionWith = function(selector) {
var other = $(selector);
this.after(other.clone());
other.after(this).remove();
};
$(document).on('click', '.fa-chevron-down', function () {
var ul = $(this).parents('ul'),
li_index = $(this).parents('li').index();
@exit99
exit99 / render_script
Last active August 29, 2015 14:11
How to run django scripts in supervisord
#! /usr/bin/env python
from time import sleep
if __name__ == "__main__":
while True:
do_stuff()
sleep(1)
@exit99
exit99 / cool_script.py
Created December 15, 2014 17:52
Running python scripts with postfix
# Be sure to chmod +x
#!/usr/bin/env python
import email
import json
import sys
import requests
@exit99
exit99 / emai_settings.py
Created January 21, 2015 18:56
Connecting via Imap to Gmail
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'YOUR GMAIL USERNAME'
EMAIL_HOST_PASSWORD = 'YOUR GMAIL PASSWORD'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = 'YOUR FROM EMAIL FOR SENDING EMAIL'
SERVER_EMAIL = 'SAME AS ABOVE'
"""
There is also a setting in gmail to have to do. "Allow less secure apps" has to be True.
@exit99
exit99 / Flask Shell
Created February 10, 2015 15:22
Flask shell with a manage.py
#!/usr/bin/env python
import sys
from flask.ext.script import Manager
from null.app import create_app
app = create_app()
manager = Manager(app)
@exit99
exit99 / sqla_encoder.py
Created February 20, 2015 15:52
Json encode sqlalchemy models
class AlchemyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj.__class__, DeclarativeMeta):
# a SQLAlchemy class
fields = {}
for field in [x for x in dir(obj)
if not x.startswith('_') and x != 'metadata']:
data = obj.__getattribute__(field)
if field == "discount": data = unicode(data)
try:
import csv
from random import randint, randrange
with open('stuff.txt', 'r') as f:
groups = {}
current = ""
for line in f.readlines():
if line.endswith("[edit]\n"):
current = line.strip('[edit]\n ')
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>4. Django Basics &mdash; How to Tango with Django 1.7</title>
@exit99
exit99 / products.py
Last active August 29, 2015 14:23
On django==1.6
class ProductCategory(models.Model):
name = models.CharField(max_length=50)
priority = models.IntegerField()
slug = models.CharField(max_length=50, unique=True)
class Meta:
ordering = ['priority']
class AbstractProduct(models.Model):