Skip to content

Instantly share code, notes, and snippets.

@nathanntg
nathanntg / regress_bins.m
Last active June 14, 2018 16:03
Regress Spectral Bins
% Example code for analysis of neural correlate with spectral differences.
% This looks at differences in spectral power (but will not uncover
% relationships between neural activity and timing differences, as all that
% is masked by the warping process; a similar approach could look at
% correlates between neural activity and amount of warping).
%% Step 1: warp spectrograms
% How the spectrogram is warped is important, as you want to avoid spectral
% artifacts of the warping process. The exact code will vary a bit
% depending on what spectral routine you are using.
@nathanntg
nathanntg / DelimitedSerialPacketDescriptor.swift
Created February 27, 2016 13:59
Delimited Serial Packet Descriptor
import ORSSerial
/// An example of an extension of the ORSSerialPacketDescriptor that enables identifying delimited packets.
class DelimitedSerialPacketDescriptor: ORSSerialPacketDescriptor {
var delimiter: NSData?
convenience init(delimiter: NSData, maximumPacketLength maxPacketLength: UInt, userInfo: AnyObject?, responseEvaluator: ORSSerialPacketEvaluator) {
self.init(maximumPacketLength: maxPacketLength, userInfo: userInfo, responseEvaluator: responseEvaluator)
// set delimiter
@nathanntg
nathanntg / SimpleCalculate2DArea.m
Last active August 29, 2015 14:10
Estimation of diffusion coefficient and directional bias
function [Area, Dsq, Time, AreaCoef, DCoef, angle, axisRatio, xyCorrelation, Mean, std_th] = SimpleCalculate2DArea(fix_x, fix_y, varargin)
%SIMPLECALCULATE2DAREA Summary of this function goes here
% This function calculates the are covered by the 2D displacement distribution
% at each delta t.
%
% function [Area] = DiffusionCoefficient2D (Fix,varargin)
%
% INPUT:
% Fix : matrix with the eye movements data. This matrix should be
% organized in the the following way:
@nathanntg
nathanntg / knapsack.py
Created November 22, 2014 02:58
Knapsack - Recurssive
import numpy as np
"""
This is NOT the polynomial time solution (should build lookup table instead).
"""
def knapsack(c, w, remaining_capacity, i=None):
"""
Recursively solve the knapsack problem to maximize utility given the remaining capacity and items with weight w
@nathanntg
nathanntg / html_regular_expressions.py
Last active August 29, 2015 14:09
HTML Regular Expressions
import re
# match all script blocks
r = re.compile('<script[^>]*?>.*?</script>', re.IGNORECASE | re.DOTALL)
# can be used to easily remove script tags
html_without_scripts = r.sub('', html)
# match all style blocks
r = re.compile('<style[^>]*?>.*?</style>', re.IGNORECASE | re.DOTALL)
# can be used to easily remove script tags
@nathanntg
nathanntg / dist_2d.m
Created November 2, 2014 13:59
Distribution of Nearest Neighbor
% number of random points to generate
number = 500;
x_dim = 100;
y_dim = 100;
% generate points
points = rand(number,2) * [x_dim 0; 0 y_dim];
% list of nearest neighbors
nearest_neighbors = nan(1, number);