Skip to content

Instantly share code, notes, and snippets.

View t-eckert's full-sized avatar
💭
Head in the cloud

Thomas Eckert t-eckert

💭
Head in the cloud
View GitHub Profile
@t-eckert
t-eckert / rpn.py
Created June 18, 2018 04:02
Reverse Polish Calculator for the command line. Written in Python.
end_scripts = {"quit", "end", "q"}
help_scripts = {"help", "h"}
help_doc = """
A reverse polish or postfix calculator evaluates two numbers by the next opertion.
For example, the sum of 4 and 5 can be found by entering: 5 4 +
Available operations include
+ addition
@t-eckert
t-eckert / load.py
Created May 11, 2019 05:38
This script will copy `code.py` to the CIRCUITPY volume on Mac
# This will only work on MacOS
CIRCUITPY_PWD = "/Volumes/CIRCUITPY"
ORIGIN = "code.py"
TARGET = CIRCUITPY_PWD + "/code.py"
with open(ORIGIN, "r") as origin_file:
origin_code = origin_file.read()
with open(TARGET, "w") as target_file:
@t-eckert
t-eckert / .bash_profile
Created May 13, 2019 02:11
Bash profile for multiple Python versions (py3x -> Python 3.x) [MacOS only]
# == Add Python Aliases and Paths ==========================================================
# Python 3.6
alias py36="/Library/Frameworks/Python.framework/Versions/3.6/bin/Python3.6"
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
# Python 3.7
alias py37="/Library/Frameworks/Python.framework/Versions/3.7/bin/Python3.7"
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
# Python 3.8
@t-eckert
t-eckert / flat-ui-v1.json
Last active November 17, 2022 04:09
Flat UI Color Scheme V1 implemented as Windows Terminal color scheme. https://flatuicolors.com/palette/defo
{
"background":"#000000",
"black":"#000000",
"blue":"#2980b9",
"brightBlack":"#7f8c8d",
"brightBlue":"#3498db",
"brightCyan":"#1abc9c",
"brightGreen":"#2ecc71",
"brightPurple":"#9b59b6",
"brightRed":"#e74c3c",
fn main() {
let mut array = [0, 2, 0, 3, 8];
println!("{:?}", array); // [0, 2, 0, 3, 8]
move_zeroes(&mut array);
println!("{:?}", array); // [2, 3, 8, 0, 0]
}
/// `move_zeroes` function
///
/// Shifts all elements with a value of zero in the `array` to the end of the `array`.
@t-eckert
t-eckert / rotate_brackets.rs
Created April 27, 2021 22:30
Solution to the Rotate Brackets problem in Rust
/// # Rotate Brackets
///
/// Given a string of brackets, return a rotation of those brackets that is balanced.
/// The numbers of opening and closing brackets will always be equal.
///
/// Example
/// ```
/// rotate_brackets("]][][[");
/// "[[]][]" // First rotation yields "[]][][". Second one yields "[[]][]"
/// ```
@t-eckert
t-eckert / rounder.py
Created May 11, 2021 17:16
Solution to Rounder problem
"""
Given a positive or negative real number, round it to the next whole integer
closer to zero. This means if it’s positive, round down, and if it’s negative,
round up. Try to do this in as few characters possible!
"""
def round(number: float) -> int:
return int(str(number).split(".")[0])
@t-eckert
t-eckert / same_digits.py
Created May 11, 2021 17:24
Same digits
"""
Given an integer n, return true if n^3 and n have the same set of digits.
"""
def same_digits(n: int) -> bool:
return set(str(n)) == set(str(n**3))
def print_and_assert(expected, actual):
print("expected = " + str(expected))
print("actual = " + str(actual) + "\n")
@t-eckert
t-eckert / inits.py
Last active June 1, 2021 19:08
Haskell's `inits` in Python
from typing import Iterable
def inits(items: Iterable) -> list[Iterable]:
"""Given an iterable, returns all of its prefixes in ascending order of length
Arguments:
items: Iterable items whose prefixes will be returned
Returns:
list[Iterable] prefixes of the iterable
@t-eckert
t-eckert / redistribute_chars.go
Last active June 30, 2021 23:31
Go Solution to LeetCode 1897
package main
import (
"fmt"
"strings"
)
/* Redistribute Characters to Make All Strings Equal
LeetCode 1897: https://leetcode.com/contest/weekly-contest-245/problems/redistribute-characters-to-make-all-strings-equal/