Skip to content

Instantly share code, notes, and snippets.

View antiface's full-sized avatar

A.G. antiface

View GitHub Profile
@sixtenbe
sixtenbe / analytic_wfm.py
Last active May 1, 2024 02:29 — forked from endolith/peakdet.m
Peak detection in Python
#!/usr/bin/python2
# Copyright (C) 2016 Sixten Bergman
# License WTFPL
#
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law.
# You can redistribute it and/or modify it under the terms of the Do What The
# Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See
import hashlib as hasher
import datetime as date
# Define what a Snakecoin block is
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
@endolith
endolith / peakdet.m
Last active February 14, 2024 21:27
Peak detection in Python [Eli Billauer]
function [maxtab, mintab]=peakdet(v, delta, x)
%PEAKDET Detect peaks in a vector
% [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local
% maxima and minima ("peaks") in the vector V.
% MAXTAB and MINTAB consists of two columns. Column 1
% contains indices in V, and column 2 the found values.
%
% With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices
% in MAXTAB and MINTAB are replaced with the corresponding
% X-values.
@kylebgorman
kylebgorman / wagnerfischer.py
Created July 14, 2011 04:41
Python implementation of the Wagner & Fischer dynamic programming approach to computing Levenshtein distance, with support for thresholding, arbitrary weights, and traceback to get individual insertion/deletion/substitution counts.
#!/usr/bin/env python
# wagnerfischer.py: Dynamic programming Levensthein distance function
# Kyle Gorman <gormanky@ohsu.edu>
#
# Based on:
#
# Robert A. Wagner and Michael J. Fischer (1974). The string-to-string
# correction problem. Journal of the ACM 21(1):168-173.
#
# The thresholding function was inspired by BSD-licensed code from
@prophetgoddess
prophetgoddess / pixelsort.py
Last active November 24, 2023 11:39
Python pixel sorting.
# The MIT License (MIT)
# Copyright (c) 2014 Lycaon (lycaon.me)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@endolith
endolith / Accent.py
Last active November 19, 2023 00:09
Documenting the matplotlib colormaps
# https://github.com/matplotlib/matplotlib/issues/881
# Several of the ColorBrewer maps are "qualitative", meaning
# they are just a group of colors that can be used together
# for categories of data. So I remapped Accent to segments
# instead of continuous:
# Actually, these should be used with ListedColormap, and
# the number of colors should depend on the number of
# categories in the data, with colors removed from the
# list in a certain order?
@mnot
mnot / RSS.py
Created October 29, 2009 12:48
RSS.py: work with RSS channels as data structures
#!/usr/bin/env python
"""
RSS.py
Classes for working with RSS channels as arbitrary data structures.
Requires Python 2.2 or newer and PyXML 0.7.1 or newer.
ChannelBase - Base class for RSS Channels.
CollectionChannel - RSS Channel modeled as a URI-per-entry
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@fcicq
fcicq / gf2.py
Last active June 15, 2023 16:37
Finite Field / Galois Field (GF(2^n)) in python 2.7+
# GPLv2+, by fcicq
# from http://www.hpl.hp.com/techreports/98/HPL-98-135.pdf
IRRED_COEFF = [
4,3,1,5,3,1,4,3,1,7,3,2,5,4,3,5,3,2,7,4,2,4,3,1,10,9,3,9,4,2,7,6,2,10,9,
6,4,3,1,5,4,3,4,3,1,7,2,1,5,3,2,7,4,2,6,3,2,5,3,2,15,3,2,11,3,2,9,8,7,7,
2,1,5,3,2,9,3,1,7,3,1,9,8,3,9,4,2,8,5,3,15,14,10,10,5,2,9,6,2,9,3,2,9,5,
2,11,10,1,7,3,2,11,2,1,9,7,4,4,3,1,8,3,1,7,4,1,7,2,1,13,11,6,5,3,2,7,3,2,
8,7,5,12,3,2,13,10,6,5,3,2,5,3,2,9,5,2,9,7,2,13,4,3,4,3,1,11,6,4,18,9,6,
19,18,13,11,3,2,15,9,6,4,3,1,16,5,2,15,14,6,8,5,2,15,11,2,11,6,2,7,5,3,8,
3,1,19,16,9,11,9,6,15,7,6,13,4,3,14,13,3,13,6,3,9,5,2,19,13,6,19,10,3,11,
@kylebgorman
kylebgorman / wagnerfischerpp.py
Last active March 3, 2023 17:27
Wagner-Fischer Levenshtein distance, now with a means to generate all possible optimal alignments.
# Copyright (c) 2013-2022 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#