Skip to content

Instantly share code, notes, and snippets.

@shapiromatron
shapiromatron / Dockerfile
Last active July 22, 2021 16:50
adding HTTP Basic Authentication to an nginx container
FROM nginx:1.20-alpine
RUN apk --update --no-cache add apache2-utils
COPY nginx.conf /etc/nginx/nginx.conf
COPY index.html /public/data/index.html
COPY htpasswd /etc/nginx/conf/htpasswd
@shapiromatron
shapiromatron / IE11.html
Last active October 5, 2020 16:13
IE11 warning
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap-responsive.min.css" />
</head>
<body>
<div id="container">
@shapiromatron
shapiromatron / README.md
Last active August 20, 2020 04:10
centos7 + httpd + python3.6 + flask

Running a python3 app on centos7 w/ apache

Similar to how things are done in nginx-land, we'll run a separate process for serving a flask application (or any other wsgi python app), and then we'll configure apache to serve it by a reverse proxy.

Let's get started:

# install the things
sudo yum install httpd python3 vim
@shapiromatron
shapiromatron / README.md
Created February 19, 2020 16:49
simple-logging

Simple python logging

This gist demonstrates how to setup logging and write to both standard-error and a file.

Output is printed to stderr as well as a file. For example:

$ python logger.py 
2020-02-19 11:46:59,473: WARNING: __main__: Starting to do stuff...
2020-02-19 11:47:01,480: INFO: __main__: Stuff done!
@shapiromatron
shapiromatron / queue_example.py
Last active June 21, 2019 14:20
boto aws queue example
from datetime import datetime
import logging
import sys
import time
import click
import boto3
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
@shapiromatron
shapiromatron / curl-client.sh
Last active March 16, 2018 20:46
Example NTP sandbox clients
# an example job submission
curl \
-X POST \
-H "Authorization: Token abcdefghijklmnopqrstuvwxyz1234567890" \
-H "Content-Type: application/json" \
-d '{"jobtype": "success", "name": "Isaac Newton"}' \
https://sandbox.ntp.niehs.nih.gov/job-runner/api/v1/test/
# an example request to check results of job
curl \
@shapiromatron
shapiromatron / index.md
Last active February 5, 2018 17:45
pyRserve

Testing that state isn't shared between two Rserve connections using pyRserve:

>>> import pyRserve
>>> conn1 = pyRserve.connect(host='localhost', port=6311)
>>> conn2 = pyRserve.connect(host='localhost', port=6311)
>>> conn1.eval('x<-function(n){n**2}')
>>> conn1.r.x(2)
4.0
&gt;&gt;&gt; conn2.r.x(2)
@shapiromatron
shapiromatron / README.md
Created January 20, 2018 04:41
pre-commit python linting

Globally add pre-commit hooks on all user's computers. Use prettier to automatically clean JS/CSS code, and throw errors for python code which doesn't meet flake8 rules.

One problem is flake8 needs to be available in the pre-commit path, which without adding globally I struggled with...

@shapiromatron
shapiromatron / readme.md
Last active July 22, 2020 15:50
Celery parallel tasks

Celery task canvas

Demonstration of a task which runs a startup task, then parallelizes multiple worker tasks, and then fires-off a reducer task.

If passing results around would be important, then could use a chord instead for task2 and task3.

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
output {
position: absolute;
background-image: linear-gradient(#444444, #999999);