Skip to content

Instantly share code, notes, and snippets.

View sboisson's full-sized avatar

Stéphane sboisson

View GitHub Profile
@sboisson
sboisson / ssdp.py
Last active September 23, 2024 13:04 — forked from davea/ssdp.py
Tiny python SSDP discovery library with no external dependencies - Python 2 & 3 compatible
# Copyright 2014 Dan Krause
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@sboisson
sboisson / ansible-roles-dependencies.py
Created June 30, 2020 11:26
Use Graphviz to visualize roles dependencies
#!/usr/bin/env python3
import sys
import graphviz
from glob import glob
import yaml
import logging
logging.basicConfig(level=logging.DEBUG)
test
@sboisson
sboisson / kalman.py
Last active March 29, 2018 14:25
Kalman filter
class SingleStateKalmanFilter(object):
def __init__(self, A, B, C, x, P, Q, R):
self.A = A # Process dynamics
self.B = B # Control dynamics
self.C = C # Measurement dynamics
self.current_state_estimate = x # Current state estimate
self.current_prob_estimate = P # Current probability of state estimate
self.Q = Q # Process covariance
self.R = R # Measurement covariance
@sboisson
sboisson / Create_Iframe_Index_M3U8.bash
Created September 24, 2015 13:45 — forked from svagionitis/Create_Iframe_Index_M3U8.bash
Segment an mp4 file to HLS streaming files
#!/bin/bash
# Create an Iframe index from HLS segmented streams
# $1: Filename to be created
# $2: Location of segmented ts files
# Check how many arguments
if [ $# != 2 ]; then
echo "Usage: $0 [Input filename] [Location of segmented streams]"
exit 1;
fi
@sboisson
sboisson / Rx.Observable.cacheWithExpiration-demo.js
Last active August 14, 2017 18:43 — forked from trajakovic/Rx.Observable.cacheWithExpiration-demo.js
RxJs extension implementation for cache results with time expiration
var slowJob = Rx.Observable.defer(function () {
return Rx.Observable.return(Math.random() * 1000).delay(2000);
});
var cached = slowJob.cacheWithExpiration(5000);
var last = Date.now();
function repeat() {
last = Date.now();
cached.subscribe(function (data) {
@sboisson
sboisson / 576532-adaptive-replacement-cache.py
Created May 23, 2014 15:25
Adaptive Replacement Cache in python (Python recipe)
class Cache(object):
"""
>>> dec_cache = Cache(10)
>>> @dec_cache
... def identity(f):
... return f
>>> dummy = [identity(x) for x in range(20) + range(11,15) + range(20) +
... range(11,40) + [39, 38, 37, 36, 35, 34, 33, 32, 16, 17, 11, 41]]
>>> dec_cache.t1
deque([(41,)])
@sboisson
sboisson / gist:0272707f96bd17ed976c
Created May 23, 2014 14:56
Correctly reading CSV files in arbitrary encodings
import codecs
import csv
def csv_unireader(f, encoding="utf-8"):
for row in csv.reader(codecs.iterencode(codecs.iterdecode(f, encoding), "utf-8")):
yield [e.decode("utf-8") for e in row]
@sboisson
sboisson / ssdp.py
Last active March 21, 2016 18:50 — forked from dankrause/ssdp.py
#!/usr/bin/python
# Copyright 2014 Dan Krause
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software