This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dynamic(dict): | |
"""Dynamic objects are just bags of properties, some of which may happen to be functions""" | |
def __init__(self, **kwargs): | |
self.__dict__ = self | |
self.update(kwargs) | |
def __setattr__(self, name, value): | |
import types | |
if isinstance(value, types.FunctionType): | |
self[name] = types.MethodType(value, self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## follow redirects, including rePOSTing, with the requests library. | |
###################################################################### | |
import requests | |
## authentication with no redirects | |
ans = requests.post(url=endp_prod + "/session", data=json.dumps(d), headers=h) | |
## results in a successful login | |
ans.status_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Poker.R | |
## Evaluate poker hands | |
## | |
## by: Christopher Bare | |
############################################################ | |
## define suits and ranks | |
suits <- c('c','d','h','s') | |
ranks <- c(2:10,"J","K","Q","A") | |
suit_names <- c(c="clubs", d="diamonds", h="hearts", s="spades") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime as dt | |
import pytest | |
import re | |
def parse_dicom_dt(dicom_dt): | |
""" | |
Parse a Dicom formatted datetime string and return a Python datetime. | |
The Dicom format is "YYYYMMDDHHMMSS.FFFFFF&ZZXX" described here: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple HTTPS server | |
Generate cert and key with: | |
```sh | |
openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes -subj '/CN=localhost' -out ./ssl/cert.pem -keyout ./ssl/key.pem | |
``` | |
Test with httpie: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Convert JSON output from V7 Darwin to csv. | |
""" | |
import json | |
import os.path | |
import pandas as pd | |
filenames = [f"{name}.json" for name in list('abcde')] | |
data_dir = "data/lizzie-reader-study-test-part-1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## S4 classes for talented people | |
## | |
## Code to go along with a blog post about | |
## object oriented programming in R: | |
## | |
## http://digitheadslabnotebook.blogspot.com/2012/09/oo-in-r.html | |
## | |
################################################################ | |
# define an S4 class for people |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import synapseclient | |
from synapseclient import Synapse, File, Folder, Project | |
import os | |
def upload_recursive(directory, parent): | |
for item in os.listdir(directory): | |
if os.path.isdir(os.path.join(directory,item)): | |
print "%s/" % os.path.basename(item) | |
folder = syn.store(Folder(os.path.basename(item), parent=parent)) | |
upload_recursive(directory=os.path.join(directory, item), parent=folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Compute the intersection of all combinations of the | |
## elements in the list of vectors l. Might be useful | |
## for generating Venn/Euler diagrams. | |
## There might be better ways to do this! | |
overlap <- function(l) { | |
results <- list() | |
# combinations of m elements of list l | |
for (m in seq(along=l)) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# crontab -e | |
# */20 * * * * /home/ubuntu/checkpoint.py > /home/ubuntu/checkpoint.log 2>&1 | |
import os | |
hosts = [] | |
with open('/usr/local/Rmpi/hostfile.plain') as f: | |
for line in f: |
NewerOlder