Skip to content

Instantly share code, notes, and snippets.

@RyanHope
RyanHope / Hybrid2.js
Created February 3, 2012 02:58
Enyo Hybrid Kind that works on all webOS Devices
enyo.kind({
name: 'Hybrid2',
kind: enyo.Hybrid,
rendered: function() {
this.pluginReady = false;
if (this.hasNode()) {
if (this.passTouchEvents) {
this.node.addEventListener("touchstart", this.nullTouchHandler);
@RyanHope
RyanHope / charSelector.js
Created February 11, 2012 01:53
A Enyo version of the Mojo character selector.
enyo.kind({
name: 'charKey',
kind: "CustomButton",
width: '50px',
height: '50px',
layoutKind: 'HFlexLayout',
pack: 'center',
align: 'center',
style: 'border-width: 1px; border-color: gray;',
@RyanHope
RyanHope / index.html
Created February 13, 2012 02:22
Device specific css files.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="src/css/pre.css" media="only screen and (min-device-width : 320px) and (max-device-width : 480px)">
<link rel="stylesheet" href="src/css/pre3.css" media="only screen and (min-device-width : 480px) and (max-device-width : 800px)">
<link rel="stylesheet" href="src/css/touchpad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)">
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
<title>wTerm App</title>
<script src="/usr/palm/frameworks/enyo/1.0/framework/enyo.js" launch="nobridge" type="text/javascript"></script>
@RyanHope
RyanHope / pygamesupport.py
Created February 22, 2012 00:42
Integrate PyGame with twisted.internet's mainloop.
import pygame
def _update( callback, fps, reactor, clock ):
if not callback():
reactor.stop()
else:
delay = 1.0 / fps - ( clock.tick() / 1000.0 - ( 20.0 / fps ) / fps )
if delay < 0:
reactor.callLater( 0 , _update, callback, fps, reactor, clock )
else:
@RyanHope
RyanHope / test.py
Created March 2, 2012 00:14
Panglery Test
from panglery import Pangler, PanglerAggregate
class Common( object ):
pangler = Pangler()
class Listener1( Common ):
@Common.pangler.subscribe( e = "eventA", needs = ['event'] )
@RyanHope
RyanHope / Socket.js
Created March 25, 2012 01:56
Enyo Kind for HTML5 WebSockets
/**
* Copyright (c) 2012 Ryan M. Hope <rmh3093 at gmail dot com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@RyanHope
RyanHope / useragent.js
Created March 25, 2012 21:45
Lookup WebSocket support based on browser user agent
UA_FIREFOX = new RegExp(".*Firefox/([0-9+]*).*")
UA_CHROME = new RegExp(".*Chrome/([0-9+]*).*")
UA_CHROMEFRAME = new RegExp(".*chromeframe/([0-9]*).*")
UA_WEBKIT = new RegExp(".*AppleWebKit/([0-9+\.]*)\w*.*")
UA_WEBOS = new RegExp(".*webOS/([0-9+\.]*)\w*.*")
var matchRegex = function(s, r) {
var m = r.exec(s)
if (m) return m[1]
return m
import numpy as np
import scipy, scipy.signal
def savitzky_golay( y, window_size, order, deriv = 0 ):
r"""Smooth (and optionally differentiate) data with a Savitzky-Golay filter.
The Savitzky-Golay filter removes high frequency noise from data.
It has the advantage of preserving the original shape and
features of the signal better than other types of filtering
approaches, such as moving averages techhniques.
Parameters
@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="|")
@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()