Skip to content

Instantly share code, notes, and snippets.

View NathanEpstein's full-sized avatar

Nathan Epstein NathanEpstein

View GitHub Profile
@NathanEpstein
NathanEpstein / skewCharts.R
Created June 23, 2015 13:25
generating skewed normal plots in R
library(fGarch)
skew_plot = function(skewParam = 1, std=1, color = 'black', xmin = -5, xmax = 5) {
x <- seq(xmin, xmax, length = 200)
y <- dsnorm(x, sd=std, xi = skewParam)
plot(x, y, type = 'l', col = color)
}
add_line = function(skewParam = 1, std=1, color = 'black', xmin = -5, xmax = 5) {
x <- seq(xmin, xmax, length = 200)
y <- dsnorm(x, sd=std, xi = skewParam)
@NathanEpstein
NathanEpstein / insertsort.rb
Last active February 22, 2016 21:37
insertion sort in ruby
def insertion_sort(array)
for i in 1..array.length-1
j = i
while j > 0 && array[j-1] > array[j]
pivot = array[j]
array[j] = array[j-1]
array[j-1] = pivot
j -= 1
end
end
@NathanEpstein
NathanEpstein / insertsort.js
Created April 1, 2015 18:05
insertion sort in js
function insertSort(arr){
for (var i=1;i<arr.length;i++){
var j = i;
while ((j > 0) && (arr[j-1] > arr[j])){
var pivot = arr[j];
arr[j] = arr[j-1];
arr[j-1] = pivot;
j -= 1;
}
}
@NathanEpstein
NathanEpstein / boxMuller.rb
Last active February 22, 2016 21:47
Box Muller transform in ruby
def boxMuller()
u1, u2 = rand, rand
z1 = Math.sqrt(- 2 * Math.log(u1)) * Math.cos(2 * u2 * Math::PI)
z2 = Math.sqrt(- 2 * Math.log(u1)) * Math.sin(2 * u2 * Math::PI)
[z1,z2]
end
@NathanEpstein
NathanEpstein / data.js
Created February 20, 2015 20:59
D3 workshop at Code Crew Meetup 2/25/15
// Data Source: http://vincentarelbundock.github.io/Rdatasets/csv/cluster/votes.repub.csv
var data = {
'Alabama':{'X1968': '14', 'X1856': 'NA', 'X1876': '40.02', 'X1872': '53.19', 'X1912': '8.26', 'X1916': '21.97', 'X1964': '69.5', 'X1976': '43.48', 'X1896': '28.13', 'X1972': '72.4', 'X1892': '3.95', 'X1932': '14.15', 'X1956': '39.39', 'X1936': '12.82', 'X1952': '35.02', 'X1868': '51.44', 'X1860': 'NA', 'X1864': 'NA', 'X1904': '20.65', 'X1900': '34.67', 'X1908': '24.38', 'X1928': '48.49', 'X1884': '38.44', 'X1940': '14.34', 'X1960': '41.75', 'X1880': '36.98', 'X1944': '18.2', 'X1920': '30.98', 'X1948': '19.04', 'X1924': '27.01', 'X1888': '32.28'}
,
'Alaska': {'X1968': '45.3', 'X1856': 'NA', 'X1876': 'NA', 'X1872': 'NA', 'X1912': 'NA', 'X1916': 'NA', 'X1964': '34.1', 'X1976': '62.91', 'X1896': 'NA', 'X1972': '58.1', 'X1892': 'NA', 'X1932': 'NA', 'X1956': 'NA', 'X1936': 'NA', 'X1952': 'NA', 'X1868': 'NA', 'X1860': 'NA', 'X1864': 'NA', 'X1904': 'NA', 'X1900': 'NA', 'X1908': 'NA', 'X1928': 'NA', 'X1884': 'NA', '
@NathanEpstein
NathanEpstein / qsort.cpp
Created February 10, 2015 16:17
quicksort algorithm in C++
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
void qsort(vector<int>& v){
if (v.size() > 1){
int pivot = floor(v.size()/2);
vector<int> left;
@NathanEpstein
NathanEpstein / binsearch.cpp
Created February 9, 2015 15:43
binary search in C++
#include <vector>
#include <math.h>
#include <iostream>
using namespace std;
//get the index of a target integer from a sorted vector
int binSearch(const vector<int>& sorted, const int target){
const int mid = floor(sorted.size()/2);
@NathanEpstein
NathanEpstein / fifolifo.cpp
Created February 6, 2015 16:26
C++ implementation of queue and stack
#include <list>
#include <iostream>
using namespace std;
// Implement Q class
class Q{
public:
Q();
~Q();
@NathanEpstein
NathanEpstein / sort.cpp
Created February 3, 2015 18:40
bubble sort and merge sort in C++
#include <vector>
#include <math.h>
#include <iostream>
using namespace std;
//BUBBLE SORT IMPLEMENTATION
vector<double> bubbleSort(vector<double> arr){
bool pass = false; //have we passed through the array without a swap?
double temp;
@NathanEpstein
NathanEpstein / sorting.js
Last active August 29, 2015 14:14
bubble sort and merge sort in JS
bubbleSort = function(array){
var swaps = 0;
var comparisions = 0;
var bool = true;
if (array.length <= 1){
bool = false;
return array;
}