Skip to content

Instantly share code, notes, and snippets.

View sphaero's full-sized avatar

Arnaud Loonstra sphaero

View GitHub Profile
from pyre import zbeacon
import zmq
import struct
import uuid
import socket
ctx = zmq.Context()
beacon = zbeacon.ZBeacon(ctx, 1200)
transmit = struct.pack('cccb16sH', b'Z',b'R',b'E',
1, uuid.uuid4().bytes,
# win_socket_test.py
#
# Test using netcat:
# nc -un 127.0.0.1 1200
# Broadcast test:
# socat - UDP-DATAGRAM:255.255.255.255:1200,broadcast
import socket
import struct
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
@sphaero
sphaero / uae_from_kodi.sh
Last active August 29, 2015 14:11
Start UAE from Kodi on the Raspberry PI (RaspBMC)
#!/bin/bash
#
# Start this script through the Advanced Launcher Addon
#
# This script fixes not getting a display after stopping Kodi
# After quitting UAE it will return to Kodi
#
# Expecting UAE4All in /home/pi/amiga/uae4all
#
# Author: Arnaud Loonstra <arnaud@sphaero.org>
@sphaero
sphaero / handover.py
Created June 4, 2015 08:40
Python passing object by reference through a socket
#!/usr/bin/python3
# WARNING: This is a very nast hack into passing the pointer of an
# object through a socket thus bypassing any copy. The garbage
# collector can remove an object before its being received so you
# should know what you are doing!
import threading
from PIL import Image, ImageDraw, ImageTk
import zmq
import time
@sphaero
sphaero / get_ifs.py
Created January 2, 2014 10:31
Get all interfaces and ipaddressen, python3 compatible. Tested on Linux
# Compatible with Python3, tested on Linux
# Author Arnaud Loonstra <arnaud@sphaero.org>
# based on <http://code.activestate.com/recipes/439093/#c1>
import socket
import fcntl
import struct
import array
import sys
# Based on http://carnivore.it/2012/10/12/python3.3_sendmsg_and_recvmsg
# Example of using the new recvmsg() method of the sockets module
import ipaddress
import socket
import ctypes
# First, we have to tell the socket we want to receive this additional data.
# As the socket module lacks some constants, we need to define them too.
IP_PKTINFO = 8
if __name__ == "__main__":
c = MlmClient()
c.connect("tcp://192.168.1.223:9999", 1000, "PythonTest")
c.set_consumer("stream", ".+")
msg = c.recv().popstr()
while (msg == "hello"):
print(msg)
msg = c.recv().popstr()
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#salaris_graph {
background-color: black;
color: white;
width: 400px;
height: 400px;
padding: 1em;
@sphaero
sphaero / zmq_dispatcher.py
Last active May 24, 2016 15:53
A Python Asyncore Dispatcher class for ZeroMQ (PyZMQ)
#!/usr/bin/python3
#
# A Python Asyncore Dispatcher class for ZeroMQ (PyZMQ)
# Copyright 2016 Arnaud Loonstra <arnaud@sphaero.org>
#
# I know Asyncore is sort of deprecated but it still used in many
# frameworks. Therefore this class makes it easy to implement
# ZeroMQ sockets into those frameworks.
#
# This Source Code Form is subject to the terms of the Mozilla Public
@sphaero
sphaero / cast2kodi.py
Last active November 28, 2017 10:34
Cast screen to kodi
#!/usr/bin/python3
#
# Cast screen to kodi, sort of like Chromecast functionality
#
# original version found on reddit:
# https://www.reddit.com/r/kodi/comments/5googi/push_stream_of_linux_desktop_to_kodi_using_vlc/
import sys
import time
import os