Skip to content

Instantly share code, notes, and snippets.

@ievans3024
ievans3024 / toSarcasm.js
Last active September 12, 2023 19:55
Hack to add .toSarcasm() method to javascript strings
/*
* A common way of denoting sarcasm in text on the internet is to alternate upper and lower casing in the text.
* For example: "But I didn't do it!" might become "BuT i DiDn'T dO iT!"
*
* This adds a method to strings in JavaScript to convert them to this sarcastic format.
*
* The method returns a new string with the casing of each letter appropriately changed.
* The method supports letters with diacritic marks, e.g., umlauts.
*
* By default, it will start the converted string in lowercase form
@ievans3024
ievans3024 / geodistance.ts
Created September 12, 2023 18:57
Typescript code for calculating distance between two gps coordinates.
/**
* Enumeration of Earth's radius for a given distance unit
* The value can be used as the radius value in a great circle calculation
* @readonly
* @enum {number}
*/
const enum EarthRadius {
FEET = 2.0925e+7,
KILOMETERS = 6378.0,
METERS = 6378000.0,
@ievans3024
ievans3024 / find.py
Last active April 20, 2020 16:32
Python module for providing unix/linux "find" command behavior.
#! /usr/bin/env python3
"""
Module for providing behavior like the unix/linux "find" command.
Supports glob expressions and python regex objects.
"""
import fnmatch
import os
import os.path

Keybase proof

I hereby claim:

  • I am ievans3024 on github.
  • I am ievans3024 (https://keybase.io/ievans3024) on keybase.
  • I have a public key whose fingerprint is C621 22C2 0584 49DE EC05 3FB8 8BE5 0E82 7D89 23C3

To claim this, I am signing this object:

@ievans3024
ievans3024 / configparser_extended.py
Last active September 12, 2023 19:34
Extension of the configparser library for some much needed but ignored features
from configparser import *
# copypasta from configparser source
# see https://github.com/python/cpython/blob/3.8/Lib/configparser.py#L357
_UNSET = object()
class ConfigParser(ConfigParser):
def __init__(self, *args, sectionless=False, strip_quotes=False, **kwargs):
self.__sectionless = sectionless
@ievans3024
ievans3024 / binary_clock.py
Last active October 29, 2019 13:45
A simple command-line binary clock
import curses
from argparse import ArgumentParser
from datetime import datetime
from time import sleep
ON = '\N{BLACK CIRCLE}'
OFF = '\N{WHITE CIRCLE}'
@ievans3024
ievans3024 / logging_verbosity
Created August 8, 2018 03:59
A function inspired by my verbosity.py gist for auto-configuring verbosity given an int and a logger.
import logging
LOG_LEVELS = [
logging.CRITICAL,
logging.ERROR,
logging.WARNING,
logging.INFO,
logging.DEBUG
]
@ievans3024
ievans3024 / alpha_getter.py
Created August 1, 2018 13:53
An overengineered way to get what 1-based index a letter is in the roman alphabet
import struct
"""
An overengineered way to get what 1-based index a letter is in the roman alphabet
"""
class AlphaBytes:
UPPERCASE = set([struct.pack('>b', i) for i in range(65, 91)])
LOWERCASE = set([struct.pack('>b', i) for i in range(97, 123)])
@ievans3024
ievans3024 / indentation.py
Created July 21, 2018 15:44
Proving Jeremy wrong, indentation experimentation
"""Proving Jeremy wrong, indentation experimentation"""
def four():
# indented with 4 spaces
return 4
def three():
# indented with 3 spaces
return 3
@ievans3024
ievans3024 / verbosity.py
Created May 8, 2018 13:29
Logging verbosity control with a single argument
"""
A demonstration of how to control stdout verbosity with argparse and logging.
Examples of running this file and its expected output:
$ python verbosity.py
CRITICAL :: A critical message.
$ python verbosity.py -v
CRITICAL :: A critical message.