Skip to content

Instantly share code, notes, and snippets.

@belsander
belsander / Jenkinsfile
Created November 21, 2018 16:13 — forked from ftclausen/Jenkinsfile
Jenkins pipeline - An approach to get all commits since the last successful build.
// -*- mode: groovy -*-
// vim: set filetype=groovy :
node( 'some_node' ) {
stage( "Phase 1" ) {
sshagent( credentials: [ 'some_creds' ] ) {
checkout scm
def lastSuccessfulCommit = getLastSuccessfulCommit()
def currentCommit = commitHashForBuild( currentBuild.rawBuild )
if (lastSuccessfulCommit) {
@belsander
belsander / SetupStaticRouteThatOverrulesDefaultInterface.bat
Created June 6, 2018 04:23
In case you want to have your default gateway on a higher metric interface (so slower) and only use the lower metric interface for specific routes
REM If you want to set metrics on interfaces go to the confguration of the network interface:
REM (THIS IS NOT POSSIBLE WITH THE route COMMAND !!)
REM Goto: 'Internet Protocol Version 4 (TCP/IPv4)' -> Properties
REM Goto: 'General' -> Advanced
REM Goto: 'IP Settings'
REM Uncheck 'Automatic metric'
REM Type in the metric you want for that interface in 'Interface metric'
REM Find out what the interface number is
route print
@belsander
belsander / find_key_occurences.py
Last active May 3, 2018 14:26
Find all occurences of a key in a nested Python dictionary and return the occurences together with the keys
def find(find_object, result, keys=[]):
if isinstance(find_object, dict):
for key, value in find_object.iteritems():
find(value, result, keys + [key])
else:
if not(result):
result['values'] = [find_object]
result['keys'] = [keys]
else:
result['values'].append(find_object)
@belsander
belsander / adb_with_reconnect.sh
Last active December 17, 2016 15:52
Script to connect to Android device attached via the network. Reconnects if connection was lost.
#!/bin/bash
#
# adb_with_reconnect.sh: Wrapper around Android Debug Bridge which auto reconnects when network connection has to reestablished (Useful in case of unstable Android device or poor network connection. Also makes use of nmap for an analysis of the Android device, so installation of nmap is recommended
#
# Copyright (C) 2016 Sander Bel
#
# This program is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@belsander
belsander / football-data.co.uk_convert.py
Last active December 17, 2016 15:32
Convert XLS files from http://football-data.co.uk to a more workable CSV format
#!/usr/bin/python
"""football-data.co.uk_convert.py: Convert xslx files to one or more workable csv file(s)
Copyright (C) 2016 Sander Bel
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# Basic examples
>>> var1 = 100
>>> eval("50 + var1")
150
>>> eval("var1 = 25")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
var1 = 25
^
# Code below behaves the same as eval()
eval(compile(str_source_code, “<string>”, “eval”))
# Code below behaves the same as exec()
exec(compile(str_source_code, “<string>”, “exec”))
var = <any valid Python syntax you can place here is an expression>
import dbus
class dbus_parse(object):
__slots__ = ("__dbus_parse_dict", "__parse_dbus_dict", "__parse_dbus_list", "__parse_dbus_tuple", "__parse_dbus_var", "parse_dbus_vars")
def __init__(self):
self.__dbus_parse_dict = { dbus.String: str,
dbus.Int16: int, dbus.Int32: int, dbus.Int64: int,
dbus.UInt16: int, dbus.UInt32: int, dbus.UInt64: int,
dbus.Double: float,
dbus.Boolean: bool,
zip([iterable, ...])
# Example
>>> test_list1 = ["a", "b", "c"]
>>> test_list2 = [1, 2, 3]
>>> zip(test_list1, test_list2)
[('a', 1), ('b', 2), ('c', 3)]
>>> dict(zip(test_list1, test_list2))
{'a': 1, 'c': 3, 'b': 2}
>>> test_list2 = [1, 2, 3, 4]