Skip to content

Instantly share code, notes, and snippets.

@wowkin2
wowkin2 / SingletonMongoClient.py
Created May 14, 2016 17:20
Python Singleton with parameters (so the same parameters get you the same object) with support to default arguments and passing arguments as kwargs (but no support for pure kwargs).
"""
Python Singleton with parameters (so the same parameters get you the same object)
with support to default arguments and passing arguments as kwargs (but no support for pure kwargs).
And implementation for MongoClient class from pymongo package.
"""
from pymongo import MongoClient
import inspect
@wowkin2
wowkin2 / parse_signed_request
Created April 5, 2016 14:34 — forked from albertobajo/parse_signed_request
Python implementation of Facebook's php signed_request parser: http://developers.facebook.com/docs/authentication/canvas
import hmac
import simplejson as json
from base64 import urlsafe_b64decode
from hashlib import sha256
def parse_signed_request(signed_request, secret):
[encoded_sig, payload] = signed_request.split('.')
# decode data
@wowkin2
wowkin2 / db.php
Last active January 13, 2016 16:24
Python/Django vs. PHP/Symfony
// ### PHP / Symfony2 / ORM ###/
// create new document
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getManager();
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from django import template
from django.conf import settings
register = template.Library()
# ...
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.9.1/bootstrap-social.min.css">
@wowkin2
wowkin2 / disqus.html
Last active August 29, 2015 14:26
Comments in your WebSite from here: http://spodaryk.pp.ua/post/18/blog-social-comments
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES * * */
var disqus_shortname = '<your app name>';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
@wowkin2
wowkin2 / daemon.py
Last active August 29, 2015 14:24 — forked from Apkawa/daemon.py
'''
Simple usage as cherrypy daemon as example
'''
import soaplib
from soaplib.core.server import wsgi
from cherrypy.wsgiserver import CherryPyWSGIServer
HOST = "0.0.0.0"
PORT = 45124
# ##############################################
# HEROKU DEPLOYMENT
# ##############################################
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
.git
.idea
*.pyc
__pycache__
local_settings.py
db.sqlite3
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,