Skip to content

Instantly share code, notes, and snippets.

mgd020 mgd020

Block or report user

Report or block mgd020

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mgd020
mgd020 / jira2es.py
Created Oct 30, 2019
parse JIRA api and put it into ES for analysis
View jira2es.py
"""
requirements:
jira<3
elasticsearch<7
elasticsearch-dsl<7
raven<7
python-dateutil<3
jsonpointer<3
"""
View postcode_state.py
import re
import sys
from collections import Mapping, Container
from itertools import chain
from array import array
def deep_getsizeof(o):
seen = set()
todo = {id(o): o}
View progress.py
import sys, re
class TerminalController:
"""
A class that can be used to portably generate formatted output to
a terminal.
`TerminalController` defines a set of instance variables whose
values are initialized to the control sequence necessary to
perform a given action. These can be simply included in normal
View print-replace.js
function forceOpen() {
var url = "http://www.google.com";
window.open(url) ? location.reload() : (location.href = url);
}
window.addEventListener("beforeprint", function (e) { e.preventDefault(), forceOpen() })
window.matchMedia('print').addListener(function (e) { e.matches && forceOpen() })
View fnv1a.py
fnv1a_128_prime = 309485009821345068724781371
fnv1a_128_offset = 144066263297769815596495629667062367629
fnv1a_128_mask = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
def fnv1a_128(bs):
h = fnv1a_offset
for b in bs:
h ^= b
h *= fnv1a_prime
View base_26.py
def base26_encode(n, max_len=6):
# base-26 alphabet (A-Z)
value = ''
digits = n
while digits > 0:
if len(value) == max_len:
raise ValueError(n)
value += chr((digits % 26) + A)
digits /= 26
value += 'A' * max(max_len - len(value), 0)
@mgd020
mgd020 / template.py
Created Oct 29, 2019
python template engine
View template.py
import re
example = """
one
two
three
{% if 1 %}{% end %}
{{
dance(
View image_nes_filter.js
var image_nes_filter = (function() {
var PIXEL_SIZE = 4;
dither = (function() {
// Floyd–Steinberg dither
var ERROR_DIFFUSION_1_16 = 1 / 16,
ERROR_DIFFUSION_3_16 = 3 / 16,
ERROR_DIFFUSION_5_16 = 5 / 16,
ERROR_DIFFUSION_7_16 = 7 / 16,
@mgd020
mgd020 / fairqueue.py
Created Apr 23, 2019
Fair Queueing implementation for Python multiprocessing
View fairqueue.py
"""A multiprocessing Queue but is "fair" to every flow/session/channel.
See https://en.wikipedia.org/wiki/Fair_queuing.
"""
import sys
import time
from multiprocessing.queues import Queue
@mgd020
mgd020 / onetomanyfield.py
Created Mar 21, 2019
Adds OneToManyField django model field
View onetomanyfield.py
from django.db import models
from django.db.models.fields.related import ManyToManyRel, ReverseOneToOneDescriptor
from django.utils.translation import gettext_lazy as _
class OneToManyRel(ManyToManyRel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.multiple = False
You can’t perform that action at this time.