Skip to content

Instantly share code, notes, and snippets.

Avatar

Andy Reagan andyreagan

View GitHub Profile
View sort_encrypt.py
import random
random.seed(42)
key = list(range(1000))
random.shuffle(key)
def decrypt(x, key):
short_key = [y for y in key if y < len(x)]
return ''.join([x[y] for y in [z for z in sorted(range(len(x)),key=short_key.__getitem__)]])
@andyreagan
andyreagan / index.html
Created Mar 23, 2021
Scrollytelling complete
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=900, initial-scale=1.0">
<title>Document</title>
<style>
body {
font-family: sans-serif;
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=900, initial-scale=1.0">
<title>Document</title>
<style>
body {
font-family: sans-serif;
View 00_how_to_use_R_like_python.md

Here's how to use an R script like a Python script, relying on box. While there are reasons to use R, there are also two very bad parts of the R language, avoid them: (1) never use source and (2) never use library. These encourage patterns of code that are difficult to test or maintain. Using source comes along with changing the working directory sometimes, which should also be avoided. I'll quote Jenny Bryan, who, among other things says

Have setwd() in your scripts? PLEASE STOP DOING THAT. ... I will come into your lab and SET YOUR COMPUTER ON FIRE.

She has also written a whole post on why setwd() is, and I quote again, "so problematic and often associated with other awkward workflow problems".

There are three files here:

  • src/main/myscript.R: the main script, has functions that can be used elsewhere and also can be run standalone.
  • `src/main/04_uncon
View mydata.csv
day game KD Accuracy match Kills
1 1 0.56 07.60 TDM 9
1 2 0.48 04.40 TDM 12
1 3 0.50 09.80 TDM 13
1 4 0.90 09.40 TDM 27
1 5 0.36 03.50 TDM 4
1 6 0.71 04.70 TDM 10
1 7 1.38 00.00 TDM 18
1 8 1.00 20.00 TDM 2
2 1 0.78 15.30 TDM 7
@andyreagan
andyreagan / gps_track.gpx
Last active Sep 25, 2020
Virtual boston marathon data
View gps_track.gpx
<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="StravaGPX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
<metadata>
<time>2020-09-13T10:04:30Z</time>
</metadata>
<trk>
<name>Virtual Boston Marathon!</name>
<type>9</type>
<trkseg>
<trkpt lat="42.4211140" lon="-72.4243420">
@andyreagan
andyreagan / .flake8
Created Jul 14, 2020
Standard pre commit and isort, flake8 settings
View .flake8
[flake8]
max-line-length = 88
max-complexity = 12
select = C,E,F,W,B,B950
ignore = E203, E501, W503
@andyreagan
andyreagan / tastypie-smarturl.py
Last active Jun 23, 2020
Smart url encoder for tastypie
View tastypie-smarturl.py
from django.utils.html import smart_urlquote
from tastypie import fields
class SmartUrlField(fields.ApiField):
"""
A field for urls in plain text.
"""
dehydrated_type = 'string'
help_text = 'a field for urls in plain text.'
@andyreagan
andyreagan / jenkins-block.sh
Created May 22, 2020
Shell script to wait on a upstream jenkins job - a "block" node in an execution graph
View jenkins-block.sh
# watch multiple jobs, can handle any number of upstreams
virtualenv-3.5 pyenv
pyenv/bin/pip install requests
JENKINS_URI=...
echo "import json
import requests
import time