Skip to content

Instantly share code, notes, and snippets.

View henryefranks's full-sized avatar

Henry Franks henryefranks

  • Cadence Design Systems
  • United Kingdom
View GitHub Profile
@henryefranks
henryefranks / triangle.c
Created September 9, 2018 22:58
Sierpinski triangle generator in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
int layers = 16; // Default value
if (argc > 1) { // Optional layers input
layers = atoi(argv[1]);
if (layers < 1) {
@henryefranks
henryefranks / chi-caesar.py
Created September 9, 2018 22:56
Caesar cipher decoder using chi-squared values
###################################################
## DECODE CAESAR CIPHER USING CHI-SQUARED VALUES ##
## COPYRIGHT (C) 2018 HENRY FRANKS ##
###################################################
phrase = "AOLJHLZHYJPWOLYPZVULZMAOLLHYSPLZARUVDUHUKZPTWSLZAJPWOLYZPAPZHAFWLVMZBIZAPABAPVUJPWOLYPUDOPJOLHJOSLAALYPUAOLWSHPUALEAPZZOPMALKHJLYAHPUUBTILYVMWSHJLZKVDUAOLHSWOHILA" # Phrase to decode
expected = [13.2345, 2.4138, 4.5036, 6.885, 19.602, 3.6126, 3.2724, 9.8658, 11.2914, 0.243, 1.2474, 6.5286, 3.9042, 10.935, 12.1662, 3.1226, 0.162, 9.7038, 10.2546, 14.6772, 4.4712, 1.5876, 3.8232, 0.243, 3.1914, 0.1134] # Expected frequencies for 162 letters
observed = [18, 3, 0, 3, 1, 1, 0, 12, 3, 8, 3, 22, 4, 0, 12, 17, 0, 1, 6, 2, 11, 7, 8, 0, 8, 12] # Observed letter frequencies
@henryefranks
henryefranks / box.sh
Created September 9, 2018 10:06
A Bash script for drawing CLI boxes
box_width=$(tput cols)
function create_line() {
input_width=$(($(echo "$*" | wc -c) - 1))
if [ $# -lt 1 ]; then
input_width=0
fi
half_width=$(($(($box_width - $input_width)) / 2))
for i in `seq 1 $half_width`; do
echo -n '-'
@henryefranks
henryefranks / select_menu.py
Last active January 19, 2024 03:13
Interactive CLI select menu in Python
from __future__ import print_function # Not needed in Python 3
import sys, tty, termios
class Menu:
"""Interactive select menu.
Attributes:
opts (list of str): Options for the user to choose from.
"""
opts = []
@henryefranks
henryefranks / select_menu.sh
Last active August 31, 2017 18:05
A Bash script for an interactive CLI select menu without curses
#!/usr/local/bin/bash
stty -echo
tput civis
function cleanup() {
stty echo
tput cnorm
}