Skip to content

Instantly share code, notes, and snippets.

View rsbohn's full-sized avatar

Randall Bohn rsbohn

  • Rando Media
  • Orem Utah USA
View GitHub Profile
@rsbohn
rsbohn / stringdiff.py
Created October 21, 2011 20:24
show differences in strings -- uses SequenceMatcher
from difflib import SequenceMatcher
def diff(actual, expected):
if actual != expected:
raise AssertionError(combine(actual, expected))
def combine(a,b):
"""Form one string showing the differences between a and b."""
sm = SequenceMatcher(None, a,b)
out = []
@rsbohn
rsbohn / watchdog.js
Created November 11, 2011 23:44
Software watchdog in Javascript
// Use a watchdog to control functions that may take too long.
// You might use a watchdog to update the UI if your JSONP script fails to load
// in a timely manner.
function may_fail(n, slot) {
setTimeout(function(){
//stop processing if the watchdog fired
if (dog[slot] == "FIRED") {
console.log("<may_fail slot='"+slot+"'> FAILED");
return;
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SoundCloud OAuth 2 User Agent Authentication Flow Demo</title>
<script type="text/javascript" charset="utf-8" src="javascript/jquery-1.4.2.js"></script>
<script type="text/javascript" charset="utf-8">
$(function () {
var extractToken = function(hash) {
@rsbohn
rsbohn / a421x98.krl
Created November 25, 2011 20:59
leaky abstraction
ruleset a421x98 {
meta {
name "Leaky Abstraction"
description <<
>>
author "Randall Bohn"
logging off
}
@rsbohn
rsbohn / bootstrap.cmd
Created December 15, 2011 17:56
How I got node.couchdb.js working on Windows
REM Set up workspace
mkdir \work\node_modules
cd \work\node_modules
REM check out modules
cmd /c git clone https://github.com/mikeal/node.couchapp.js.git couchapp
cmd /c git clone https://github.com/mikeal/request.git
cmd /c git clone https://github.com/mikeal/watch.git
REM create my_app
@rsbohn
rsbohn / server.js
Created February 9, 2012 16:14
When will the world end? jpocalypse.herokuapp.com
var http = require("http");
var port = process.env.PORT || 9944;
var somany = Math.round(port/10+10);
console.log("server.js on "+port);
console.log("The world will end in "+somany+" days.")
http.createServer(function(request, response) {
var status = 200;
@rsbohn
rsbohn / wild_servo.ino
Created February 14, 2012 06:07
Simple game on arduino
// wild_servo
// a game
// Your potentiometer controls the servo position
// But there is a region of instability in the center
// Keep the servo between 45 and 135 degrees
// Or the light flashes and you lose a point
// How long can you keep it going?
// Based on the servo>knob example code:
// Controlling a servo position using a potentiometer (variable resistor)
@rsbohn
rsbohn / win7-use-node.md
Created February 27, 2012 15:54
Run .js files using node.exe on Windows 7

Want to run node.js files on Windows 7 just by typing in the file name? Here's how I got it to work:

echo %pathext%

You should see .JS included in the list. This allows you to type in the script name (hello.js) and Windows will attempt to run it. Next you need to tell Windows to use node.exe instead of wscript.exe (Anyone still use that?) You'll need a CMD.exe window with Administrator privileges. Easy way to do that is to tap the 'Windows' key, type in CMD, right click when it appears in the menu and click 'Run as Administrator'. You may need a password.

When you have the CMD.exe window enter the following:

assoc .js=JavaScript

ftype JavaScript=node.exe %1 %*

@rsbohn
rsbohn / rule42.krl
Created March 1, 2012 21:06
Catch email from cloudmailin.com
// handle email from cloudmailin.com
// Set up an email address on cloudmailin.com
// Set the webhook URL to:
// http://cs.kobj.net/sky/event/:your_kynetx_token/:endpoint_id/email/recv
// (fill in :your_kynetx_token and :endpoint_id)
//
// Save these rules in a ruleset, then subscribe to the ruleset
// To test:
// Use the Kynetx Event Console, raise an event with domain=email and type=recv
// (This stores the event attributes in ent:postbox.)
@rsbohn
rsbohn / actor.py
Created March 14, 2012 13:41
Like ActionChains.py but it just does what you want. #selenium2 #webdriver #python
# Copyright 2012 Randall Bohn
# based on ActionChains.py:
# Copyright 2011 WebDriver committers
# Copyright 2011 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0