Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Ralston MatthewRalston

View GitHub Profile
@MatthewRalston
MatthewRalston / root_logger.py
Created Nov 19, 2020
Root_logger boto update
View root_logger.py
def get_root_logger(level):
levels=[logging.WARNING, logging.INFO, logging.DEBUG]
if level < 0 or level > 2:
raise TypeError("{0}.get_root_logger expects a verbosity between 0-2".format(__file__))
logging.basicConfig(level=levels[level], format="%(levelname)s: $(asctime)s %(funcName)s L%(lineno)s| %(message)s", datefmt="%Y/%m/%d %I:%M:%S")
root_logger = logging.getLogger(__name__)
for name in logging.Logger.manager.loggerDict.keys():
if ('boto' in name) or ('urllib3' in name) or ('s3' in name):
logging.getLogger(name).setLevel(logging.ERROR)
return root_logger
View trump-bot-twiml.xml
<Response>
<Say voice="alice">Hi, I'd like to say on behalf of democracy that your behavior is unpatriotic, undemocratic, and your allegations have all been debunked. Check the debunking megathread on Twitter by Isaac Saul. Your actions are shameful and undermine democracy. Furthermore, you're wasting Republican money by keeping this line open. So I will continue to waste your time. Someone has to listen to this stuff anyways. Trump failed. Trump is supported by racists and xenophobes. Trump has hurt American health. Trump has hurt the economy through trade wars. Trump is friends with dictators. Trump was installed through election interference. Trump is a sexual predator. And you are supporting him. Trump failed. Trump is supported by racists and xenophobes. Trump has hurt American health. Trump has hurt the economy through trade
@MatthewRalston
MatthewRalston / reader.py
Created Jun 22, 2019
Fasta + Bam file validation with S3 support
View reader.py
import os
import sys
import gzip
import io
import tempfile
from Bio import SeqIO, bgzf
import pysam
import boto3
# Logger
@MatthewRalston
MatthewRalston / setup.py
Last active Jun 22, 2019
Example setup.py
View setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import io
import os
import sys
from shutil import rmtree
from setuptools import find_packages, setup, Command
View loadLogger.js
const log4js = require('log4js');
// Accessory configurations for log4js
// Works with log4js >= 2.3.3
// Usage:
//var logger = require('./app/loadLogger').logger; // Default is stderr only
// Alternate (app : file + stderr)
// const loadLog = require('./app/loadLogger');
// var logger = loadLog.log4js.getLogger('app'); // For an express app: stderr + file : logs/application.log)
View webdocs.el
;; Add this to your favorite html/jekyll configuration elisp file
;; Replace $IMG with the relative path to your websites image folder (e.g. img/)
(defun add-popover (link imagepath caption linktext)
"Generate an html popover.
-- Downloads an image file to your website/blog (etc.) image folder.
-- Generate a Bootstrap HTML popover link at the cursor position with caption.
"
(interactive "MImage link:\nFImagepath:\nMCaption:\nMLink text:\n")
(url-copy-file link imagepath)
@MatthewRalston
MatthewRalston / difflib.patch.py
Last active Nov 4, 2018
difflib.SequenceMatcher.get_matching_blocks() doesn't return all results
View difflib.patch.py
# get_matching_blocks returns non-overlapping matches: https://bugs.python.org/issue35079
# the incomplete result is considered a feature
def get_matching_blocks(s1, s2, overlap=True):
if type(s1) is not str:
throw TypeError("get_matching_blocks() expects a string as its first positional argument")
if type(s2) is not str:
throw TypeError("get_matching_blocks() expects a string as its second positional argument")
if type(overlap) is not bool:
throw TypeError("get_matching_blocks() expects a bool as the named argument 'overlap'")
@MatthewRalston
MatthewRalston / Makefile
Created Apr 18, 2018
Python project Makefiles
View Makefile
.PHONY: test docs
install:
pip install -r reuqirements.txt;
docs: docs/Makefile
cd docs; $(MAKE) docs
test: test/Makefile
cd test; $(MAKE) test
View s3sync.py
from awscli.clidriver import create_clidriver
def s3sync(source, destination, *options):
old_env = dict(os.environ)
try:
env = os.environ.copy()
env["LC_CTYPE"] = u"en_US.UTF"
os.environ.update(env)
exit_code = create_clidriver().main(["s3", "sync", source, destination] + list(options))
@MatthewRalston
MatthewRalston / roflcopter.md
Created Feb 14, 2018
ROFLcopter ASCII text art
View roflcopter.md

ROFLcopter ASCII

If you hear SOI SOI SOI, you better RUN RUN RUN ’cause the ROFLCOPTER ASCII army is coming for you!

THE ORIGINAL ROFLCOPTER

 ROFL:ROFL:ROFL:ROFL
         _^___
 L    __/   [] \
You can’t perform that action at this time.