Skip to content

Instantly share code, notes, and snippets.

View thearn's full-sized avatar

Tristan Hearn thearn

  • NASA Glenn Research Center
  • Cleveland, OH
View GitHub Profile
from openmdao.core.explicitcomponent import ExplicitComponent
from openmdao.api import Problem, Group, ExecComp, IndepVarComp
from openmdao.devtools.generate_derivative import GenerateDerivative
class Paraboloid(ExplicitComponent):
"""
Evaluates the equation f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3.
"""
import requests
import json
import sys
import time
timer = {}
hub_url = "192.168.1.2"
hours_to_refresh_token = 8
class ZWaveController(object):
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fmin, fminbound, fmin_bfgs
from scipy.misc import ascent
import pywt
from scipy.stats import kurtosis
true_image = ascent()
sigma = 25.0
test_image = true_image + sigma * np.random.randn(*true_image.shape)
@thearn
thearn / The Technical Interview Cheat Sheet.md
Last active August 3, 2017 13:42 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
from petsc4py import PETSc
rank = PETSc.COMM_WORLD.getRank()
num_ranks = PETSc.COMM_WORLD.getSize()
x = PETSc.Vec().createMPI(4) # VecCreateMPI: Creates a parallel vector. size=4
x.setValues([0,1,2,3], [10,20,30,40]) # VecSetValues: Inserts or adds values into certain locations of a vector. x[0]=10, x[1]=20, x[2]=30, x[3]=40
print ('Rank',rank,'has this portion of the MPI vector:', x.getArray() ) # VecGetArray: Returns a pointer to a contiguous array that contains this processor's portion of the vector data.
vec_sum = x.sum() # VecSum: Computes the sum of all the components of a vector. 10+20+30+40=100
import numpy as np
from openmdao.core.component import Component
from pycycle.constants import R_UNIVERSAL_ENG, MIN_VALID_CONCENTRATION
from openmdao.core.options import OptionsDictionary
from openmdao.components.indep_var_comp import IndepVarComp
from ad import adnumber
@thearn
thearn / implicit.py
Created February 8, 2016 20:53
working example
from openmdao.api import *
import numpy as np
"""
Test model:
-------------
Find value of state variable "x" such that the line 2*x + 1 has a specific
value of 'y1'
"""
Connections for inlet.flow_in:
------------------------------
.foo -> {unconnected}
fc.subgroup.fs.exit_static.flow_static.Fl_O:stat:V (fc.Fl_O:stat:V) [ft/s] -> .Fl_I:stat:V (inlet.Fl_I:stat:V) [ft/s]
fc.subgroup.fs.exit_static.flow_static.Fl_O:stat:W (fc.Fl_O:stat:W) [lbm/s] -> .Fl_I:stat:W (inlet.Fl_I:stat:W) [lbm/s]
fc.subgroup.fs.totals.flow.Fl_O:tot:Cp (fc.Fl_O:tot:Cp) [Btu/(lbm*degR)] -> .Fl_I:tot:Cp (inlet.Fl_I:tot:Cp) [Btu/(lbm*degR)]
fc.subgroup.fs.totals.flow.Fl_O:tot:Cv (fc.Fl_O:tot:Cv) [Btu/(lbm*degR)] -> .Fl_I:tot:Cv (inlet.Fl_I:tot:Cv) [Btu/(lbm*degR)]
fc.subgroup.fs.totals.flow.Fl_O:tot:P (fc.Fl_O:tot:P) [lbf/inch**2] -> .Fl_I:tot:P (inlet.Fl_I:tot:P) [lbf/inch**2]
fc.subgroup.fs.totals.flow.Fl_O:tot:S (fc.Fl_O:tot:S) [Btu/(lbm*degR)] -> .Fl_I:tot:S (inlet.Fl_I:tot:S) [Btu/(lbm*degR)]
fc.subgroup.fs.totals.flow.Fl_O:tot:T (fc.Fl_O:tot:T) [degR] -> .Fl_I:tot:T (inlet.Fl_I:tot:T) [degR]
@thearn
thearn / sklearn_example.py
Last active December 19, 2015 01:39
Scikit-learn example
import random
from sklearn import svm
from sklearn.grid_search import GridSearchCV
import pylab
import numpy as np
data = []
labels = []