Skip to content

Instantly share code, notes, and snippets.

View chroto's full-sized avatar
🦍

Chris Proto chroto

🦍
View GitHub Profile
@chroto
chroto / takeoff.py
Created November 25, 2011 21:19
Getting django projects started without fuss.
#! /usr/bin/env python
import os
import subprocess
import pprint
def use_virtualenv(virtualenv_path):
command = ['bash', '-c', 'source '+os.path.join(virtualenv_path,'bin','activate')+' && env']
proc = subprocess.Popen(command, stdout = subprocess.PIPE)
for line in proc.stdout:
(key, _, value) = line.partition("=")
@chroto
chroto / bookstore.py
Created April 16, 2012 07:06
SA Bookstore
"""
# Bookstore
- Book => Images
- Book <=> Author
- Book <=> Genre
- Book -> Genre (Primary)
@chroto
chroto / gist:3107078
Created July 13, 2012 20:06
Find a dict key from its value
def reverse_dict_lookup(d, val):
"""
Performs a reverse lookup on a dictionary object, raising ValueError on
failure.
>>> reverse_dict_lookup({'a': 1, 'b': 2, 'c': 3}, 2)
'b'
>>> reverse_dict_lookup({}, 'a')
Traceback (most recent call last):
...
@chroto
chroto / gist:3107097
Created July 13, 2012 20:09
timedelta functions
def human_time(td):
"""
Return a more human readable version of a timedelta instance
"""
ret_str = ""
translate_tuple = [
"day",
"hour",
"minute",
"second"]
@chroto
chroto / index.html
Created July 13, 2012 21:21
Django - detect MIME type
{% for file in mixed_files %}
<a href=""
{% if "image" in file|mimetype %}class="fancybox"{% endif %}
{% if "pdf" in file|mimetype %}rel="external"{% endif %}
>foo</a>
{% endfor %}
@chroto
chroto / sms_gateways.py
Created October 16, 2012 15:22
A tuple of tuples consisting of (SMS gateway, name of carrier)
SMS_GATEWAYS = (
(u'{number}@digitextdm.com', u'Digicel (Dominica)(Dominica)'),
(u'{number}@message.alltel.com', 'Alltel'),
(u'0{number}@smsmail.eplus.de', u'E-Plus(Germany)'),
(u'{number}@sms.edgewireless.com', u'Edge Wireless(USA)'),
(u'{number}@SMS.elementmobile.net', u'Element Mobile(USA)'),
(u'{number}@emtelworld.net', u'Emtel(Mauritius)'),
(u'{number}@echoemail.net', u'Esendex(UK)'),
(u'{number}@echoemail.net', u'Esendex(USA)'),
(u'{number}@esendex.net', u'Esendex(Spain)'),
@chroto
chroto / .gitignore
Created December 3, 2012 23:54
Intro to crypto Week 1 Problem Sets
*.pyc
@chroto
chroto / death.py
Created June 9, 2014 20:43
Behold I am Death, destroyer of worlds
def unpatch_models():
"""unpatch"""
if __backup == {}:
return
for module_to_unpatch in model_mods:
name = module_to_unpatch.__name__
for cls_name in vars(module_to_unpatch).get('__patchable__', []):
setattr(module_to_unpatch,
cls_name,
__backup[name][cls_name])
var fs = require('fs');
// Lambda knows what region it's in but a local execution doesn't, so preload the SDK and set the region
// This will only work if the same variable name is used in the Lambda function file
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
// validate arguments
if(process.argv.length < 4) {
@chroto
chroto / install.sh
Created March 4, 2020 17:36 — forked from mkubenka/install.sh
OpenVPN Access Server Letsencrypt
#!/bin/sh
apt-get -y install git bc
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
mkdir /etc/letsencrypt