Skip to content

Instantly share code, notes, and snippets.

View mbreese's full-sized avatar

Marcus Breese mbreese

  • Indiana University
  • Cincinnati, OH
View GitHub Profile
@mbreese
mbreese / bcrypt.py
Last active October 10, 2024 14:55
bcrypt
#!/home/mbreese/.local/src/bcrypt-venv/bin/python3
import sys
import bcrypt
def usage():
sys.stderr.write('''\
Encrypting text
Usage: bcrypt {-r} [text]
You can also pipe raw plaintext through stdin (will be stripped unless -r is set!)
@mbreese
mbreese / abspath
Created July 30, 2024 22:51
abspath replacement in python
#!/usr/bin/env python3
import os
import sys
if len(sys.argv) == 1:
print(os.path.abspath('.'))
else:
for arg in sys.argv[1:]:
print(os.path.abspath(arg))
@mbreese
mbreese / CustomSignalHandler.java
Created February 13, 2024 00:25
Capture signals from Java
package io.compgen.ngsutils.support;
import sun.misc.Signal;
import sun.misc.SignalHandler;
abstract public class CustomSignalHandler implements SignalHandler {
private SignalHandler old = null;
private void setOld(SignalHandler old) {
@mbreese
mbreese / gist:159ab2b04fb05de81e3776827b63a73c
Created July 12, 2023 06:10
Bookmarklet to save web site URLs to a [usememos/memos] site. Replace $$OPENID_URL$$ with your OpenID URL/ID
javascript:function sendurl_to_memos(url,data){let xhr=new XMLHttpRequest();xhr.open("POST", url, true);xhr.setRequestHeader("Content-Type", "application/json");xhr.onreadystatechange=function(){if (xhr.readyState === 4) { if (xhr.status === 200) {alert("Saved!");}else{alert(xhr.readyState+"\n"+xhr.status+" error: "+this.responseText);}}};xhr.send(JSON.stringify(data));};sendurl_to_memos('$$OPENID_URL$$', {"content": document.title+"\n"+window.location.href+"\n#link"});
@mbreese
mbreese / fit.sh
Created February 15, 2023 14:52
Quick script to convert stdin to a line size that fits the screen. For example, `ps -e` will return only lines that fit on the current screen. If you want to grep that output, you get all of the data and it wraps the screen. If you pipe `ps -e | grep foo | fit`, then you get the trimmed output again.
#!/bin/bash
COLS="$(tput cols)"
while read LINE; do
echo $LINE | head -c $COLS
done
@mbreese
mbreese / daily_zfs_snapshot.sh
Last active January 7, 2022 22:57
This is a script to take daily snapshots of a ZFS filesystem (and prune older snapshots).
#!/bin/bash
#
# This will by default take snapshots of all zfs filesystems,
# but could be adapted to only pull specific ones. This script
# will also rotate snapshots, removing those that are older
# than 2 weeks.
#
CURDATE=$(date +%Y%m%d)
TWOWEEKSAGO=$(date -d'2 weeks ago' +%Y%m%d)
@mbreese
mbreese / sample_tree.py
Created March 14, 2018 10:30
Sampling program to read write every X lines to stderr, otherwise, just read from stdin and write to stdout (useful for monitoring stream progress)
#!/usr/bin/env python
import sys
import datetime
rate = 100000
if len(sys.argv) > 1:
rate = int(sys.argv[1])
@mbreese
mbreese / vep_vcf_worst_consequence.py
Created February 21, 2018 14:31
Given a VCF file annotated with VEP (and expanded), calculate the worst consequence, gene, SIFT, PolyPhen, etc...
#!/usr/bin/env python
import sys
import itertools
cons_key = "VEP_Consequence"
impact_key = "VEP_IMPACT"
gene_key = "VEP_SYMBOL"
csn_key = "VEP_CSN"
sift_key = "VEP_SIFT"
@mbreese
mbreese / expand_vep_vcf.py
Created February 21, 2018 14:29
Given a VCF file annotated with VEP, expand the VEP "CSQ" INFO field to add INFO fields for all annotations
#!/usr/bin/env python
import sys
prefix="VEP_"
vep_info_name = "CSQ"
def parse_info_format(line):
###INFO=<ID=CSQ,Number=.,Type=String,Description="Consequence annotations from Ensembl VEP. Format: Allele|Consequence|IMPACT|SYMBOL|Gene|Feature_type|...">
@mbreese
mbreese / db.sql
Created January 30, 2018 15:56
Add a new user to Postgres
CREATE ROLE db_user LOGIN ENCRYPTED PASSWORD 'secret-password' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
CREATE DATABASE db_name WITH OWNER db_user;
GRANT ALL PRIVILEGES ON DATABASE db_name TO db_user;