Skip to content

Instantly share code, notes, and snippets.

@allenaven
allenaven / FFTutils.R
Created August 4, 2012 16:03
FFT utilities from stackoverflow user nico in this community wiki: http://stackoverflow.com/questions/3485456/useful-little-functions-in-r
# Gets the frequencies returned by the FFT function
getFFTFreqs <- function(Nyq.Freq, data)
{
if ((length(data) %% 2) == 1) # Odd number of samples
{
FFTFreqs <- c(seq(0, Nyq.Freq, length.out=(length(data)+1)/2),
seq(-Nyq.Freq, 0, length.out=(length(data)-1)/2))
}
else # Even number
{
@allenaven
allenaven / HMMpractice.R
Created November 15, 2012 05:55
practice with HMMs and plotting them with R pkg RHmm
## HIDDEN MARKOV MODEL practice...
library(RHmm)
# Sim up some financial market data...
bear <- rnorm(100, -0.01, 0.20)
bull1 <- rnorm(100, 0.1, 0.10)
bull2 <- rnorm(100, 0.11, 0.08)
@allenaven
allenaven / closestTime.R
Created December 7, 2012 19:24
Match a time datum with the nearest time in a vector of times
### Function to match a time datum with the closest time in another (for, say, finding water heights)
closest.time <- function(in.datum, ref.vec){
return(which.min(abs(difftime(in.datum, ref.vec, units="secs"))))
}
@allenaven
allenaven / ggplot2_IMPROVE.R
Last active September 21, 2017 17:09
Improve the standard ggplot2 plot! Increase text size, get rid of the grey background!!!
## library(devtools)
## source_gist(7489113)
## use like this: ggplot(mtcars, aes(x=hp, y=mpg)) + geom_point(aes(col=factor(cyl)), size=3) + t1
t1 <- theme(
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
@allenaven
allenaven / IIPP_Proj_4.py
Last active August 29, 2015 14:00
Coursera IIPP Mini-project number 4
import simplegui
my_number = int(0)
n_stops = int(0)
n_stops_on_zero = int(0)
is_running = False
def timer_handler():
global my_number
my_number += 1
@allenaven
allenaven / Color_Sort_PCA.R
Last active August 29, 2015 14:03
An R port of CDP's Python script to sort RGB color values using principal components analysis
##### Recreate Cam Davidson Pilon's Python script to sort RGB color values
##### using Principal Components Analysis:
library(scatterplot3d)
## Make a function to plot a series of color values in rectangles:
plot_colors <- function(values) {
# Note, this function takes an matrix of dimensions (n, 3) of numbers
# between 0 and 1 for RGB values. Plotspace is between 0 and 100 for x and y
x <- 0:100
@allenaven
allenaven / circular_plot.R
Created June 30, 2014 22:13
Plot circular with R and ggplot2
# The circular conversion/transformation:
library(circular)
library(ggplot2)
k <- rad(360)
u <- runif(100000, 0, 359)
x <- cos(rad(u) * 2 * pi) / k
y <- sin(rad(u) * 2 * pi) / k
@allenaven
allenaven / NBA_54_game_winners
Last active August 29, 2015 14:03
NBA teams that won 54 games in one season, and whether they won the NBA championship that year (coded 1/0 for win / no win)
Pct,Won,Lost,Home,Away,Neutral,Diff,Team,Season,Result
.878,72,10,39-2,33-8,0-0,12.2,ChicagoBulls,1995-96,1
.841,69,13,36-5,31-7,2-1,12.3,LosAngelesLakers,1971-72,1
.841,69,13,39-2,30-11,0-0,10.8,ChicagoBulls,1996-97,1
.829,68,14,33-6,32-8,3-0,8.2,BostonCeltics,1972-73,0
.840,68,13,28-2,26-8,14-3,9.4,Philadelphia76ers,1966-67,1
.817,67,15,36-5,31-10,0-0,7.2,DallasMavericks,2006-07,0
.817,67,15,40-1,27-14,0-0,9.4,BostonCeltics,1985-86,1
.817,67,15,36-5,31-10,0-0,10.4,ChicagoBulls,1991-92,1
.817,67,15,36-5,31-10,0-0,8.5,LosAngelesLakers,1999-00,1
@allenaven
allenaven / Thousanth_prime.py
Created August 13, 2014 13:53
Find 1000th prime number
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 12 23:54:45 2014
@author: Allen
"""
primes = [2] # Vector of prime numbers: initialize with 2, since that is
# a prime number but fails the tests

Keybase proof

I hereby claim:

  • I am allenaven on github.
  • I am aven (https://keybase.io/aven) on keybase.
  • I have a public key whose fingerprint is D674 B45A F42C 888B 3AEA 40C1 7A58 8D55 9755 D1ED

To claim this, I am signing this object: