Skip to content

Instantly share code, notes, and snippets.

@cmacrander
cmacrander / deidentifier.js
Last active January 26, 2019 22:30
Functions for the deidentification tool.
var DEIDENTIFIER = (function () {
'use strict';
// ** Constants ** //
var separator = '\t', // what separates fields in a row
saltRegex = /^\S{20,40}$/, // 20-40 characters, no white space
tokenRegex = /^\S{3,}$/, // at least 3 characters, no white space
emailRegex = /^.+@.+$/, // @ with something before and after
tokenColumnName = 'plaintext_token',
@cmacrander
cmacrander / openApi.yaml
Last active December 23, 2018 05:00
API specification for a demo project, showing off openApi 3.0
openapi: 3.0.1
servers:
- url: https://macrander-toptal.appspot.com/api
description: Production server (uses live data)
- url: http://localhost:3002/api
description: Sandbox server (uses test data)
info:
description: Toptal Time Management
version: "1.0.0"
title: Toptal Time Management
@cmacrander
cmacrander / withData.js
Created December 23, 2018 03:29
`withData` React HOC for loading and flux-like data flow
import React from 'react';
import omit from 'lodash/omit';
const LoadingDefault = () => <div>Loading&hellip;</div>;
/**
* Higher-order component factory, acting as a layer between App and the scenes
* that want to load data. Pass in a scene component and a collection of
* functions that "select" i.e. pick out certain parts of the "appState" i.e.
* App's `this.state` to use as props. The scene will then only re-render when
@cmacrander
cmacrander / neptune_custom_portal_sample.php
Created January 20, 2017 22:28
Neptune Custom Portal (ISR) Sample
<?php
# Custom Portal Code Sample
# ----------------------------------------------------------------------------
#
# The purpose of this script is to demonstrate how institutions should
# handle a PERTS program participant and correctly return them to PERTS.
#
# The most up-to-date version of this script and other accompanying
# documentation is available at:
@cmacrander
cmacrander / promises_workshop.html
Created December 1, 2016 17:50
A small tutorial on promises, as a web page.
<!Doctype html>
<html>
<head>
<title>JavaScript Promises</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/q.js/0.9.2/q.min.js"></script>
</head>
<body>
<button id="the-button">Click Me</button>
@cmacrander
cmacrander / ctc_dynamic_content.js
Last active May 20, 2016 15:50
CTC Dynamic Content File
// CTC Dynamic Content File
if (window.perts === undefined) {
window.perts = {};
}
window.perts.dynamicContent = (function () {
'use strict';
var dynamicContent = {};
@cmacrander
cmacrander / completion_code_page.js
Created March 3, 2016 18:51
Qualtrics completion code javascript
var unloadEvent;
var listener;
Qualtrics.SurveyEngine.addOnload(function () {
'use strict';
// initially hides completion code
$j('#completion-code').hide();
var code = '${e://Field/mturk_code_part_1}';
q_unique_ed <- mutate(
q_unique,
#the reason for the repetitions is that I cannot figure out how to handle the NAs otherwise
mother_education = t1__demog__ed_level_m,
father_education = t1__demog__ed_level_f,
mother_education = ifelse(mother_education > 10,NA,mother_education),
father_education = ifelse(father_education > 10,NA,father_education),
mother_education = ifelse(is.na(mother_education),0,mother_education),
father_education = ifelse(is.na(father_education),0,father_education),
highest_parents_education = apply(data.frame(mother_education,father_education), 1, max),
// qualtrics.js
//
// Original author: CAM 2014-07-23
// CURRENTLY TESTING JFE COMPATIBILITY
//
// Purpose: Javascript file to be included in Qualtrics. Designed to be easy
// for survey writers and editors.
//
// Example javascript to be put in head of a survey:
/*
@cmacrander
cmacrander / query_string_to_object.js
Created November 11, 2015 19:30
queryStringToObject
// Read query string parameters as a javascript object.
//
// Not tested for:
//
// * Mixing bracketed and non-bracketed keys
// * Indexed brackets
// * Nested lists
//
// Some examples (See unit tests below for full details):
//