Skip to content

Instantly share code, notes, and snippets.

View royvandam's full-sized avatar
🚀

Roy van Dam royvandam

🚀
View GitHub Profile
@royvandam
royvandam / string.cpp
Last active January 24, 2020 14:44
C++ String tools
/*
Copyright (c) 2018, 2019 Roy van Dam <[email protected]>
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:
@royvandam
royvandam / tail.cpp
Created June 13, 2018 16:07
C++11 cross platform tail class for tailing streams
#include <iostream>
#include <fstream>
#include <vector>
#include <istream>
#include <chrono>
#include <thread>
class Tail {
public:
@royvandam
royvandam / googletest.cmake
Created March 19, 2018 20:10
Include Google Test into a CMake project as external project
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
ExternalProject_Add(googletest
GIT_REPOSITORY "https://github.com/google/googletest.git"
GIT_TAG "master"
UPDATE_COMMAND ""
INSTALL_COMMAND "")
SET(GTEST_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest-prefix/src/googletest/googletest/include)
SET(GTEST_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest-prefix/src/googletest-build/googlemock/gtest)
@royvandam
royvandam / util.py
Last active November 6, 2017 10:58
Small collection of Python utility functions and classes
import tempfile, os, shutil
import socket, errno
import subprocess
import platform
class dotdict(dict):
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
@royvandam
royvandam / rsh.py
Created November 1, 2017 20:20
Python RSH client
import subprocess
class RemoteShell:
def __init__(self, hostname, port=514, username='root', encoding='ascii'):
self.hostname = hostname
self.port = port
self.username = username
self.encoding = encoding
self.rsh = ['/usr/bin/rsh', '-p', str(port), '%s@%s' % (username, hostname) ]
@royvandam
royvandam / eth2080.py
Last active April 30, 2017 21:09
Antratek ETH8020 python relay control script
import socket
import struct
class eth8020:
def __init__(self, hostname, port=17494):
self.s = socket.create_connection((hostname, int(port)))
def execute(self, request):
self.s.send(request)
response = self.s.recv(10)
@royvandam
royvandam / svn_ignore.py
Created December 16, 2016 18:44
Add files to svn:ignore propset the easy way...
#!/usr/bin/env python
# Call from your SVN directory the following way:
# svn status | grep '?' | tr -s ' ' | cut -d' ' -f2 | xargs -n1 ./svn_ignore.py
import sys, os, subprocess
def svn(action, argv=[], stdin=None):
cmd = ['svn', action]
cmd.extend(argv)
@royvandam
royvandam / svn_stash.sh
Created December 7, 2016 15:15
Hackish Git like SVN stash drop in shell function
svn() {
local svn_cmd='/usr/bin/env svn'
case $1 in
stash)
case $2 in
"")
if ! $svn_cmd status | grep -q '^M'; then
echo "No outstanding changes"
return
fi
@royvandam
royvandam / selector.py
Last active October 21, 2016 13:22
Some BeagleBone Black python code to poll a digital IO pin and send a UDP command to a video player
#!/usr/bin/env python2
import signal, time, threading, socket, sys
import Adafruit_BBIO.GPIO as GPIO
class Pir:
def __init__(self, pin, pud=GPIO.PUD_UP):
self.pin = pin
self.pud = pud
GPIO.setup(self.pin, GPIO.IN, pull_up_down=pud)
@royvandam
royvandam / server2server.py
Created October 1, 2016 12:55
Small python script that connects one or more TCP servers to each other.
#!/usr/bin/env python
import sys
import socket
import select
def usage(name):
print('Usage {} [hostname:port](2..n)'.format(name))
if (len(sys.argv) < 3):