Skip to content

Instantly share code, notes, and snippets.

Avatar
🛰️

Matthew Barber honno

🛰️
View GitHub Profile
@rhettinger
rhettinger / mymax10e.py
Created Nov 18, 2021
Type annotated pure python implementation of the builtin max() function
View mymax10e.py
'Emulate max() as fully as possible in pure Python.'
# https://stackoverflow.com/questions/69997857/implementation-of-max-function-in-python/69997876#69997876
# https://github.com/python/mypy/issues/7231
from typing import TypeVar, Any, Iterator, Iterable, Optional
from typing import Union, Protocol, Callable, cast, Tuple, overload
class SupportsGT(Protocol):
@tonyfast
tonyfast / 2021-09-20-pandas-one-liner.ipynb
Created Sep 20, 2021
pandas one liner demonstrating apply pandas Series patterns
View 2021-09-20-pandas-one-liner.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View emoji.md.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pouyatafti
pouyatafti / moomin.c
Last active Aug 18, 2020
Linux process Moomin ASCII art (via ps x)
View moomin.c
#include <string.h>
#include <unistd.h>
char *moomin[] = {
" . ,",
"ASCII art (c) Maija Haavisto (@DiamonDie)",
"",
" \"._.' `' mh/VK",
" `. `, `. .'",
" . .' `. `' ;",
@merlinmann
merlinmann / twitter-bios.md
Last active Jan 13, 2023
bios - Merlin likes to change his Twitter bio for some reason. #runx
View twitter-bios.md

good twitter bios runx

Bios

The bar is in the globe.

This is a factory, not a circus.

I weigh less than a slice of bread.

@dannvix
dannvix / mydft.py
Last active Dec 20, 2022
Intuitive impementation of discrete Fourier transform (and inverse DFT) in Python (without numpy)
View mydft.py
#!/usr/bin/env python3
import math
# >> Discrete Fourier transform for sampled signals
# x [in]: sampled signals, a list of magnitudes (real numbers)
# yr [out]: real parts of the sinusoids
# yi [out]: imaginary parts of the sinusoids
def dft(x):
N, yr, yi = len(x), [], []
@StuartGordonReid
StuartGordonReid / LinearComplexity.py
Last active Jul 13, 2022
Python implementation of the linear complexity cryptographic test for randomness. This includes the Berklekamp Massey algorithm.
View LinearComplexity.py
def linear_complexity(self, bin_data, block_size=500):
"""
Note that this description is taken from the NIST documentation [1]
[1] http://csrc.nist.gov/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf
The focus of this test is the length of a linear feedback shift register (LFSR). The purpose of this test is to
determine whether or not the sequence is complex enough to be considered random. Random sequences are
characterized by longer LFSRs. An LFSR that is too short implies non-randomness.
:param bin_data: a binary string
@ma-ric
ma-ric / flatten.py
Created May 21, 2015
Python; recursive flatten of nested iterables, with proper handling of string elements
View flatten.py
#!/usr/bin/env python3
def flatten(t):
"""
Generator flattening the structure
>>> list(flatten([2, [2, "test", (4, 5, [7], [2, [6, 2, 6, [6], 4]], 6)]]))
[2, 2, "test", 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
"""
from collections.abc import Iterable
View cheatsheet.rst
@myusuf3
myusuf3 / delete_git_submodule.md
Created Nov 3, 2014
How effectively delete a git submodule.
View delete_git_submodule.md

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule