Skip to content

Instantly share code, notes, and snippets.

@RyanHope
RyanHope / errorBounds.R
Created September 12, 2012 23:04
R/lattice xyplot with error bounds
#
# From Hmisc, pasted here so as to not need any deps for this demo
#
Cbind <- function (...)
{
dotlist <- list(...)
if (is.matrix(dotlist[[1]])) {
y <- dotlist[[1]]
ynam <- dimnames(y)[[2]]
if (!length(ynam))
@RyanHope
RyanHope / pangler_test.py
Created September 23, 2012 23:03
Pangler Test
from panglery import Pangler
class Dispatcher(Pangler):
def listen(self, event):
def decorator(target):
@self.subscribe(e=event)
def wrapper(*args, **kwargs):
return target(*args, **kwargs)
return wrapper
@RyanHope
RyanHope / changes.R
Created October 5, 2012 13:41
Find the indices of a vector where the data changes.
changes <- function(x) {
r <- rle(x)$lengths
c(0,cumsum(r[1:length(r)-1]))+1
}
@RyanHope
RyanHope / carbonation.R
Created June 24, 2013 16:48
Slow Force Carbonation Functions for R
bars <- function(temp, psi) {
(psi+14.695)*(0.01821+0.090115*exp(-(temp-32)/43.11))-0.003342
}
psi <- function(bars, temp) {
((bars+0.003342)/(0.01821+0.090115*exp(-(temp-32)/43.11)))-14.695
}
temp <- function(bars, psi) {
-log(((bars+0.003342)/(psi+14.695)-0.01821)/0.090115)*43.11+32
@RyanHope
RyanHope / PyViewX_Video_Stream_Test.py
Last active December 25, 2015 02:39
A test of video stream on an SMI eyetracker using the PyViewX package.
#!/usr/bin/env python
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),"pyviewx.client"))
sys.path.insert(1, os.path.join(os.path.dirname(os.path.realpath(__file__)),"pyviewx.pygame"))
from pyviewx.client import iViewXClient, Dispatcher
from pyviewx.pygame import Calibrator
from twisted.internet import reactor
@RyanHope
RyanHope / browser.py
Last active January 4, 2016 09:58
A simple Python script that renders a URL in a simple window using PySide/Qt.
#!/usr/bin/env python
import sys, os
import argparse
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
class ValidateURL(argparse.Action):
def __call__(self, parser, args, values, option_string=None):
#include "Rcpp.h"
using namespace std;
using namespace Rcpp;
NumericMatrix lowPass6xDecX(NumericMatrix src)
{
const int ws = src.ncol(), h = src.nrow();
const int h2 = h * 2, h3 = h * 3, h4 = h * 4, h5 = h * 5;
int wr = ws / 2;
#include "Rcpp.h"
using namespace std;
using namespace Rcpp;
/*
inline unsigned char saturate( float x )
{
return x > 255.0f ? 255
: x < 0.0f ? 0
// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#include <Rcpp.h>
using namespace Rcpp;
// GaussianSubsample
NumericMatrix GaussianSubsample(NumericMatrix img);
RcppExport SEXP gazetools_GaussianSubsample(SEXP imgSEXP) {
#include "Rcpp.h"
using namespace std;
using namespace Rcpp;
/*
inline unsigned char saturate( float x )
{
return x > 255.0f ? 255
: x < 0.0f ? 0