Skip to content

Instantly share code, notes, and snippets.

View natevw's full-sized avatar

Nathan Vander Wilt natevw

View GitHub Profile
@natevw
natevw / multi_id_test.html
Created June 20, 2019 23:09
Testing whether querySelectorAll finds multiple elements with #non_unique id.
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>Testing multiple ids</title>
</head><body>
<p id="one">
<span id="not_unique">One</span>
</p>
<p id="two">
<span id="not_unique">Two</span>
@natevw
natevw / xed_better.sh
Last active April 8, 2019 06:35
Better `xed` — the CLI tool for Xcode is handy, but has a few issues that get in the way. For starters, if the file doesn't exist, the builtin `x\ed` won't create a new one. I also noticed that Xcode will open a symlink and let you edit, but then gets really angry when it tries to save. So…this.
alias xed='function _xed() { [ ! -f $1 ] && touch $1; xed `python -c "import os,sys;print os.path.realpath(sys.argv[1])" $1`; };_xed'
@natevw
natevw / psc↔pdx|sea transportation schedules.md
Last active August 30, 2018 21:24
Direct connections available between the Tri-Cities and Portland or Seattle, with approximate prices as of 2013 April.

All price estimates are for one-way. Car and train and bus return doubles price, air has significant discount for round trip.

TODO: For longer trips it can be a little cheaper to ride Amtrak by signing up for rewards, buying miles, then booking tickets; haven't calculated cost for Portland yet.

PSC ↔ PDX

Car $26

Downtown Portland is about 215 miles from the Tri-Cities and takes about 3h30m. Cost calculated with gas at $3.69/gal and fuel economy averaging 30mpg (i.e. 12.3¢/mile).

@natevw
natevw / spi_http_example.js
Created June 15, 2016 17:23
A quick little script showing someone a general outline of bridging a hardware SPI device to an HTTP api via node.js. It's fairly terse, but I tried to provide a few documentation and project links for further exploration.
var SPI_DEV = "/dev/spidev0.0", // hardware will be connected to pins matching a certain Linux SPI device
HTTP_PORT = 0, // if you leave 0, a port gets randomly assigned
POLL_INTERVAL = 1e3; // equivalent to 1 second, set to `20` for 20 milliseconds
// this global variable will store the values
var most_recent_value = null;
var spiInstance = require('pi-spi').initialize(SPI_DEV); // this sets up the SPI device for use in node.js
// then we register a timeout that will get called repeatedly at an approximate interval
@natevw
natevw / python_interact_debug_snippet.py
Last active June 8, 2016 19:33
Helpful Python snippet to drop into code and get an instant "playground" at a breakpoint
# see e.g. http://stackoverflow.com/a/7677387/179583
import code
code.interact(local=dict(globals(), **locals()))
@natevw
natevw / webrtc-dataconnection.html
Last active May 8, 2016 20:52
WebRTC data connection testing, works in both Chrome and Firefox but not expected to between until they gain interop (and this only communicates within a single page anyway…) You'll likely need to host "somewhere" (e.g. `python -m SimpleHTTPServer`) rather than opening file directly.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WebRTC p2p data</title>
<script src="https://webrtc-samples.googlecode.com/svn/trunk/apprtc/js/adapter.js"></script>
</head>
<body>
Testing WebRTC connection.
@natevw
natevw / AppDelegate.m
Last active March 14, 2016 23:10
Hook this up to a coupla text boxes and see NSAnimation only ever do 60fps, picture of sample interface at https://twitter.com/natevw/status/709516893917319168
@interface MyAnimation : NSAnimation {}
@property NSUInteger frameCount;
@end
@implementation MyAnimation
- (void)startAnimation {
_frameCount = 0;
[super startAnimation];
}
@natevw
natevw / fermata.bigcouch.js
Last active December 31, 2015 02:09
Cloudant-specific Fermata plugin to treat write quorum failures as an error. (BigCouch returns a 202 status code which would normally be considered "successful", but the update could still end up lost or in conflict. So you may prefer to handle more similarly to a 500. Note that in this case, the best strategy AFAICT is to *write* until a 201 is…
// WORKAROUND: custom statusCheck to treat 202 responses as an error
// if Cloudant sends this, we can't be sure the write won't conflict
// see https://github.com/cloudant/bigcouch/issues/55
// and https://cloudant.com/for-developers/faq/data/
// and http://bigcouch.cloudant.com/api
// it's futile to attempt a unanimous quorum read to be sure (r=N is only advisory)
// so…assume the worst (e.g. conflicting or lost update) and treat these like a 500
// NOTE: this is copy-pasta from Fermata's builtin plugins.
fermata.registerPlugin('statusCheck_bigcouch', function (transport) {
return function (request, callback) {
@natevw
natevw / gist:7885121
Created December 10, 2013 03:02
extract timestamp/waterTemp aka random notes on (horrible) shell-scripting that (halfway) worked
cat /media/data_usb/logging/greenhouse.log | strings | sed -r 's/^([^ ]+).*waterTemp=([0-9]+).*$/\1 \2/'