Skip to content

Instantly share code, notes, and snippets.

View 123andy's full-sized avatar

Andy Martin 123andy

  • Stanford University
  • Stanford, CA
View GitHub Profile
@123andy
123andy / SQL for Lookups of Enums.MD
Last active August 6, 2025 22:11
REDCap Dyanmic SQL to lookup Enumerated Fields

See Community post: https://redcap.vumc.org/community/post.php?id=259667&comment=259668

Background

I was working on a dynamic sql field, but ran into a snag where one of the data elements I wanted to include in the label was a dropdown. So, instead of piping the label of the field into the visible part of the dynamic sql, I put the numerical key.

As a challenge, I spent the next few hours trying to hack a sql solution for replacing the value with the label and got something that seems to work. The following is the story:

So, the intended sql label was to look something like this:

@123andy
123andy / README.md
Last active August 11, 2025 19:09
Automating Stanford's New Project Survey (as of 2025-07-07)

Automating Stanford's New Project Survey

This assumes you are using Google Chrome browser.

It is a recording of the submission of the standard new project survey (as of 2025-07-07)

Setup

Follow the instructions here: https://www.perplexity.ai/search/0cd872cc-1556-4edb-82e0-803dabe4063e

  • enable DevTools
  • activate the Recorder (under 'More Tools' in the hamburger menu)
@123andy
123andy / PB
Last active March 22, 2025 20:28
# Test PiHole Block List
0.0.0.0 perplexity.ai
@123andy
123andy / puzzle.php
Created October 28, 2024 22:55
Airplane boarding puzzle
Sample Output:
Airplane Boarding Problem
Ran simluation a total of 10000 times boarding 100 people per plane.
A total of 4970 of 10000 times (49.7%) the last passenger got their assigned seat.
The number of non-assigned passengers varied from 0 to 14 with an avg of 5.1828
Winners: 4970
The number of non-assigned passengers varied from 0 to 13 with an avg of 4.6796780684105
@123andy
123andy / gist:ade63284496877e1ad40eb5f03265ad2
Last active November 17, 2022 00:50
A Plugin for Gzipping old Edocs for local EDOC storage on REDCap
<?php
/**
This is a plugin that was used to gzip old edocs that were created prior to when REDCap introduced Gzip.
Which was with version 6 in 2014! So, if you've only been REDCapping for a while, then this might not
have that much importance. If, like us, you've got an old instance with lots of old files, this could save
you some substantial disk space
Compressing old .csv, .r, .xls, .sas exports can free up about 90% of their previous storage space.
@123andy
123andy / migrateLogEventTable
Created May 4, 2022 18:31
A MySql procedure to help migrate log entries from one table to another in REDCap
create
definer = andy123@`10.130.0.0/255.255.0.0` procedure migrateLogEventTable(IN pid int, IN source_table varchar(255),
IN target_table varchar(255))
p1:BEGIN
set @pid = pid;
set @source_table = source_table;
set @target_table = target_table;
-- MAKE SURE WE ARENT MOVING TO SAME TABLE!
@123andy
123andy / example.php
Created March 17, 2022 21:38
Example template for a context token
function getContextToken (
$project_id = null,
$record = null,
$event_id = null,
$module_prefix = self::_PREFIX,
$custom = [],
$duration_valid_in_mins = 5
) {
// refactor to allow passing parameters in an array as a single argument as well
@123andy
123andy / ideas.sql
Created June 24, 2020 17:57
Ideas for a REDCapDataQuery class to convert queries to SQL
-- main
set @PID = 19184;
set @EID = 115110;
set @F1 = 'rsp_prt_portal_email';
set @F2 = 'rsp_prt_portal_phone';
set @F3 = 'rsp_prt_portal_url';
set @F4 = 'rsp_prt_start_date';
set @F5 = 'rsp_prt_disable_email';
set @F6 = 'rsp_prt_disable_sms';
@123andy
123andy / RepeatingForms
Created April 17, 2020 17:18
A helper object for working with repeating forms in REDCap - this is a WIP...
<?php
class RepeatingForms
{
// Metadata
private $Proj;
private $pid;
private $is_longitudinal;
private $data_dictionary;
private $fields;
private $events_enabled = array(); // Array of event_ids where the instrument is enabled
@123andy
123andy / records.php
Last active April 15, 2020 17:11
Record Exists and reserveNewRecordId
<?php
class Record
{
/**
* DETERMINE IF A RECORD RESERVED (private method)
* See if a record is reserved in the new_record_cache table
*
* @param $project_id