Skip to content

Instantly share code, notes, and snippets.

View xsleonard's full-sized avatar

Steve Leonard xsleonard

View GitHub Profile
@xsleonard
xsleonard / db.py
Created September 26, 2013 16:50
sqlalchemy schema create script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from forq import db, create_app
def drop():
db.drop_all()
print 'Dropping completed successful!'
@xsleonard
xsleonard / curl_ssl_cookies.c
Created July 20, 2013 21:30
SSL and cookie handling with libcurl
#include <stdio.h>
#include <curl/curl.h>
/* Compiling example:
*
* gcc -o curltest curl_ssl_cookies.c -L./lib/ -I./lib/include -lcurl -Wl,-rpath ./lib
*
*/
/* Example cookie handling copied from:
@xsleonard
xsleonard / curl_ssl_cookies.cpp
Created July 20, 2013 21:17
SSL and cookie handling with libcurl
#include <stdio.h>
#include <curl/curl.h>
/* Example cookie handling copied from:
* http://curl.haxx.se/libcurl/c/cookie_interface.html
* Example SSL request adapted from:
* http://curl.haxx.se/libcurl/c/https.html
*/
@xsleonard
xsleonard / mtgox exchange rate calculator
Created May 22, 2013 14:40
mtgox exchange rate calculator
#!/usr/bin/env python
'''
USAGE:
./rate.py <amount:float> <bid|ask>
'''
import sys
import requests
import re
import copy
import BeautifulSoup
class HTMLSanitizer(object):
# replace hexadecimal character reference by decimal one
_hexentity_massage = (copy.copy(BeautifulSoup.MARKUP_MASSAGE) +
[(re.compile('&#x([^;]+);'),
@xsleonard
xsleonard / gist:5508581
Created May 3, 2013 11:24
voluptuous validation failure
from voluptuous import Schema
data = {
'InactiveMails': 26,
'Bounces': [
{
'Name': 'All',
'Count': 30
},
{
@xsleonard
xsleonard / gist:5043853
Created February 27, 2013 00:48
fix missing subreddit submissions
from r2.models import Subreddit
from r2.lib.db.queries import get_links
def fix_sr(name):
sr = Subreddit._by_name(name)
for sort in ('hot', 'new', 'controversial', 'top'):
get_links(sr, sort, 'all').update()
def secure_url_for(endpoint, *args, **kwargs):
# Force generate https url. Necessarily is _external
kwargs['_external'] = True
url = url_for(endpoint, *args, **kwargs)
parsed = urlparse(url)
parsed._replace(scheme='https')
return urlunparse(parsed)