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 / 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 / parse-hash-bang-arguments-in-javascript.js
Created January 6, 2012 12:08
Parse hash bang HTTP GET query style arguments from an URL using Javascript
/**
* Parse hash bang parameters from a URL as key value object.
*
* For repeated parameters the last parameter is effective.
*
* If = syntax is not used the value is set to null.
*
* #x&y=3 -> { x:null, y:3 }
*
* @param aURL URL to parse or null if window.location is used
@miohtama
miohtama / test-three.py
Created January 23, 2012 23:47
Testing Three.js 3d rendered with Selenium + Python
"""
See that rendering Javascript loads jobs properly.
Skeleton based on https://github.com/Pylons/deformdemo/blob/master/deformdemo/test.py
Running::
./run-selenium.sh
@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:2821647
Created May 28, 2012 23:30
Sorted datetime objects with Python
# The trick is to pass timedelta object as a sort key and not to use cmp() function
import datetime
def date_key(a):
"""
a: date as string
"""
a = datetime.datetime.strptime(a, '%d.%m.%Y').date()
return a