Skip to content

Instantly share code, notes, and snippets.

Avatar

Jimmy John jimmyislive

View GitHub Profile
View csrf_decorator.py
def csrf_check(web_request):
def real_decorator(view_func):
@wraps(view_func)
def wrapper(*args, **kwargs):
if (request.method == 'GET'):
return view_func(*args, **kwargs)
u = urlparse(request.headers['Origin'])
if u.netloc in ['www.my_awesome_domain.com', 'my_awesome_domain.com']:
return view_func(*args, **kwargs)
View aws_kms.py
# Define your AWS_KMS_ARN, KMS_REGION, KMS_AWS_ACCESS_KEY_ID, KMS_AWS_SECRET_ACCESS_KEY someplace
import base64
import boto3
from Crypto.Cipher import AES
class AwsKms(object):
def __init__(self):
self.key_id = AWS_KMS_ARN
self.client = boto3.client('kms',
View gist:d9d00783f06d7f278e30
Ever want to meet like minded individuals who have (or have the desire) to start some crazy idea on their own. Maybe over coffee or lunch. You may/may not want to start your own, but just meeting with such folks is an interesting excercise in itself. If so, email me your details and i'll hook you up with someone closeby (me included!)
Jim
jimmyislive@gmail.com
@jimmyislive
jimmyislive / clone_redis.py
Created Jan 4, 2015
Redis Elasticache Export
View clone_redis.py
from optparse import OptionParser
import sys
import redis
__author__ = 'Jimmy John'
__doc__ = '''
This is a script to make a copy of a redis db. Mainly to be used for cloning AWS Elasticache
instancces. Elasticache seems to disable the SAVE/BGSAVE commands and you do not have access to
the physical redis instances. The UI allows you to create 'Snapshots', but no way to download
View form
<div class="control-group">
<label class="hidden" for="inputPot">Do not fill me in</label>
<div class="controls">
<input class="hidden" type="text" id="inputPot" placeholder="pot" ng-model="session.packagePot" name="packagePot">
</div>
</div>
@jimmyislive
jimmyislive / index.js
Created Apr 16, 2014
angularjs with seo
View index.js
exports.index = function(req, res){
if (req.query._escaped_fragment_ !== undefined) {
if (req.query._escaped_fragment_[0] === '/') {
req.query._escaped_fragment_ = req.query._escaped_fragment_.substring(1);
}
if (req.query._escaped_fragment_[req.query._escaped_fragment_.length - 1] === '/') {
req.query._escaped_fragment_ = req.query._escaped_fragment_.substring(0, req.query._escaped_fragment_.length - 1);
@jimmyislive
jimmyislive / api_module.js
Last active Jan 3, 2018
Single Page App components
View api_module.js
var cfg = require('../config').Config,
qs = require('querystring'),
request = require('request');
request = request.defaults({jar: true})
exports.awesome = function(req, res){
headers = {};
@jimmyislive
jimmyislive / pubsubhubbub_post.js
Created Dec 16, 2013
Sample function that can be used to POST to the hub whenever your feed changes. The cfg object is something that has all the appropriate params depending on which environment you are on e.g. dev | staging | production etc
View pubsubhubbub_post.js
function pubsubhubub_post(post_url, callback) {
var payload = { hostname: cfg.hub,
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}
var pubsubhubub_request = https.request(payload, function(pubsubhubub_response) {
//dunno y, but this no-op is needed here !!!
pubsubhubub_response.on('data', function(chunk) {
@jimmyislive
jimmyislive / feeds.html
Created Dec 2, 2013
Sample files to add a RSS feed to an Express/Restify setup
View feeds.html
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>My title</title>
<link>https://awesomesite.com/#/</link>
<description>My Description</description>
<language>en-us</language>
<copyright>Copyright 2014, MyAwesomeSite</copyright>
<managingEditor>owner@myawesomesite.com</managingEditor>
<webMaster>owner@myawesomesite.com</webMaster>