Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Typing...

Spencer Bliven sbliven

💻
Typing...
View GitHub Profile
@sbliven
sbliven / 404ForCaseSensitiveURLs.js
Last active Oct 12, 2020 — forked from AmrEldib/404ForCaseSensitiveURLs.js
Jekyll 404 page on GitHub Pages to fix case sensitive URLs
View 404ForCaseSensitiveURLs.js
var allposts = [];
function redirectToCorrectPage() {
console.log("Unable to find page. Trying other URL cases.");
{% for post in site.pages %}
allposts.push("{{ post.url }}");
{% endfor %}
var url = window.location.pathname;
// strip trailing /
if (url.slice(-1) === "/") {
url = url.slice(0, -1);
@sbliven
sbliven / timeout_fn.sh
Last active Sep 21, 2020
'timeout' command, implemented within the shell so that it works with shell functions
View timeout_fn.sh
#!/bin/zsh
# A version of the 'timeout' command that works with shell functions
#
# Usage:
# source timeout_fn.sh
# timeout_fn DURATION COMMAND [ARG]...
timeout_fn () {
local timeout=$1
shift
@sbliven
sbliven / vcd2mp4
Created Aug 3, 2020
Convert a VCD .dat file to .mp4 video
View vcd2mp4
#!/bin/bash
# usage: vcd2mp4 output.mp4 input.dat [input2.dat...]
if [[ $# -lt 2 ]]; then
echo "usage: $0 output.mp4 input.dat [input2.dat...]" >&2
exit 1
fi
output="$1"
shift
@sbliven
sbliven / cif2pdb.py
Created Apr 26, 2017
Convert mmCIF files to PDB format using biopython
View cif2pdb.py
#!/usr/bin/env python
"""
Script to convert mmCIF files to PDB format.
usage: python cif2pdb.py ciffile [pdbfile]
Requires python BioPython (`pip install biopython`). It should work with recent version of python 2 or 3.
@author Spencer Bliven <spencer.bliven@gmail.com>
"""
View animals.cpp
/* Solutions to https://stackoverflow.com/questions/800368/declaring-an-object-before-initializing-it-in-c/62247236#62247236
*
* Uses c++17 for some solutions
*
* Output:
*
* $ g++ --std=c++17 -o animals animals.cpp && ./animals
* Naive Method
* ------------
* Default Constructing Animal at 0x7ffee3fc20d0
@sbliven
sbliven / 99_telegram
Created Nov 7, 2017
Raspberry Pi setup to send IP changes via telegram
View 99_telegram
# /lib/dhcpcd/dhcpcd-hooks/99-telegram
#
# Notify telegram chat of ip changes
# man dhcpcd-run-hooks for variables
TELEGRAM=/home/pi/bin/telegram
if $if_up; then
case "$reason" in
BOUND|BOUND6)
@sbliven
sbliven / circular_types.py
Last active Sep 11, 2019
Test a difficult typing case. Python type annotations!
View circular_types.py
"""Test a difficult typing case.
Inspired by biopython's Bio.PDB.Entity.
https://gist.github.com/sbliven/8fb593f005eeafc0fecef71063f5dc39
"""
import sys
from typing import TypeVar, Union
View linelength.py
"""Create distribution of line lengths over files
Example:
find . -regextype egrep -regex './(Bio|Tests)/.*\.py' -type f -exec \
python linelength.py --hist linelengths.png \
--cdf linelengthscumulative.png -v '{}' '+'
"""
import sys
@sbliven
sbliven / google-authenticator.rb
Last active Mar 8, 2019 — forked from Dan-Q/google-authenticator.rb
Command-line Google Authenticator (TOTP)
View google-authenticator.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
# encoding: utf-8
#
# TOTP implementation (google authenticator)
#
# Reads ~/.google-authenticator-accounts for account info.
# For security, you should run `chmod 600 ~/.google-authenticator-accounts
#
# Changelog:
@sbliven
sbliven / test10.sh
Created Feb 6, 2019
Generate evenly-spaced heic file for testing Mac dynamic wallpapers
View test10.sh
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
JSONFILE="${1:-wallpapper.json}"
HEICFILE="${2:-wallpapper.heic}"
blocks=()
for ((a=-90;a<=90;a+=10)); do
for ((z=0; z<360; z+=10)); do
You can’t perform that action at this time.