Skip to content

Instantly share code, notes, and snippets.

@shapiromatron
shapiromatron / gist:5024948
Last active January 31, 2025 12:43
Convert an Excel Range to a Bootstrap HTML table
' Example function call: =BuildHTMLTable(A1:D5)
Public Function BuildHTMLTable(rng As Range) As String
' Given a Range of Cells, build a Bootstrap HTML table, using the formatting
' specified in the Excel cells. If "header" is specified to equal true, assumes
' the first row in the table is a header row.
Dim last_r As Long: last_r = rng.Cells(1, 1).Row
Dim tds As New Collection
Dim txt As String
Dim isFirstRow As Boolean: isFirstRow = True
@shapiromatron
shapiromatron / prepare_css.py
Last active December 20, 2015 09:08
Prepares one CSS stylesheet for all styles which may be applied to D3 objects.
#usr/bin/python
import os
import re
this_path = os.path.abspath(__file__)
static_path = os.path.abspath(os.path.join(this_path, r'../../project/static'))
@shapiromatron
shapiromatron / gmail.py
Last active August 29, 2015 14:05
send email using gmail and built-in python smtplib
import smtplib
def send_email(email, pw, subject, text):
FROM = email
TO = [email]
try:
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s\n""" % (FROM, ", ".join(TO), subject, text)
server = smtplib.SMTP("smtp.gmail.com", 587) # alternatively port 465
server.ehlo()
@shapiromatron
shapiromatron / renameFilesByDatestamp.py
Last active August 29, 2015 14:05
Rename files in a path based on the file creation date. Useful for renaming pictures and movies from multiple sources.
from datetime import datetime, timedelta
import os
def renameByDatestamp(path, hourAdjustment):
"""
Rename files in a path using the time-created stamp. Adjust name by adding
an integer if files have non-unique timestamps.
Ideal for renaming pictures and videos from multiple sources.
<!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);
@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.

@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 / 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 / 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 / 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)