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
@thearn
thearn / array_squared_error.py
Created January 24, 2015 16:18
Array Squared Error Component
from openmdao.main.api import Component
from openmdao.main.datatypes.api import Float, Array
import numpy as np
class ArraySquaredError(Component):
"""
Computes the square of the norm of the distance (error) between two
n-dimensional arrays "current" and "target", with analytic derivatives.
Meant for use in models which seek to minimize the distance/error between
from openmdao.main.api import Component
from openmdao.lib.datatypes.api import Float, Array, Str
from rk4 import RK4
import numpy as np
import pylab
# http://www.math.psu.edu/tseng/class/Math251/Notes-Predator-Prey.pdf
from openmdao.main.api import Component
from openmdao.lib.datatypes.api import Float
import numpy as np
from itertools import combinations
class ActuatorDisc(Component):
"""Simple wind turbine model based on actuator disc theory"""
# inputs
@thearn
thearn / fft_analysis.py
Last active August 29, 2015 13:58
FFT basics
import numpy as np
import pylab
# make some random data
x = np.random.randn(15)
# get length of data
n = len(x)
# compute PSD (square of the abs of the fft values)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

The Project Euler Sprint Hack Nights

Project Euler Sprint Hack Nights are beginner friendly events where you can work on your own projects or engage in a friendly competition called the Project Euler Sprint.

The Project Euler Sprint is a friendly competition involving solving Project Euler ([http://projecteuler.net][projecteuler]) problems for points. Project Euler is a series of increasingly difficult computational math problems that must be solved with code (generally speaking - we've had some impressive solutions in pen and paper as well as on an Excel spreadsheet).

Each problem is harder than the last, so each problem is worth its problem number in points. Problem #1 is easy, so it's worth 1 point, while problem #50 is much harder, but worth 50 points. You can form teams of 4 people and solutions can be in any language as long as it's coded there. More detailed rules below.

Sprint Rules

@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 = []
@thearn
thearn / capture.py
Created June 15, 2013 21:31
Screen capture using python PIL
import time
import Image
import ImageGrab
while True:
time.sleep(0.5)
t = str(time.time()).replace('.','-')
tt = time.time()
img=ImageGrab.grab()
img = img.resize((800,600))
@thearn
thearn / microscope.py
Last active December 17, 2015 09:29
Code to operate USB microscope, with selectable contrast correction
import cv2
# Create object to read images from camera 0
cam = cv2.VideoCapture(1)
class imgSlice(object):
def __init__(self):
self.x = 0