Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys,os
# For general environment
from twisted.internet import reactor
from twisted.internet.task import LoopingCall, Cooperator
from twisted.protocols.basic import LineReceiver
from twisted.internet.protocol import Factory
import json
@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):
@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 / 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
<html xmlnx="http://wwww.w3.org/1999/xhtml">
<head>
<title>Killa Lipstick</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<div id="wrapper">
<div id="header">
@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 / 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 / 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 / pygame_twisted.py
Created September 12, 2012 16:46
PyGame / Twisted integration with fixed fps screen updating and fast as possible event processing.
#!/usr/bin/env python
from twisted.internet import reactor
from twisted.internet.task import LoopingCall, Cooperator
import pygame
import pygame.font
pygame.display.init()
pygame.font.init()
@RyanHope
RyanHope / cumhist.R
Created August 24, 2012 00:51
Cumulative Histogram
cumhist <- function(x, data=NULL, ...) {
terms<-as.character(x)
rhs<-terms[length(terms)]
splt<-strsplit(rhs,split="|", fixed=T)[[1]]
var<-splt[1]
grp<-splt[2]
lhs<-paste("ecdf(",var,")(",var,")", sep="")
ff<-paste(lhs, var, sep="~")
if(!is.na(grp)) {
ff<-paste(ff,grp,sep="|")