Skip to content

Instantly share code, notes, and snippets.

View hhenrichsen's full-sized avatar

Hunter Henrichsen hhenrichsen

View GitHub Profile
@hhenrichsen
hhenrichsen / 00-README.md
Last active November 27, 2018 20:12
Purges and re-runs django migrations without breaking everything.

django-remigrate

Removes existing migrations from django, clears the sqlite database, and re-runs migrations.

Installation

Place the script on your $PATH. Have django and python installed.

wget: wget https://gist.githubusercontent.com/hhenrichsen/4276164d086450c4870b226246d7cddb/raw/18f1f8ee1e5677aebdafdabe3433696166f2eb6a/django-remigrate

var isPalindrome = (str) =>
str.toLowerCase()
.split("").reduce((a, i) => a += (i.match(/^[A-Za-z0-9]/) ? i : ""), "") //Kill invalid characters.
.split("").reduce((a, i, idx, c) => a && i === c.pop(), true); //Check equivalency; Short circuit if needed.
const outerOffset = 65; //ASCII code of first letter
const innerOffset = outerOffset - 13; //Number that is subtracted to determine new ASCII code
const allowedChars = /[A-Z]/; //Characters to be transformed
var rot13 = (str) => str.toUpperCase() //Function declaration, accept lowercase
.split("") //Basic stream transforms
.map(c => (c.match(allowedChars) ? //Check if its a character to be transformed;
String.fromCharCode(outerOffset + ((c.charCodeAt(0) - innerOffset) % 26)) //Transform it
: c)) //Don't transform it
.join(""); //Join it back into a string.
const re = /^([1])?(?:[ ])?((?:\(\d{3}\))|[^\(\d]??(?:(?=[^\)])\d{3}))(?:[ -])?(\d{3})(?:[- ])?(\d{4})$/;
//Regexr: https://regexr.com/46u08
function telephoneCheck(str)
{
return re.test(str);
}
var findScores = function() {
return Array.from(document.querySelectorAll('span[class^=StudentPointsLabel]'))
.map(i => i.textContent)
.filter(i => i !== "" && i !== "1/1" && i !== "0/1")
.map(i => i.split('/').map(i => parseFloat(i)))
.reduce((a, i) => {a[0] += i[0]; a[1] += i[1]; return a}, [0, 0]);
}
var alertScores = function() {
let scores = findScores();
@hhenrichsen
hhenrichsen / 00_README.md
Last active February 7, 2024 10:04
Turn a CSV file into a matplotlib graph.

CSV to Matplotlib

This is a python module/CLI utility that allows you to plot CSV files using matplotlib. It comes with a command line so that the plot can be configured in many common ways without having to write code to do so.

Parameters

  • --xscale [linear|log] - Sets the x scale. (Has a Y equivalent)
  • --xbase [base] - Sets the x base when using a logarithmic scale. (Has a Y equivalent)
  • --xlabel [label] - Sets the label for the x axis. (Has a Y equivalent)
  • --title [title] - Sets the title of the graph.
  • --approximate - Tells the graph to do an approximation and prints it.
@hhenrichsen
hhenrichsen / ListUtil.cs
Last active May 9, 2020 23:41
Predication in C# collections.
using System.Collections.Generic;
public static class ListUtil
{
/**
* <summary>
* Extension function for a list. Finds any matches in the list, and returns <c>true</c> if it finds any. Short circuits.
* </summary>
* <param name="list">The list for this to be used on.</param>
* <param name="predicate">The predicate for this to use to find any items that fit the critera.</param>
import math
from functools import lru_cache
def pair(x, y):
return math.pow(2, x) * (2 * y + 1) - 1
def unpair(z):
zr = z + 1
x = 0
while zr % 2 == 0:

Hunter's Introduction to the Game of Life

Cells

The game of life is made up of cells. These are either alive or dead. Cells are normally represented within a 2D list, and look like this:

Rules

The cells also have rules that allow us to simulate them. They're normally defined as follows:

@hhenrichsen
hhenrichsen / 00_README.md
Last active March 24, 2023 09:14
Hypercube Topology Bitshift Indexing

Hypercube Topology Bitshift Indexing

Introduction

This is a hypercube, or a 2D representation of a 3D representation of it: A picture of a hypercube.

Say we wanted each point in the cube to be able to reach out to its neighbors. We could do some math specific to each dimension, ensuring that numbers loop back around and such, but that's more complicated than we like, especially when we're sure that there's a pattern -- we're working with vertices in a power of