Skip to content

Instantly share code, notes, and snippets.

@tertek
tertek / export_fields_with_comments.sql
Last active January 7, 2021 11:21
SQL to export fields with all comments from REDCap
SELECT d.record, d.field_name, d.value, dqr.comment, dqr.ts as `Time Raised`, u.username as `User Assigned`, dqr.response
FROM `redcap_data` as d
LEFT JOIN `redcap_data_quality_status` as dqs ON d.record = dqs.record AND d.field_name = dqs.field_name
LEFT JOIN `redcap_data_quality_resolutions` as dqr ON dqr.status_id = dqs.status_id
LEFT JOIN `redcap_user_information` as u ON dqs.assigned_user_id = u.ui_id
WHERE
# exclude unneeded fields
d.field_name NOT LIKE "%_complete"
@tertek
tertek / big_data_import_workaround.sql
Created January 18, 2021 15:45
SQL to reset REDCap EM Big Data Import Module when stuck.
delete from redcap_external_module_settings
where `project_id`= 14 and `external_module_id` = 9
and `key` <> "enabled"
@tertek
tertek / REDCap_API_to_Stata_via_Pyhton_Example.do
Created February 8, 2021 11:07
Example of using REDCap API for exporting record data and importing into Stata via Python
python:
#!/usr/bin/env python
import requests
data = {
'token': '<PLEASE INSERT API TOKEN HERE>',
'content': 'record',
'format': 'csv',
'type': 'flat',
'csvDelimiter': '',
'records[0]': '1',
@tertek
tertek / .htaccess
Last active June 7, 2022 06:52
Rewrite Rules needed for pretty URLs for the REDCap Module Repo API
RewriteEngine On
# Rewrite Rules needed for pretty URLS for the Modules API
# Add trailing slash to all requests within /api directory
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# Route URL Query parameters to pretty URls with "endpoints" - DO NOT CHANGE THE ORDER - can break things
RewriteRule ^v1/$ ?NOAUTH&pid=472&type=module&prefix=em_submission_module&page=module-repo-api
@tertek
tertek / docker-commands.sh
Last active June 8, 2022 15:07
Useful Docker Commands
# Clear Build Cache
# https://docs.docker.com/engine/reference/commandline/builder_prune/
$ docker builder prune
# Remove Image
# https://docs.docker.com/engine/reference/commandline/image_rm/
$ docker image rm IMAGE
# Run docker build with output to console
# https://stackoverflow.com/a/69524819/3127170
@tertek
tertek / local-composer-package.md
Created August 16, 2022 06:46
Local Composer Package Development

Example package with structure:

project
│   composer.json
│   ...
│
└───packagename
│   │   composer.json
│   │
│ └───src
@tertek
tertek / redcap-testing.php
Last active August 19, 2022 10:39
REDCap Testing Helpers
<?php
function addRepeatingForm($projectId=null, $eventId=null, $form=null, $customLabel=null) {
// Prepare parameters
if($projectId === null) {
$projectId = PROJECT_ID;
}
if($eventId === null){
@tertek
tertek / remote-odk.py
Last active December 5, 2023 09:24
Test python remote code execution for zapier
def hello():
return "Hello World from Github"
test = hello()
output = [{'test-2': test}]
@tertek
tertek / initial_setup.sh
Created January 22, 2024 07:50
Initial Setup Script for a VPS running Linux Ubuntu
#!/bin/bash
set -euo pipefail
########################
### SCRIPT VARIABLES ###
########################
# Name of the user to create and grant sudo privileges
USERNAME=sammy
@tertek
tertek / pdfToThumbnailImage.js
Created April 20, 2021 09:01
PDF to Thumbnail Image with pdf.js
function makeThumb(page) {
// draw page to fit into 96x96 canvas
var vp = page.getViewport({ scale: 1, });
var canvas = document.createElement("canvas");
var scalesize = 1;
canvas.width = vp.width * scalesize;
canvas.height = vp.height * scalesize;
var scale = Math.min(canvas.width / vp.width, canvas.height / vp.height);
console.log(vp.width, vp.height, scale);
return page.render({ canvasContext: canvas.getContext("2d"), viewport: page.getViewport({ scale: scale }) }).promise.then(function () {