Skip to content

Instantly share code, notes, and snippets.

View miohtama's full-sized avatar
🏠
https://tradingstrategy.ai

Mikko Ohtamaa miohtama

🏠
https://tradingstrategy.ai
View GitHub Profile
@miohtama
miohtama / customized_web_server.py
Created August 21, 2015 20:15
Start a Pyramid WebTest web server with INI settings overrides
_customized_web_server_port = 8522
@pytest.fixture()
def customized_web_server(request, app) -> typing.Callable:
"""py.test fixture to create a WSGI web server for functional tests with custom INI options set.
This is similar to ``web_server``, but instead directly spawning a server, it returns a factory method which you can use to launch the web server which custom parameters besides those given in test.ini.
Example::
@miohtama
miohtama / presto.py
Created August 23, 2015 13:41
PrestoDoctor OAuth implementation with Authomatic, Pyramid and Python 3.x
"""Prestodoctor OAuth on Authomatic implementation with data import and mapping to internal database."""
from argparse import Namespace
import time
from authomatic.core import json_qs_parser
from authomatic.providers.oauth2 import OAuth2
from websauna.system.model import now
from websauna.system.user.social import EmailSocialLoginMapper, \
NotSatisfiedWithData
@miohtama
miohtama / Plone developer tutorial.rst
Created July 24, 2011 09:37
How to start developing plone

Sauna Sprint 2011 head first group 2011-07-24

How to start developing Plone - from the scratch approach.

Use man pages, info pages and commandline help before asking others, please.

Install virtualenv

@miohtama
miohtama / zope-startup-fork.txt
Created July 26, 2011 08:18
How Zope starts up and where to fork
Zope start process
Zope2.__init__ contains ZopeStarter
def prepare(self):
self.setupInitialLogging()
self.setupLocale()
self.setupSecurityOptions()
self.setupPublisher()
# Start ZServer servers before we drop privileges so we can bind to
@miohtama
miohtama / capture.py
Created April 24, 2012 12:28
Wrap Python print statement to breakpoint when something prints by catching output
import sys
old_f = sys.stdout
BAD_OUTPUT = "hospitalArrival_dateTimeStrokeOnSet"
class F:
def write(self, x):
if x == BAD_OUTPUT:
import pdb ; pdb.set_trace()
@miohtama
miohtama / gist:2727891
Created May 18, 2012 22:25
Create HTML5 <audio> compatible files out of MP3 using ffmpeg
# -*- coding: utf8 -*-
import os
import subprocess
def create_prelisten_ogg(mp3, ogg):
"""
Run en-code for a single file
Do 48 kbit files for prelisten.
"""
@miohtama
miohtama / ordereddict-2.6.py
Created May 20, 2012 11:32
Python 2.6 compatible OrderedDict
# Python 2.6 compatible ordered dict
# NOTE: API is not 1:1, but for normal dict access of
# set member, iterate keys and values this is enough
# Add odict egg to your project http://pypi.python.org/pypi/odict/
try:
from collections import OrderedDict
except ImportError:
from odict import odict as OrderedDict
@miohtama
miohtama / gist:2788628
Created May 25, 2012 15:03
Throttle Javascript events so that the same event doesn't fire twice in the timeframe
/**
* Kindly ask to redraw the one frame preview.
*
* This function has throttling support so you can
* fire this from mouse move events (color picking) safely.
*
* XXX: Make sure all the fonts are loaded in this point or the
* first round of text rendering fails. See hidden font preloader in creator.pt.
*
@miohtama
miohtama / gist:2821586
Created May 28, 2012 23:09
Parsing European day.month.year date in Python
import datetime
string = "1.1.2012"
date = datetime.datetime.strptime(string, '%d.%m.%Y').date()
@miohtama
miohtama / gist:2835464
Created May 30, 2012 10:49
How to style a custom <input type="file"> button
HTML:
<button id="add-photo" i18n:translate="">
Upload photos
</button>
<div id="photo-upload">
<form id="upload-form" action="/upload/" method="POST" enctype="multipart/form-data">
<input id="add-photo-upload" style="display: none" type="file" name="files[]" multiple="multiple"/>
</form>