Skip to content

Instantly share code, notes, and snippets.

@oxtopus
oxtopus / gist:1227445
Created September 19, 2011 20:04
lambda : list :: % : str
>>> (lambda s: ['a', s, 'c'])('b')
['a', 'b', 'c']
>>> 'a %s c' % 'b'
'a b c'
@oxtopus
oxtopus / gist:1242678
Created September 26, 2011 16:38
map(itemgetter(n), iterable) == [i[n] for i in iterable]
>>> from operator import itemgetter
>>> iterable=[('foo', 'bar', 'baz'), ('apple', 'banana', 'orange')]
>>> [i[1] for i in foo]
['bar', 'banana']
>>> map(itemgetter(1),foo)
['bar', 'banana']
@oxtopus
oxtopus / gist:2476625
Created April 24, 2012 05:10
dictify/tuplify
>>> dictify = lambda t:dict(zip(*[iter(t)]*2))
>>> dictify(('a', 'A', 'c', 'C', 'b', 'B'))
{'a': 'A', 'c': 'C', 'b': 'B'}
>>>
>>> tuplify = lambda d:tuple(chain(*d.iteritems()))
>>> tuplify({'a': 'A', 'c': 'C', 'b': 'B'})
('a', 'A', 'c', 'C', 'b', 'B')
>>>
>>> assert (lambda d:dictify(tuplify(d))==d)({'a': 'A', 'c': 'C', 'b': 'B'})
>>> assert (lambda t:tuplify(dictify(t))==t)(('a', 'A', 'c', 'C', 'b', 'B'))
@oxtopus
oxtopus / webapp.py
Created March 17, 2013 19:18
Quick hack to define web.py routes and handlers via decorators.
import types
import web
urls = []
def GET(route):
def decorate(fn):
clsName = '%s_%s' % (fn.__name__, 'GET')
from nupic.frameworks.opf.clamodel import CLAModel
params = \
{'clParams': {'alpha': 0.0001,
'clVerbosity': 0,
'regionName': 'CLAClassifierRegion',
'steps': '1,5'},
'inferenceType': 'TemporalMultiStep',
'sensorParams': {'encoders': {'consumption': {'clipInput': True,
'fieldname': u'consumption',
'n': 100,
@oxtopus
oxtopus / Output
Created June 10, 2013 18:03
Bootstrap NuPIC installation in virtualenv from github.
$ ./bootstrap-nta.sh
Running virtualenv with interpreter /usr/bin/python2.6
New python executable in nta/bin/python2.6
Also creating executable in nta/bin/python
Installing setuptools............done.
Installing pip...............done.
Cloning into 'nupic'...
remote: Counting objects: 12804, done.
remote: Compressing objects: 100% (8984/8984), done.
remote: Total 12804 (delta 3622), reused 12540 (delta 3558)
@oxtopus
oxtopus / demo.py
Last active December 23, 2015 22:09
import validictory
import yaml
data = yaml.load("""
- foo
- bar: [baz, null, 1.0, 2]
""")
with open('schema.yml', 'r') as inp:
schema = yaml.load(inp.read())
@oxtopus
oxtopus / history.txt
Last active June 10, 2024 16:28 — forked from anonymous/history.txt
Installing NuPIC from scratch on Ubuntu 13.10
sudo apt-get update
sudo apt-get install python-dev git python-pip automake libtool libssl-dev
git clone https://github.com/numenta/nupic.git
mkdir -p nta/eng
echo "
export NTA=$HOME/nta/eng
export NUPIC=$HOME/nupic
export BUILDDIR=/tmp/ntabuild
export MK_JOBS=3
source $HOME/nupic/env.sh" >> ~/.bashrc
foo.split("").reverse().join("").split(/:(?!([\\]))/).map(function(_){if (_) {return _.split("").reverse().join("")} else {return _ }}).reverse().filter(function(_) {return (_)})
============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- pytest-2.4.2
plugins: cov, xdist
collected 788 items / 1 errors / 2 skipped
../usr/local/lib/python2.7/dist-packages/tests/unit/nupic/utils_test.py ...
../usr/local/lib/python2.7/dist-packages/tests/unit/nupic/algorithms/anomaly_likelihood_jeff_test.py ...ss..
../usr/local/lib/python2.7/dist-packages/tests/unit/nupic/algorithms/anomaly_likelihood_test.py .............
../usr/local/lib/python2.7/dist-packages/tests/unit/nupic/algorithms/anomaly_test.py ............
../usr/local/lib/python2.7/dist-packages/tests/unit/nupic/algorithms/cells4_test.py