Skip to content

Instantly share code, notes, and snippets.

View hzbd's full-sized avatar
I may be slow to respond.

hzbd

I may be slow to respond.
View GitHub Profile
@hzbd
hzbd / gist:4723104
Created February 6, 2013 15:01 — forked from saga/gist:4137880
#!/usr/bin/env python
import simplejson
import logging
import random
import re
import datetime
import string
import time
import sys
import urllib
@hzbd
hzbd / Json_encoder.py
Created February 11, 2013 05:38
Implementation of JSONEncoder
"""Implementation of JSONEncoder
"""
from __future__ import absolute_import
import re
from operator import itemgetter
from decimal import Decimal
from .compat import u, unichr, binary_type, string_types, integer_types, PY3
def _import_speedups():
try:
from . import _speedups
@hzbd
hzbd / Appfog_django_setting.py
Created February 11, 2013 05:41
Appfog a simple django_setting.py for Postgresql-9.1
import json, psycopg2
vcap_services = json.loads(os.environ['VCAP_SERVICES'])
postgres_srv = vcap_services['postgresql-9.1'][0]
try:
cred = postgres_srv['credentials']
except KeyError,ke:
print >> sys.stderr, "VCAP_SERVICES = %s" % str(vcap_services)
raise ke
DATABASES = {
@hzbd
hzbd / SendMail.py
Created April 18, 2013 15:44
using optparse to update sendmail script.
#!/usr/bin/env python
import smtplib
import sys
from optparse import OptionParser
def initialize_smtp_server(smtpserver, smtpport, email, pwd):
'''
This function initializes and greets the SMTP server.
It logs in using the provided credentials and returns the
@hzbd
hzbd / fabfile.py
Created April 21, 2013 16:27
Fabric deploy script with : south migrations, rollback and maintenance page.
from fabric.api import env, run, sudo, local, put
def production():
"""Defines production environment"""
env.user = "deploy"
env.hosts = ['example.com',]
env.base_dir = "/var/www"
env.app_name = "app"
env.domain_name = "app.example.com"
env.domain_path = "%(base_dir)s/%(domain_name)s" % { 'base_dir':env.base_dir, 'domain_name':env.domain_name }
@hzbd
hzbd / fabfile.py
Created April 21, 2013 16:27
Fabric deploy script with : south migrations, rollback and maintenance page.
#!/usr/bin/env python
#-*- coding:UTF-8 -*-
from fabric.api import env, run, sudo, local, put
def production():
"""Defines production environment"""
env.user = "deploy"
env.hosts = ['example.com',]
# -*- coding: utf-8 -*-
from celery.task import task
@task
def generate(model, pk, attr):
instance = model._default_manager.get(pk=pk)
file = getattr(instance, attr)
file.generate(save=True)
return attr
@hzbd
hzbd / fabric.py
Created April 21, 2013 19:09
grahamweldon.com fabfile
from __future__ import with_statement
from datetime import datetime
from sys import exit
from fabric.api import env, run, local, task, settings, sudo
import re
env.hosts = ['[email protected]']
environments = {
'__base__': {
import fabric.api as api
with api.env_shell("PYTHONPATH=. DJANGO_SETTINGS_MODULE=settings.imagawa"):
api.run("python dosomething.py")
@hzbd
hzbd / fabfile.py
Created April 23, 2013 17:16 — forked from soyrex/fabfile.py
from fabric.context_managers import cd
from fabric.operations import sudo,run,local
from fabric.state import env
env.hosts = ['127.0.0.1',]
env.user = 'username'
env.deploy_user = 'django'
env.key_filename = ['/Users/soyrex/Keys/keyfile.pem',]
def stage():
local('git push origin staging')