Skip to content

Instantly share code, notes, and snippets.

View royvandam's full-sized avatar
🚀

Roy van Dam royvandam

🚀
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / main.go
Created August 2, 2018 07:42
Roles API test
package main
import (
"net/http"
"github.com/gorilla/mux"
"log"
"encoding/json"
)
type Role struct {
@royvandam
royvandam / array_view.hpp
Last active February 12, 2020 08:16
array_view<T> a C style pointer array wrapper class with bounds checking, similar to std::span which is introduced in C++20.
#pragma once
#include <algorithm>
#include <iterator>
#include <stdexcept>
template <typename T>
class ArrayView
{
public:
@royvandam
royvandam / autossh.service
Created February 28, 2020 10:40
Auto-starting reverse SSH proxy using systemd service file
[Unit]
AssertPathExists=/home/${user}/.ssh/id_rsa
After=network.target
[Service]
User=${user}
WorkingDirectory=/
ExecStart=/usr/bin/ssh -vvv -N -T \
-R 0:localhost:22 \
-o PasswordAuthentication=no \