Skip to content

Instantly share code, notes, and snippets.

@theodoregoetz
theodoregoetz / diamond_awesomepattern.py
Last active November 19, 2015 16:08
Diamond Pattern in Python 3
print(r'''
The Classic Diamond Pattern
or
How I Learned to Stop Worrying and Love Python
--> := 'inherets from'
A
^
@theodoregoetz
theodoregoetz / no_reentry_methods.py
Last active August 29, 2015 14:23
Class disallowing reentry into methods when calculating properties
class LockError(Exception):
def __init__(self,call_stack):
self.call_stack = call_stack[:]
def __str__(self):
msg = 'Not enough information.\n'
msg += ' call stack:\n '
msg += '\n '.join(self.call_stack)
return msg
@theodoregoetz
theodoregoetz / pid_controller.ipynb
Last active August 29, 2015 14:25
PID Controller
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theodoregoetz
theodoregoetz / macaw.py
Created September 5, 2015 20:09
viridis-like colormap going all the way to white instead of yellow
from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
# Used to reconstruct the colormap in pycam02ucs.cm.viscm
parameters = {'xp': [22.674387857633945, -10.903679653679603, -27.867965367965326, -46.32034632034626, 9.9296536796537396, -1.2562144886363136],
'yp': [-20.102530541012214, -39.58333333333333, -51.19047619047619, 60.714285714285694, 66.369047619047592, -0.46657986111111427],
'min_Jp': 18.8671875,
'max_Jp': 99.79166666666667}
@theodoregoetz
theodoregoetz / gist:bae909c3b98c247dc530
Created September 10, 2015 22:58
C++ Constructor with rvalue
#include <iostream>
struct Foo
{
public:
Foo(int d) : x(d) {}
int x;
};
int main()
@theodoregoetz
theodoregoetz / trie.cpp
Created October 22, 2015 18:09
A Trie using C++11
#include <unordered_map>
#include <memory>
using namespace std;
struct Node {
bool end;
unordered_map<char,unique_ptr<Node>> children;
Node() : end(false), children() {}
};
@theodoregoetz
theodoregoetz / find-grep.py
Created November 20, 2015 16:59
Find-Grep python script
#!/usr/bin/python3
import sys
import os
import argparse
import fnmatch
import re
class AppendAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
@theodoregoetz
theodoregoetz / fit_gaussian.py
Created December 2, 2015 02:27
using scipy to fit a gaussian signal
import numpy as np
from scipy import optimize as opt
from scipy import stats
from matplotlib import pyplot
xx,yy = np.array([
[760.0500, 195],
[760.1500, 193],
[760.2500, 187],
[760.3500, 185],
@theodoregoetz
theodoregoetz / find_headers.py
Created January 1, 2016 00:23
C++ header include graph
#!/usr/bin/env python3
import sys
import os
import re
from os import path
from glob import glob
from graph_tool.all import *
@theodoregoetz
theodoregoetz / ctypes_mock.py
Created February 24, 2016 17:41
Python unittest.mock to handle ctypes calls to underlying native binary libraries.
import re
from ctypes import *
from nose.tools import *
from six import *
from unittest.mock import *
def ref_to_pointer(ref, ctype):
'''convert byref() object to real pointer'''
addr = int(re.search(r'(0x[\dabcdefABCDEF]+)',repr(ref)).group(1), 0)