Skip to content

Instantly share code, notes, and snippets.

View tspycher's full-sized avatar

Thomas Spycher tspycher

View GitHub Profile
@tspycher
tspycher / beam_introduction.py
Last active March 15, 2024 14:27
Very simple Pipeline for a warmup
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
from typing import Iterable
import dataclasses
@dataclasses.dataclass
class Person:
GENDER_MALE = "m"
GENDER_FEMALE = "f"
@tspycher
tspycher / dynamicDns.py
Created December 29, 2020 22:27
Update Route53 Entry with IP from dyndns clients
import json
import boto3
import base64
import os
def lambda_handler(event, context):
client = boto3.client('route53')
username,password = base64.b64decode(event.get("headers").get("Authorization").replace("Basic ", "")).decode().split(":")
if not password or not password == os.environ.get("password"):
@tspycher
tspycher / multicast_udp_discovery.py
Last active June 7, 2019 12:51
Example or udp discovery in python
import socket
import time
import uuid
import struct
instance_id = uuid.uuid4().hex
payload = "this is data"
multicast_group = ('224.31.5.85', 19845)
discovery = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
name = "Hubert"
class Thing():
attributes = {
"size": 12,
"weigth": 20,
"name": "a thing"
}
@property
@tspycher
tspycher / queue-it_example.py
Created December 19, 2017 13:02
Queue-It.org Python Flask Example
from flask import Flask, redirect, request
import hashlib
import re
app = Flask(__name__)
# plays best with ngrok proxy server https://ngrok.com/
@app.route("/")
def hello():
@tspycher
tspycher / thread.py
Created March 7, 2017 09:35
Simple Multithreaded Synchronisation routine
#!/usr/bin/python
import time
import threading
import Queue
import random
class BaseSynchronisation(object):
num_threads = 5
threads = None
@tspycher
tspycher / flask_session_injector.php
Last active March 7, 2019 14:01
Flask Session generation in PHP
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
// payload
$data = array("username"=>"John");
$data_json = json_encode($data);
$dataz = gzcompress($data_json);
if(strlen($dataz) < (strlen($data_json) - 1))
@tspycher
tspycher / array_diff_example.php
Created May 25, 2016 08:56
array_diff() example with objects instead of primitives
<?php
class X {
public $name;
public function __construct($name) {
$this->name = $name;
}
# This must be defined in order to have array_diff() working
#public function __toString() {
# return $this->name;
@tspycher
tspycher / send.py
Created May 20, 2016 08:11
Sends a message to HipChat and allows configuration by parameters
from hypchat import HypChat
import re
import sys
import argparse
import select
from hypchat.requests import HttpClientError
parser = argparse.ArgumentParser(description='Simply sends a message to a given room')
parser.add_argument('-t', '--token', action='store', dest="apitoken", default='xxxxxx')
parser.add_argument('-r', '--room', action='store', dest="room", default='rnd')
@tspycher
tspycher / simple_tournament.py
Last active May 12, 2016 11:50
A fellow just asked me how simple it would be to create the most simple tournament application. this is what came out in a couple of minutes.
import random
import math
teamof = 2
def teams(people):
teams = []
for i in range(len(people) / teamof):
team = []
for i in range(teamof):
p = random.choice(people)