Skip to content

Instantly share code, notes, and snippets.

View s4parke's full-sized avatar

Steve J. s4parke

View GitHub Profile
@s4parke
s4parke / message.sh
Created February 14, 2018 17:16
Multicolor text formatting utility for bash scripts
#!/bin/bash
# message.sh
# Multicolored text formatting utility for bash
#
# Usage:
# message --help
#
# message -red "string1" -s -blue "string2" -t "string3" ...
# msg -error "ERROR:" -s -info "File not found"
@s4parke
s4parke / date.sh
Created September 13, 2017 15:07
Date regex (MM/DD/YYYY)
(?:0?[1-9]|1[012])([\/.-])(?:0?[1-9]|[12]\d|3[01])([\/.-])(?:19|20)\d\d
@s4parke
s4parke / heredoc_with_indents.rb
Created August 1, 2017 08:10
Use ruby here documents with indentation
Use here documents with indentation
===================================
Thanks to [@dhamidi](https://github.com/dhamidi)
```ruby
# somewhere in your code
# make sure to use tabs!
def some_method
<<-EOF.gsub(/^\t/, '')
@s4parke
s4parke / mss-assessment-views.sql
Created July 21, 2017 17:06
MySQL views for MSS intervention
-- Generated from prepared statements T1-T4
CREATE VIEW t1_responses AS
SELECT participant_id, max(case prop_key when 't1_ethnicity' then prop_value else null end) AS t1_ethnicity,max(case prop_key when 't1_race_list' then prop_value else null end) AS t1_race_list,max(case prop_key when 't1_race_textbox' then prop_value else null end) AS t1_race_textbox,max(case prop_key when 't1_education' then prop_value else null end) AS t1_education,max(case prop_key when 't1_income' then prop_value else null end) AS t1_income,max(case prop_key when 't1_marital' then prop_value else null end) AS t1_marital,max(case prop_key when 't1_distress' then prop_value else null end) AS t1_distress,max(case prop_key when 't1_eyes' then prop_value else null end) AS t1_eyes,max(case prop_key when 't1_hair' then prop_value else null end) AS t1_hair,max(case prop_key when 't1_skincolor' then prop_value else null end) AS t1_skincolor,max(case prop_key when 't1_skinreaction' then prop_value else null end) AS t1_skinreaction,max(case prop
@s4parke
s4parke / cast_value_as_boolean.rb
Created June 29, 2017 19:17
Typecast a value (string, integer, nil) to boolean using ActiveRecord(5.0)
## /config/initializers/cast_value_as_boolean.rb
##
## Typecast a value to boolean using ActiveRecord(5.0)
##
## 'whatever'.to_b => true
## 0.to_b => false
## Supported types:
# Integer
@s4parke
s4parke / mssc_rollback_time_offsets.rb
Last active February 8, 2017 23:10
Reset "time traveling" mySmartSKin participants and clean up participation data
## Find all time travel test participants
Participant.find( :all, :participant_type => 'Patient', :deleted => false,
:conditions => ['IFNULL(time_delta_days,0) != 0'] )
## Reset time offset and timezone
@participant.time_delta_days = 0
@participant.timezone = 'US/Eastern'
## Delete all of their moles and Diaries
@participant.moles.destroy_all
@s4parke
s4parke / average_time_of_day.rb
Last active February 8, 2017 02:03
Calculates mean time of day using circular vector average
class AverageTimes
# Accepts an array of objects (ActiveRecord collection probably)
# Computes the average time of day for a given :time_attr
# by converting times to degrees, calculating mean angle
#
# @sleep_diaries = Diary.all
# @average_times = AverageTimes( @sleep_diaries )
# @average_bedtime = @average_times.of( :bed_at )
@s4parke
s4parke / story_html5_autoplay.html
Created February 3, 2017 23:39
Storyline HTML5: Autoplay, Remove interstitial play button
<!-- Around line 79 -->
<script src="mobile/player_compiled.js" type="text/javascript"></script>
<script>
// Insert the following 2 lines anywhere to enable autoplay on mobile
player.launch = $('<div></div>');
window.setTimeout( player.revealPostInterstitial, 500 );
// Storyline defaults
// player.autoplay = true;
@s4parke
s4parke / visudo-deb-conf.sh
Created December 6, 2016 17:43
Debian/Ubuntu VISUDO config: allows users in group 'staff' to do basic admin without a password
# /etc/sudoers.d/visudo-deb-conf (root:root, 0440)
#
# Visudo configuration for Debian (and Ubuntu?) systems
# Allows users in group 'staff' to do basic admin without a password
#
# Setup:
# groupadd staff
# usermod -a -G staff shuti
# chown root:root && chmod 0440 visudo-deb-conf
# cp ~/visudo-deb-conf /etc/sudoers.d/
@s4parke
s4parke / generate-ssl.sh
Created March 1, 2016 22:57
Script to generate a self-signed SSL wildcard certificate
#!/usr/bin/env bash
# Specify where we will install
# the ssl certificate
SSL_DIR="secrets"
# Set the wildcarded domain
# we want to use
DOMAIN="*.uvabht.org"