Skip to content

Instantly share code, notes, and snippets.

ks.default <- function(rows) seq(2, max(3, rows %/% 4))
many_kmeans <- function(x, ks = ks.default(nrow(x)), ...) {
ldply(seq_along(ks), function(i) {
cl <- kmeans(x, centers = ks[i], ...)
data.frame(obs = seq_len(nrow(x)), i = i, k = ks[i], cluster = cl$cluster)
})
}
all_hclust <- function(x, ks = ks.default(nrow(x)), point.dist = "euclidean", cluster.dist = "ward") {
@gjkerns
gjkerns / powerSampleSize.R
Created January 13, 2012 19:30
Simulation for determining sample size in Repeated Measures ANOVA
# Simulation study for sample size between/within
# got Treat + Sham between subjects
# got Time within subjects
nPerGroup <- 30
nTime <- 4
muTreat <- c(37, 32, 20, 15)
muSham <- c(37, 32, 25, 22)
stdevs <- c(12, 10, 8, 6)
stdiff <- 9
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@seberg
seberg / rolling_window.py
Created October 10, 2012 14:38
Multidimensional rolling_window for numpy
def rolling_window(array, window=(0,), asteps=None, wsteps=None, axes=None, toend=True):
"""Create a view of `array` which for every point gives the n-dimensional
neighbourhood of size window. New dimensions are added at the end of
`array` or after the corresponding original dimension.
Parameters
----------
array : array_like
Array to which the rolling window is applied.
window : int or tuple
@fabianp
fabianp / svd_memory.py
Created December 10, 2012 14:10
Timings and memory consumption for the singular value decomposition implemented in scipy. The script svd_memory.py generates a plot about the memory consumption (requires the package `memory_profiler`) and the second one will plot the timings. The scripts will perform several iterations for matrices of different sizes and will take about 30 minu…
# .. Memory benchmarks for SciPy's Singular Value Decomposition ..
# .. Author: Fabian Pedregosa <fabian@fseoane.net>
import numpy as np
from scipy.sparse import linalg as splinalg
from scipy import sparse, linalg
import pylab as pl
from memory_profiler import memory_usage
dims = np.arange(500, 1500, 20)
@ashwin
ashwin / latex-letter.tex
Created January 2, 2013 06:31
Simple letter template for LaTeX
%-----------------------------------------------------------------------------%
% Letter class
\documentclass[a4paper, 10pt]{letter}
% Name of sender
\name{Joe Fox}
% Signature of sender
\signature{Joe Fox}
@xuanlongma
xuanlongma / nc2tiff.R
Last active March 30, 2024 20:01
From netCDF to GeoTIFF using R
require(ncdf)
require(raster)
## Input: a netCDF file
file.nc <- 'rain.nc'
## Output: a GeoTIFF file
file.tiff <- 'rain.tiff'
## Import netCDF
@bertbalcaen
bertbalcaen / Extract all frames from a 24 fps movie using ffmpeg
Last active April 6, 2021 09:02
Extract all frames from a 24 fps movie using ffmpeg
ffmpeg -i shame-run.mov -r 24/1 test/output%03d.jpg
@mabdrabo
mabdrabo / sound_recorder.py
Created January 28, 2014 23:05
Simple script to record sound from the microphone, dependencies: easy_install pyaudio
import pyaudio
import wave
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"