Skip to content

Instantly share code, notes, and snippets.

import socket, ssl, pprint, threading, time
HOST = '127.0.0.1'
PORT = 8090
CA = 'server.csr'
KEY = 'server.key'
CERT = 'server.crt'
#openssl genrsa -des3 -out server.key.orig 2048
#openssl rsa -in server.key.orig -out server.key
import os
import sys
try:
import canistreamit
print canistreamit
except Exception as e:
print type(e), e
from setuptools.command import easy_install
easy_install.main(['-U', 'canistreamit'])
@bulv1ne
bulv1ne / ioscert.sh
Created October 16, 2013 10:57
Convert iOS push notification pem to cert and key
#!/bin/bash
FILENAME="$1.p12"
echo $FILENAME
openssl pkcs12 -in $FILENAME -out $1.cert -clcerts -nokeys -passin pass:
openssl pkcs12 -in $FILENAME -out $1.key -nocerts -nodes -passin pass:
{% with messages = get_flashed_messages(category_filter=["error"]) %}
{% if messages %}
<div class="panel panel-danger">
<div class="panel-heading">
Error
</div>
<div class="panel-body">
<ul class=flashes>
{% for message in messages %}
<li>{{ message }}</li>
@bulv1ne
bulv1ne / justcache.py
Created September 23, 2013 22:29
Flask decorator for just caching and not caring about anything else
import hashlib
from flask import request, make_response, Response
import datetime
from functools import wraps
def just_cache(f):
@wraps(f)
def _wrap(*args, **kwargs):
if 'If-Modified-Since' in request.headers:
return Response(status=304)
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<script src="http://knockoutjs.com/downloads/knockout-2.3.0.js"></script>
<script src="http://pagerjs.com/demo/pager.min.js"></script>
</head>
<body>
@bulv1ne
bulv1ne / autosave.py
Last active December 23, 2015 12:19
MongoDB lazy saving
class AutoSave(object):
def __init__(self, d, collection):
self.d = d
self.collection = collection
def __enter__(self):
return self.d
def __exit__(self, type, value, traceback):
timeit.timeit('x()', setup='''
def create_constant(value):
return itertools.repeat(value).next
x=create_constant("")
''')
#0.13626525126508682
timeit.timeit('x()', setup='def x(): ""')
#0.17869136946876552
timeit.timeit('x()', setup='x = lambda: ""')
#0.18088355837787162
# self.app can be None
# self.app.config.get('DATABASE') can be None
try:
db = self.app.config['DATABASE']
logger.debug('Using database "{db}"'.format(db=db))
except:
db = 'test'
logger.warning('DATABASE setting not set, using database "test"')
GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES,CREATE TEMPORARY TABLES, DROP, REFERENCES ON database.* TO user@localhost IDENTIFIED BY 'password';