Skip to content

Instantly share code, notes, and snippets.

@devilholk
devilholk / sunet_ping.plot
Last active May 24, 2016 05:23
Ping times plotting
set terminal png size 1600,800 enhanced font "DejaVuSans,12" background rgb '#ff101010'
set output 'pingplot.png'
set title 'Svarstider (IPv4 ICMP Ping) till ping.sunet.se' textcolor rgb "#FF80C0FF" font "DejaVuSans-Bold,16"
set xdata time
set format x "%Y-%m-%d %H:%M:%S"
set rmargin at screen 0.85
@devilholk
devilholk / timestamp_ping.py
Created May 24, 2016 05:24
timestamp_ping.py
import re, sys, time
t = re.compile(r'time=(.*?) ms')
line = True
while line:
line = sys.stdin.readline()
r = tuple(t.finditer(line))
if len(r) == 1:
print(time.time(), r[0].group(1))
import struct
def Align(data, size=4, padding=b'\x00'):
return data + ((size-(len(data) % size)) % size) * padding
def Aligned_split(data, char, size=4):
i = data.index(char)
i += ((size-(i % size)) % size)
return data[:i], data[i:]
@devilholk
devilholk / notes.py
Created September 23, 2016 20:45
Some notes about using ctypes for accessing structured data
import ctypes
class rgba(ctypes.Structure):
_fields_ = (
('r', ctypes.c_uint8),
('g', ctypes.c_uint8),
('b', ctypes.c_uint8),
('a', ctypes.c_uint8),
)
@devilholk
devilholk / text_manipulation.py
Last active November 28, 2016 18:36
Simple text manipulation in python
class indented_line:
def __init__(self, line):
self.line = line.lstrip('\t')
self.tabs = len(line) - len(self.line)
def indent(self, indention):
return indented_line('\t'*(self.tabs + indention) + self.line)
@property
def stripped(self):
@devilholk
devilholk / output.c
Created November 28, 2016 18:33
Output of text manipulation example
//Include directives
#include <stdio.h>
#include <stdlib.h>
//Main application
int main(int argc, char* argv[]) {
printf("Hello World!\n");
}
@devilholk
devilholk / example.py
Created November 28, 2016 18:36
Example for text manipulation in python
T = indented_block
program_template = T([
'//Include directives',
'¶includes',
'',
'//Main application',
'¶main',
])
@devilholk
devilholk / using-__new__.py
Last active March 19, 2017 03:21
Example usage of the __new__ method of python objects
class list_of_lines:
__slots__ = 'data', #Not necersary for this example but __slots__ is always
# nice to make the members a bit more strictly defined
def __new__(cls, text_or_instance):
#We use cls instead of self to make it clear that it is the class,
# not the new instance as you would with __init__
#You could use __init__ together with __new__ of course but then you
# need to make sure the arguments of __init__ is compatible
@devilholk
devilholk / mining.lua
Created March 28, 2017 20:04
Unfinished script for turtle in minecraft/computercraft
-- Inledande tester
-- Config
ender_chest_slot = 2
bucket_slot = 1
my_inventory = peripheral.wrap('right') -- Assumes we have a duck antenna equipped to the right
dofile('navigation.lua')
@devilholk
devilholk / gltest.py
Created May 23, 2017 11:18
Testing using ctypes to use glfw
#Some testing
# Run this script with python 3
# Use the interactive mode, like:
# $ python3 -i gltest.py
# You need to have the glfw and of course GL runtimes
# Once you start the script you get a window
# You will also get the python interactive prompt in the terminal you started
# the script in
# Here you can adjust variables sx, sy, sr and s and directly observe the effect