Skip to content

Instantly share code, notes, and snippets.

View reedacartwright's full-sized avatar
💭
I may be slow to respond.

Reed A. Cartwright reedacartwright

💭
I may be slow to respond.
View GitHub Profile
@reedacartwright
reedacartwright / sync-ports
Last active April 15, 2021 04:07
A script to syncronize a local ports directory with the latest revision used to build FreeBSD packages.
#!/bin/sh
# Copyright (c) 2014-2015 Reed A. Cartwright <cartwright@asu.edu>
# Copyright (c) 2014-2015 Alberto Villa <avilla@FreeBSD.org>
# Copyright (c) 2015 Mike Clarke <jmc-freebsd2@milibyte.co.uk>
#
# This script determines the revision number used to build FreeBSD packages
# and syncs a local ports directory to match it.
#
# USAGE: sync-ports [name or abs_path]
#
@reedacartwright
reedacartwright / shell_prompts.txt
Last active August 29, 2015 14:17
Shell Commands for Colorizing Shell Prompt and including error information
# Taken from https://github.com/reedacartwright/shell-config
#
# The following commands will produce a prompt that includes the error code of the
# last command run if it is not zero. E.g.
# [user@host dir $?=123]$
# If the user is not root, the prompt is green, except the error information which is red.
# If the user is root, the prompt is read, except the error information which is green.
# If the last commend exited with a 0, then the prompt looks normal. E.g.
# [user@host dir]$
#
@reedacartwright
reedacartwright / portable_endian.h
Created April 30, 2016 01:24 — forked from panzi/portable_endian.h
This provides the endian conversion functions form endian.h on Windows, Linux, *BSD, and Mac OS X. You still need to use -std=gnu99 instead of -std=c99 for gcc. The functions might actually be macros. Functions: htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh. License: I hereby put "port…
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
@reedacartwright
reedacartwright / pack.cc
Created June 10, 2016 23:27
Pack 4 ASCII Nucleotides into 1 byte
#include <cstring>
#include <cstdint>
#include <cstdio>
uint8_t pack_a(const char *cs) {
uint32_t u;
memcpy(&u,cs,4);
u &= 0x06060606;
u = (u | (u << 6) | (u << 12) | (u << 18)) >> 19;
return u;
@reedacartwright
reedacartwright / xorshift64.h
Last active October 18, 2022 01:36
A 64-bit Xorshift PRNG combined a Weyl Generator. Passes all BigCrush tests.
/*******************************************************************************
Copyright (C) 2009-2017 Reed A. Cartwright, PhD <reed@cartwrig.ht>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@reedacartwright
reedacartwright / coveragehmm.R
Last active December 13, 2017 22:15
HMM to estimate coverage
#!/usr/bin/Rscript
# Authors: David Winter
# Joanna Malukiewicz
# Reed A. Cartwright
library(HiddenMarkov)
library(data.table) #makes reading a data table faster than using R data frame functions
library(jsonlite)
cat("Started at ", as.character(Sys.time()), "\n")
@reedacartwright
reedacartwright / mutaton_entropy.R
Created December 14, 2017 23:37
Script to calculate the entropy of a mutation specturm from a vcf
# This script calculates the average entropy and effective number of
# possible mutants for the human mutation spectrum.
# Preparing to run this script
# > wget ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606_b150_GRCh38p7/VCF/common_all_20170710.vcf.gz
# > wget ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606_b150_GRCh38p7/VCF/common_all_20170710.vcf.gz.tbi
# > bcftools query -f '%REF\t%ALT\n' common_all_20170710.vcf.gz | zstd > altref.txt.zst
library(data.table)
library(stringr)
@reedacartwright
reedacartwright / dynamic_machine.cc
Last active February 28, 2018 00:09
Example of using virtual functions to dynamically construct a functor machine
// Compile with -std=c++14
#include <array>
#include <memory>
#include <iostream>
#include <algorithm>
struct A {
virtual void operator()() = 0;
std::array<int,10> data;
@reedacartwright
reedacartwright / aatodna.R
Created March 31, 2019 01:52
Align DNA sequences using an amino acid alignment
#!/usr/bin/Rscript --vanilla
suppressPackageStartupMessages(library(stringr))
suppressPackageStartupMessages(library(Biostrings))
G = BString("-")
main = function(infile, dnafile, outfile) {
ARGS = commandArgs(trailingOnly=TRUE)
if(missing(infile)) {
@reedacartwright
reedacartwright / find_spawners.R
Created March 14, 2020 00:26
A script for identifying all spawners in a Minecraft World
# uncomment and reinstall rbedrock to get the latest code.
# devtools::install_github("reedacartwright/rbedrock", INSTALL_opts="--no-multiarch")
library(tidyverse)
library(rbedrock)
# Local copy of the Advanced Automation Realm
# replace with your own world id
dbpath <- "XBdsXqo+AAA="