Skip to content

Instantly share code, notes, and snippets.

View nigma's full-sized avatar

Filip Wasilewski nigma

View GitHub Profile
@nigma
nigma / fabfile.py
Created January 25, 2010 19:28 — forked from heckj/fabfile.py
#!/usr/bin/env python
from __future__ import with_statement # needed for python 2.5
from fabric.api import *
from fabric.contrib.console import confirm
# ================================================================
# NOTE:
# using this fabfile expects that you have the python utility
# fabric installed locally, ssh access to reamea.com, and your
# ssh public key associated with the account 'mboza@reamea.com'
@nigma
nigma / fabfile.py
Created January 25, 2010 19:30 — forked from kogakure/fabfile.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
fabfile for Django
------------------
see http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p/
modified for fabric 0.9/1.0 by Hraban (fiëé visuëlle)
several additions, corrections and customizations, too
@nigma
nigma / gist:642152
Created October 23, 2010 12:26 — forked from dcramer/gist:550435
def queryset_to_dict(qs, key='pk'):
"""
Given a queryset will transform it into a dictionary based on ``key``.
"""
return dict((getattr(u, key), u) for u in qs)
def distinct(l):
"""
Given an iterable will return a list of all distinct values.
"""
@nigma
nigma / scanner.py
Created January 13, 2011 12:32 — forked from blinks/scanner.py
"""
Scanner: match text to generate tokens.
Adam Blinkinsop <blinks@acm.org>
First, construct a scanner with the tokens you'd like to match described as
keyword arguments, using Python-syntax regular expressions.
WARNING: Group syntax in these expressions has an undefined effect.
>>> simple = Scan(ID=r'\w+')
@nigma
nigma / wavedecn.py
Created April 21, 2011 11:00
Multi-level n-dimensional wavelet transform with PyWavelets.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
__author__ = 'Filip Wasilewski <en@ig.ma>'
from pywt import Wavelet, dwtn, dwt_max_level
from pywt.numerix import as_float_array
def wavedecn(data, wavelet, mode='sym', level=None):
data = as_float_array(data)
@nigma
nigma / gist:3131916
Created July 17, 2012 20:41
Reconstructing WP tree using nth level coefficients
def get_node_paths(level=1):
"""
Lists node paths on the given level.
Order of the paths is the same as order of nodes
returned by `WaveletPacket2D.get_leaf_nodes`.
"""
paths = [""]
for i in range(level):
paths = [
path + name
@nigma
nigma / gist:3784395
Last active October 11, 2015 01:48
PostgreSQL field type casting in Django subqueries
User.objects.filter(
pk__in=Follow.objects.filter(
user=self.user,
content_type=ContentType.objects.get_for_model(User)
).extra(select={"user_ids": "object_id::integer"}).values_list("user_ids")
)
import pywt
data = [1, 3, 4, 1, 2, 5, 3, 2]
a2, d2, d1 = pywt.wavedec(data, 'db1', level=2)
a1 = pywt.upcoef('a', a2, 'db1', level=1) + \
pywt.upcoef('d', d2, 'db1', level=1)
@nigma
nigma / serve.py
Created December 20, 2012 22:44
Serving Django with CherryPy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import webbrowser
from threading import Timer
os.environ["DJANGO_SETTINGS_MODULE"] = "webapp.settings"
import cherrypy
#-*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
import logging
logging.captureWarnings(True)