Skip to content

Instantly share code, notes, and snippets.

import collections
import random
def main():
#deck = [(value, color) for value in range(3) for color in range(4)] * 4
#deck = [(value, color) for value in range(4) for color in range(4)] * 3
x16 = [(value, color) for value in range(2) for color in range(4)] * 4
x8 = [(value + 2, color) for value in range(2) for color in range(4)] * 2
deck = x16 + x8
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <glib.h>
#define GST_USE_UNSTABLE_API
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
@angri
angri / nhlib-demo.py
Created August 23, 2012 21:48
nhlib demo
import nhlib, nhlib.site, nhlib.calc
fault_mfd = nhlib.mfd.EvenlyDiscretizedMFD(min_mag=5.5, bin_width=1,
occurrence_rates=[0.1, 0.01, 0.001])
fault_trace = nhlib.geo.Line([nhlib.geo.Point(*coords)
for coords in [(10, 7), (10.4, 7), (10.6, 6.8)]])
fault = nhlib.source.SimpleFaultSource(
'f1', 'fault 1', tectonic_region_type=nhlib.const.TRT.STABLE_CONTINENTAL,
mfd=fault_mfd, rupture_mesh_spacing=5, rupture_aspect_ratio=1.5,
import numpy
from miniquake import *
SITES = sites(boundary=[(-111, 29), (-127, 29), (-127, 43.5), (-111, 43.5)],
discretization=10, vs30=760, vs30measured=False, z1pt0=100,
z2pt5=5)
SOURCES = sources('/tmp/NRML04/CaliforniaGriddedSeismicity.xml',
def missing(seq):
num_missing = 2
for i in xrange(num_missing):
seq.append(None)
for i in xrange(len(seq) - 2):
if seq[i] == i:
continue
class Reader(object):
def __init__(self):
self.buf = []
self.result = []
self._mode = 'keyvalue'
self._resdict = {}
self._datasize = 0
self._databuf = []
self._datakey = None
@angri
angri / perfmeasure.py
Created June 4, 2012 08:33
nhlib performance measure tools
import sys
from decimal import Decimal
import time
import multiprocessing
import numpy
from nhlib import const
from nhlib.site import SiteCollection
from nhlib.source import AreaSource
@angri
angri / update-license.sh
Created March 7, 2012 09:09
Attach an AGPL license
#!/bin/sh
NAME="nhlib: A New Hazard Library"
COPYRIGHT="Copyright (C) 2012 GEM Foundation"
for f in `find * -type f` ; do
if [ "$f" = "LICENSE" ] ; then continue; fi
head -n 3 $f | grep "$NAME $COPYRIGHT" --silent && \
echo "- $f has license, skipping" && \
continue
@angri
angri / yaml-logic-tree.yaml
Created September 21, 2011 13:54
Spec for yaml format of logic tree definition
# Lines starting with symbol # are comments.
# On the top level each logic tree definition should have
# two specific items: SourceModelLogicTree and GMPELogicTree.
# SourceModelLogicTree node allows to specify the first level
# of branching: uncertainty on source model definition.
SourceModelLogicTree:
# The next line means "take source_model1.xml with chance of 1/2".
- 0.5: source_model1.xml