Skip to content

Instantly share code, notes, and snippets.

View enginemodel.json
[[-19.150852756939567, -0.86960922500437798], [-10.0, -0.67314024428906383], [-4.0, -0.53092823365752206], [-2.5, -0.34978573520149692], [-1.7, -0.097415037510977784], [-1.2, 0.031117285095661945], [0.0, 0.26398121786496032], [3.0, 0.71245888265216406], [5.2096257357368652, 0.93516331581155065]]
View somdemohack.py
import numpy as np
import numpy
import math
import itertools
import random
import matplotlib.pyplot as plt
class Som(object):
"""Self-organizing map
View vmath.ls
{zipWith, fold, map, zipAll, findIndex, objsToLists} = require "prelude-ls"
fobj = -> (...args) ->
me = {}
callable = f.apply(me, args) ? me
me.__proto__ = callable.__proto__
callable.__proto__ = me
return callable
export isScalar = (v) -> typeof v == 'number'
@jampekka
jampekka / fobj.ls
Last active Aug 29, 2015
Classhack
View fobj.ls
# Motivation for this madness: I often find that simply a function is
# a nice interface objects. However, often later on a need arises that
# we need also something else in a return value / argument, which currently
# calls for refactoring of every call site. In Python this can be hacked
# around using __call__. This would be a way to hack around it in LiveScript.
#
# And anyway I think having separate "classes" and "objects" is a bit stupid
# historical artefact. KISS!
fobj = (f) -> (...args) ->
View test.html
<h1 id="otsake"></h1>
<script type="text/javascript" src="coffee-script.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.js"></script>
<script type="text/coffeescript">
otsake = $("#otsake")
otsake.text("Hello DOM!")
</script>
View tsv_to_heatmap.py
import numpy as np, matplotlib.pyplot as plt, sys
from scipy.ndimage.filters import gaussian_filter
def transparent_jet(cutoff=0.2):
colormap = plt.cm.get_cmap('jet')
colormap._init()
alphas = np.linspace(0.0, 1.0, colormap.N)
alphas[alphas < cutoff] = 0.0
alphas[alphas > cutoff] = 1.0
colormap._lut[:-3,-1] = alphas
@jampekka
jampekka / v4l2_hang.c
Created Sep 17, 2014
v4l2src hangs on Gstreamer 1.0 but works on 0.10
View v4l2_hang.c
/**
Hangs after two frames with gstreamer 1.0:
gcc -o v4l2_hang1.0 `pkg-config gstreamer-1.0 --cflags --libs` v4l2_hang.c && ./v4l2_hang1.0
Works fine with 0.10
gcc -o v4l2_hang0.10 `pkg-config gstreamer-0.10 --cflags --libs` v4l2_hang.c && ./v4l2_hang0.10
*/
#include <gst/gst.h>
#include <stdio.h>
@jampekka
jampekka / gst0.10.py
Created Sep 17, 2014
Gstreamer 1.0 v4l2src with Python halts
View gst0.10.py
# PyGST with Gst 0.10 works fine
import gst
pipe = gst.parse_launch("""v4l2src device=/dev/video0 !
appsink sync=false max-buffers=1 drop=true name=sink emit-signals=true""")
sink = pipe.get_by_name('sink')
pipe.set_state(gst.STATE_PLAYING)
View index.html
<html>
<head>
<script src="http://motherjones.github.io/newsquizjs/jquery.js"></script>
<script src="http://motherjones.github.io/newsquizjs/tabletop.js"></script>
<script src="http://motherjones.github.io/newsquizjs/newsquiz.min.js"></script>
<link href="http://motherjones.github.io/newsquizcss/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="http://motherjones.github.io/newsquizcss/bootstrap-responsive.css" rel="stylesheet" media="screen">
<link href="http://motherjones.github.io/newsquizcss/style.css" rel="stylesheet" media="screen">
</head>
<body>
View mjuna.geojson
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.