Skip to content

Instantly share code, notes, and snippets.

View clemesha's full-sized avatar

Alex Clemesha clemesha

View GitHub Profile
@clemesha
clemesha / with.py
Created July 27, 2012 20:54
Python's with statements are beautiful
with open('site.log') as infile, open('err.log', 'w') as outfile:
for line in infile:
if 'ERROR' in line:
outfile.write(line)
@clemesha
clemesha / flaskapp.py
Created June 11, 2012 09:21 — forked from kennethreitz/flaskapp.py
My typical flask app base
# -*- coding: utf-8 -*-
import os
from flask import Flask
from flask_heroku import Heroku
from flask_sslify import SSLify
from raven.contrib.flask import Sentry
from flask.ext.celery import Celery
@clemesha
clemesha / crop_resize_osx_hack.py
Created October 7, 2011 10:02
Download, resize image without ruining aspect ration. OSX specific
#!/usr/bin/env python
"""
Quick hack to download an image, then resize to a smaller image
that does not ruin the aspect ratio of the original image.
NOTE: The script is OS X specific: uses commands 'sips' and 'file'.
"""
import sys
import commands #deprecated in Python 3 - use 'subprocess' module
import sys
import time
import json
from glob import glob
from urlparse import urlparse
from itertools import groupby
from collections import defaultdict
DAY = 15
"1) install: http://wiki.github.com/bard/mozrepl
"2) turn on "Mozrepl" in Firefox "Tools"
"3) put below in .vimrc
autocmd BufWriteCmd *.html,*.css,*.gtpl,*.sass,*.erb :call ReloadFirefox()
function! ReloadFirefox()
if &modified
write
silent !echo 'BrowserReload();content.window.scrollTo(content.window.pageXOffset, content.window.pageYOffset);repl.quit();' | nc localhost 4242 2>&1 > /dev/null
endif
ACCESS_KEY='YOUR AMAZON API KEY'
SECRET='YOUR AMAZON SECRET'
BUCKET_NAME='database_backup_bucket' #note that you need to create this bucket first
from boto.s3.connection import S3Connection
from boto.s3.key import Key
def save_file_in_s3(filename):
conn = S3Connection(ACCESS_KEY, SECRET)
bucket = conn.get_bucket(BUCKET_NAME)
# use this: http://codysoyland.com/2009/sep/6/introduction-surlex/ for URL->Regex mapping
# interesting: http://github.com/simonw/djangode
import copy
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor
class ViewResource(Resource):
#from here: http://pastebin.com/GZ5UdEDZ
from twisted.web import server, resource
from twisted.application import service, internet
from twisted.internet import reactor
from twisted.internet.defer import Deferred
from twisted.python import log, logfile
from twisted.python.log import ILogObserver
import psyco
psyco.full()
server {
listen 80;
server_name foo.bar.org;
access_log /var/log/nginx/pads/access.log;
location /static {
alias /var/www/pads;
}