Skip to content

Instantly share code, notes, and snippets.

View rjcorwin's full-sized avatar

R.J. (Steinert) Corwin rjcorwin

  • Khan Academy
  • Burlington, VT
View GitHub Profile
@rjcorwin
rjcorwin / image-lists-to-jcarousels.js
Created December 27, 2011 03:11
Turn lists of images into jCarousels.
$(function() {
var contentArea = '#content-area';
// Look at all unordered lists and label them as allImages if appropriate
$(contentArea + ' ul').each(function(index) {
var list = this;
$(this).children('li').each(function(index) {
// @todo Someone could make this test more bullet proof.
if($(this).html().substr(0, 4) != "<img") {
list.isNotCarousel = true;
@rjcorwin
rjcorwin / tranform_a_text_file.js
Last active October 8, 2015 11:28
Transform text in a file into another file, line by line. Handy for cleaning up CSV files. A node.js example.
var BufferedReader = require ("buffered-reader")
var BufferedWriter = require ("buffered-writer")
var $ = require ("jquery")
var targetFile = "target.txt"
var sourceFile = "source.txt"
var linesArray = []
var transform = function (line) {
// your transform here
return line;
@rjcorwin
rjcorwin / simple-file-attachment-for-couchdb.html
Created November 14, 2012 20:03
A very basic example in Javascript of how to attach a file to a CouchDB document. This will work wether or not the Document ID you define exists.
<!DOCTYPE html>
<! --
A very basic example in Javascript of how to attach a file to a CouchDB document. This will work wether or not the Document ID you define exists.
Log in at /_utils, upload this file to a document, and then view it for your own uploader. See the code for comments. ajaxSubmit() is the magic that attaches
as long as the Couch Doc exists because you can't submit a new Couch Document with an attachment.
by @rjsteinert http://rjsteinert.com
-->
<html xmlns="http://www.w3.org/1999/xhtml">
@rjcorwin
rjcorwin / create-a-file-and-upload-as-attachment-to-couchdb.js
Created November 15, 2012 15:35
With Javascript, create a new file and send it to a CouchDB database as an attachment to a document
// With Javascript, create a new file and send it to a CouchDB database as an attachment of a Document
// Code inspired by "NEW TRICKS IN XMLHTTPREQUEST2" by Eric Bidelman
// http://www.html5rocks.com/en/tutorials/file/xhr2/
/*
* There are two ways of accomplishing this. The first way will always result in a filename of "blob", which is
* bummer. The second way you will be able to name the file what you want. Note that these examples
* assume you have the ID of the database, the ID of the Document, and the most recent revision hash of that Document.
*/
@rjcorwin
rjcorwin / reduce.js
Created November 29, 2012 20:35 — forked from greatseth/reduce.js
couchdb reduce function to find min value
function (key, values, rereduce) {
var min = Infinity
for (var i = 0; i < values.length; i++) {
if (typeof values[i] == 'number') {
min = Math.min(values[i], min)
}
}
return min
@rjcorwin
rjcorwin / sparky.c
Created December 8, 2012 00:27
(by robrock) arduino code that will get electronic flame weeder ignition/electronic LP solenoid on/off sparking when the temperature measured by the thermocouple falls beneath a set threshold
const int numReadings = 10;
int readings[numReadings];
int index = 0;
int total = 0;
int average = 0;
int led = 9;
int inputPin = A0;
void setup()
@rjcorwin
rjcorwin / all_resources.php
Created December 18, 2012 19:20
An example of using the CouchDB client for PHP (https://github.com/dready92/PHP-on-Couch)
<?php
session_start();
error_reporting(1);
// A handy library for talking to CouchDB (https://github.com/dready92/PHP-on-Couch).
// You could use another library to make pure HTTP calls but sometimes using this couch library is just easier because
// it is very concise.
require_once 'couch.php';
require_once 'couchClient.php';
@rjcorwin
rjcorwin / TrailDB.md
Last active December 14, 2015 11:39
Idea for a JSON object that lives on the file system. It's like a key value store where your keys forge a trail so clients can find just the data they are looking for without having to use SQL or map reduce. TrailDB?

This JSON object... Check it out.

{
  "slogan": "Simplicity is the key to our values",
  "theAnswer": 42,
  "isAwake": true,
  "shoppingList: [
 "water", 
@rjcorwin
rjcorwin / ka-lite-schema.sql
Created March 7, 2013 00:30
I ran a .schema on a ka-lite database and tried to prune out the Django specific tables so we can see the data model that ka-lite is working with.
CREATE TABLE "main_exerciselog" (
"signed_version" integer NOT NULL,
"user_id" varchar(32),
"complete" bool NOT NULL,
"deleted" bool NOT NULL DEFAULT 0,
"completion_timestamp" datetime,
"counter" integer NOT NULL,
"zone_fallback_id" varchar(32),
"signature" varchar(360) NOT NULL,
"signed_by_id" varchar(32),
{
"slug": ""
"path": "/"
"children": [
{
"slug":"foo",
"path":"/foo"
"children": [
{},
{},