This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### signals | |
# http://docs.python.org/library/signal.html | |
# example: https://github.com/binarydud/pyres/blob/master/pyres/scheduler.py | |
import signal | |
signal.signal(signal.SIGTERM, self.schedule_shutdown) | |
def schedule_shutdown(): | |
self._shutdown = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: def raise_exception(): | |
...: raise Exception('the base exception') | |
...: | |
In [2]: try: | |
...: raise_exception() | |
...: except Exception, e: | |
...: print "caught: %s" % e | |
...: | |
caught: the base exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### step 1. write a javascript function that inserts a script tag | |
### into the <head> with the URL you want to get. | |
### make sure this url contains the argument callback, e.g. | |
### var url = http://splitmyri.de/cofi?lat=12.34&lon=45.67&callback=deal_with_request | |
load_jsonp_script = function(url) { | |
/* makes a jsonp request for url */ | |
var e = document.createElement('script'); | |
e.setAttribute('language','javascript'); | |
e.setAttribute('type', 'text/javascript'); | |
e.setAttribute('src', url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this | |
application = tornado.web.Application([ | |
(r"/", MainHandler), # get() - homepage - link to app | |
(r"/cofi/.*", CofiHandler) # get() | |
]) | |
# becomes | |
app_settings = { | |
'debug': True | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import smtplib | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email import Encoders | |
import os | |
gmail_user = "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<style> | |
#color_label { | |
display: inline-block; | |
width: 90; | |
text-align: right | |
} | |
#color_bar { | |
display: inline-block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a group for the new user | |
groupadd shreyansgroup | |
# create user, -d = home directory, -g = group, -s = default shell | |
# note, this will not create the home directory | |
useradd -d /home/shreyans -g shreyansgroup -s /bin/bash shreyans | |
# create home directory and assign it to the user | |
mkdir /home/shreyans | |
chown shreyansgroup:shreyans /home/shreyans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Desc(object): | |
def __init__(self): | |
self.x = 'x' | |
def foo(self): | |
print 'foo' | |
def __getattribute__(self, name): | |
print 'NAME:', name | |
attr = object.__getattribute__(self, name) | |
if callable(attr): | |
print 'CALLABLE' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
txtred='\033[1;31m' | |
txtgrn='\033[1;32m' | |
txtylw='\033[1;33m' | |
end='\033[0m' | |
function parse_git { | |
branch="$(__git_ps1 "%s")" | |
if [[ -z $branch ]]; then | |
return | |
fi |