Skip to content

Instantly share code, notes, and snippets.

@wrenoud
wrenoud / dtypeclass.py
Last active September 6, 2022 11:25
dataclass concept extended to support binary serialization/deserialization with numpy
from dataclasses import dataclass, astuple
import numpy as np
def dtypeclass(cls):
cls = dataclass(cls)
def frombuffer(cls, buffer, offset=0):
values = np.frombuffer(buffer, cls._dtype, count=1, offset=offset)
return cls(*values[0])
@wrenoud
wrenoud / decimate.py
Last active December 17, 2019 16:31
writes every `skip` line number
infile = open("input.txt")
outfile = open("output.txt", "w")
count = 0
skip = 30
for line in infile:
if count >= skip:
outfile.write(line)
count = 0
else:
import os
import hashlib
def getHashes(folder):
hashes = {}
for root, dirs, files in os.walk(folder):
for file in files:
filepath = os.path.join(root,file)
hash_md5 = hashlib.md5()
with open(filepath, "rb") as f:
The loneliest is a.
(Abs function)
(returns the absolute value of 'a thought')
Abs takes a thought
If a thought is greater than nothing
Give back a thought
Else
import xml.dom
import xml.dom.minidom
def childelements(parentnode):
for node in parentnode.childNodes:
if node.nodeType != xml.dom.Node.ELEMENT_NODE:
continue
yield node
def childlayers(parentnode):

Keybase proof

I hereby claim:

  • I am wrenoud on github.
  • I am wrenoud (https://keybase.io/wrenoud) on keybase.
  • I have a public key ASBZHXulETM0k23_CXEIxe-irp1QZNxSvbRyUOEHZLc9ewo

To claim this, I am signing this object:

@wrenoud
wrenoud / Hsda.py
Created March 25, 2016 21:56
Hsda.py
# coding: utf-8
import os
import requests
import re
import json
# hdsa
if not os.path.exists('hdsa.html'):
req =requests.request('get','http://hdsa.org/about-hdsa/locate-resources/')
f = open('hdsa.html','w')
@wrenoud
wrenoud / ExecTest.py
Created March 3, 2016 17:04
ExecTest.py
# coding: utf-8
import struct
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass. For 2/3 compatibility."""
class metaclass(meta):
__call__ = type.__call__
__init__ = type.__init__
def __new__(cls, name, this_bases, d):
if this_bases is None:
@wrenoud
wrenoud / Generate.py
Last active February 18, 2016 18:24
Generates some multibeam data
# coding: utf-8
import math
import sqlite3
from matplotlib import pylab as pl
conn = sqlite3.connect('data.db')
c = conn.cursor()
c.execute('DROP TABLE BEAMS')
@wrenoud
wrenoud / prepare-commit-msg.sh
Last active January 19, 2016 18:15 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master qm-release qm-stable fm-release fm-stable)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"