Skip to content

Instantly share code, notes, and snippets.

View danieljfarrell's full-sized avatar

Daniel danieljfarrell

View GitHub Profile
@danieljfarrell
danieljfarrell / gist:d1092dbdb5a46c864145
Created February 29, 2016 15:39
Command line instructions to prevent Finder.app from writing .Spotlight-V100 .Trashes ._.Trashes .disk .fseventsd to a mounted network disk
// http://apple.stackexchange.com/questions/6707/how-to-stop-os-x-from-writing-spotlight-and-trash-files-to-memory-cards-and-usb
mdutil -i off /Volumes/yourUSBstick
cd /Volumes/yourUSBstick
rm -rf .{,_.}{fseventsd,Spotlight-V*,Trashes}
mkdir .fseventsd
touch .fseventsd/no_log .metadata_never_index .Trashes
cd -
@danieljfarrell
danieljfarrell / 95conf.py
Created February 19, 2016 12:26
Python code implementing some of MATLAB's nlparci functionality (Nonlinear regression parameter confidence intervals)
def non_linear_parameters_95_percent_confidence_interval(fvec, jac):
"""Returns the 95% confidence interval on parameters from
non-linear fit results."""
# residual sum of squares
rss = np.sum(fvec**2)
# number of data points and parameters
n, p = jac.shape
# the statistical degrees of freedom
nmp = n - p
# mean residual error
@danieljfarrell
danieljfarrell / feature_matrix.py
Created December 3, 2015 07:36
Convert a feature-list Pandas data frame to a feature-matrix.
import pandas as pd
from sklearn.preprocessing import MultiLabelBinarizer
# Feature-list data frame
df = pd.DataFrame(columns = ["features"], index=['Item 1', 'Item 2'])
df['features'] = [["A", "B"], ["C", "D"]]
# Use scikits-learn to create feature matrix and feature names
mlb = MultiLabelBinarizer()
feature_column_name = 'features'
@danieljfarrell
danieljfarrell / addColumn_PyTables.py
Created September 4, 2015 15:17 — forked from swarbhanu/addColumn_PyTables.py
Example showing how to add a column in PyTables
from tables import *
# Isolated the copying logic
def append_column(table, group, name, column):
"""Returns a copy of `table` with an empty `column` appended named `name`."""
description = table.description._v_colObjects.copy()
description[name] = column
copy = Table(group, table.name+"_copy", description)
@danieljfarrell
danieljfarrell / gist:faf7c4cafd683db13cbc
Created March 30, 2015 12:32
Ray line segment intersection in Python using Numpy
import numpy as np
def magnitude(vector):
return np.sqrt(np.dot(np.array(vector),np.array(vector)))
def norm(vector):
return np.array(vector)/magnitude(np.array(vector))
def lineRayIntersectionPoint(rayOrigin, rayDirection, point1, point2):
"""
@danieljfarrell
danieljfarrell / gist:4dbe7c322c90318d78dc
Last active August 29, 2015 14:17
Generic parameter 'U' cannot be bound to non-@objc protocol type 'SceneObject'
extension Array {
mutating func removeObject<U: Equatable>(object: U) {
var index: Int?
for (idx, objectToCompare) in enumerate(self) {
if let to = objectToCompare as? U {
if object == to {
index = idx
}
}
}
@danieljfarrell
danieljfarrell / log.txt
Created April 3, 2014 09:44
Building scikits.odes
daniel@DJF2:~/dev/git/odes*development$ rm -rf build/
daniel@DJF2:~/dev/git/odes*development$ python setup.py install
=============================================
parent package is scikits
top path is /Users/daniel/dev/git/odes
=============================================
lapack_opt_info:
FOUND:
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
define_macros = [('NO_ATLAS_INFO', 3)]
@danieljfarrell
danieljfarrell / fipy_nonuniform_poisson_electrostatics.py
Created January 17, 2014 00:52
This script illustrates a failure with the finite volume method for an elliptical problem on a non-uniform mesh. For more information see the question and answer here, http://scicomp.stackexchange.com/questions/8577/peculiar-error-when-solving-the-poisson-equation-on-a-non-uniform-mesh-1d-only
from fipy import *
import numpy as np
"""
This script illustrates a failure with the finite volume method for an elliptical problem on a non-uniform mesh.
For more information see the question and answer here,
http://scicomp.stackexchange.com/questions/8577/peculiar-error-when-solving-the-poisson-equation-on-a-non-uniform-mesh-1d-only
"""
def fipy_step_charge():
@danieljfarrell
danieljfarrell / Polarisation matrix.ipynb
Created November 8, 2013 07:54
Attenuation of laser beam with crossed polarisers and optical isolators.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danieljfarrell
danieljfarrell / fvm_half_cell.ipynb
Last active December 25, 2015 04:09
Implementation a finite volume method with a half cell at one end.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.