Skip to content

Instantly share code, notes, and snippets.

View pzwang's full-sized avatar

Peter Wang pzwang

  • Anaconda, Inc. (formerly Continuum Analytics)
View GitHub Profile
@pzwang
pzwang / CaptureSeq_ALL_V10-pwang.py
Created May 19, 2016 07:10
cleaned up version of SharpCap capture script
## IronPython Script v1.0 for SharpCap - v2.9 2529beta only
## Capture series of PNGs pics for specificed count at specified intervals (clears stack for each pic)
## Good for capturing series of pics of Comets to create a movie
import clr ## These four lines are for Thread.Sleep and DoEvents
clr.AddReference('System.Windows.Forms') ##
from System.Windows.Forms import * ##
from System.Threading import * ##
clr.AddReference('System.Drawing')
@pzwang
pzwang / gist:f0bb4f3fcf0b3595331d
Created February 16, 2016 19:56
simple 2D plot of some data
import numpy as np
import matplotlib.pyplot as plt
# Create some dummy data (a 2D cosine function) and scale it to 255
xs, ys = np.meshgrid(np.linspace(-5,5,500), np.linspace(-5,5,500),
indexing = "xy")
data = np.cos(np.sqrt(xs*xs + ys*ys)) * 255
image = plt.imshow(data, cmap="ocean")
plt.colorbar()
@pzwang
pzwang / perlis_favorites.txt
Created January 31, 2015 16:58
Peter's favorite Perlisms
One man's constant is another man's variable.
Functions delay binding: data structures induce binding. Moral: Structure data late in the programming process.
If a program manipulates a large amount of data, it does so in a small number of ways.
Symmetry is a complexity reducing concept (co-routines include sub-routines); seek it everywhere.
It is easier to write an incorrect program than understand a correct one.
@pzwang
pzwang / gist:56c7c0717c3c1c54dd76
Created January 16, 2015 16:27
Salt-crusted Loup de Mer recipe
(Originally from http://azurlingua-culture.com/en/general/loup-en-croute-de-sel-3/)
Not many foreigners know what “loup” means in France when it’s not the
male wolf that is being refered to. If you come to learn French in
Nice, you will know that ‘le loup (in the Mediterranean)’, or “bar”
(as it is called in the Atlantic) means “sea bass” in English,
“lubina” in Spanish, “Wolfsbarsch” in German, “baixo do mar” in
Portuguese, “mořský okoun” in Czech, “морской окунь” in Russian,
“branzino” in Italian, “mare bas” in Romanian, … One of the best fish
in ‘western seas’. I can’t guarantee that all of the translations are
@pzwang
pzwang / gist:91f0cd7e8bb9ee84553a
Created December 17, 2014 15:29
improved fieldparse
# fieldparse.py
import collections
def parse(lines,types,names):
if not isinstance(lines, collections.Iterable) or isinstance(lines, str):
raise TypeError("lines must be an iterable container of strings")
if not isinstance(types, collections.Sequence) or \
not isinstance(names, collections.Sequence):
@pzwang
pzwang / gist:3ec8fb0d2cd66d2d493f
Created December 17, 2014 14:54
Exercise 7.1
class Structure(object):
_fields = []
def __init__(self, *args, **kw):
""" Generic constructor which initializes the object with the passed-
in values, based on positional order and name in the **_fields**
class variable. Subclasses need to define **_fields** appropriately.
"""
@pzwang
pzwang / gist:11390322
Last active August 29, 2015 14:00
better-behaved __get__ in bokeh property descriptors
# A replacement for the Instance.__get__() from
# https://github.com/ContinuumIO/bokeh/blob/master/bokeh/properties.py#L832
def __get__(self, obj, owner, type=None):
# If the constructor for Instance() supplied a class name, we should
# instantiate that class here, instead of returning the class as the
# default object
if obj is not None and not hasattr(obj, self._name):
if type and self.default and isinstance(self.default, type):
setattr(obj, self._name, self.default())
@pzwang
pzwang / bigint.py
Created April 24, 2014 05:00
bokeh example plot showing problems with Javascript integer precision
import numpy as np
from bokeh.plotting import *
N = 10
import sys
output_file("bigint.html", title="bigint example")
for div in (1, 10, 100, 1000, 10000, 100000, 1000000):
bigint = sys.maxint / 2 / div - 100
x = range(bigint, bigint+10)
@pzwang
pzwang / Plot_PaddingTrouble_fixed.py
Created April 23, 2014 04:17
Fixed Plot_PaddingTrouble
# from https://github.com/SDiot/chaco_troubles/blob/master/Plot_PaddingTrouble.py
""" Simple example to show that I have a problem with padding
HOW TO:
1) Run Plot_PaddingTrouple.py
2) Click on Replot ===> the padding is not taken into account while it
is enforced in plot_please... Why??
"""
@pzwang
pzwang / Plot_LayoutTrouble_fixed.py
Created April 23, 2014 04:04
Fixed chaco aspect_ratio example
# from https://github.com/SDiot/chaco_troubles/blob/master/Plot_LayoutTrouble.py
""" Simple example to show a problem with the Layout
HOW TO:
1) Run Plot_LayoutTrouple.py
2) Zoom by creating a rectangular box with the left click so that the aspect_ratio is changed
3) Click on Reset Asp. Ratio
4) Click on Reset View ===> the plot is not taking all the room it could!
5) Resize the window ===> the plot is now taking all the room it can!