This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Copyright © Dirk Hoffmann -CPPM-, 2020 | |
import socket | |
UDP_IP = "255.255.255.255" | |
UDP_PORT = 60000 | |
msg = bytearray.fromhex('7effff0111000000000000000000000000000000000000000000000000000010020d') | |
print("UDP target IP:", UDP_IP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a string padded with leading zeroes for a given total length. | |
* There are other solutions around in stackoverflow etc., in particular | |
* org.apache.commons.lang.StringUtils.leftPad(), but this one is a concise | |
* and cheap solution for the particular case of 0-padding, as a reasonable | |
* feature for fixed-length <strong>binary</strong> is missing in the String | |
* and Integer classes up to now. | |
* | |
* @param s | |
* Input string (in particular binary form of number) to be padded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
// Create temp file. | |
File temp = File.createTempFile("pattern", ".suffix"); | |
// Delete temp file when program exits. | |
temp.deleteOnExit(); | |
// Write to temp file | |
BufferedWriter out = new BufferedWriter(new FileWriter(temp)); | |
out.write("aString"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enniceUnicodeError(ex): | |
return "<{0}>: {1}".format(ex.__class__.__name__, str(ex)) | |
if __name__ == '__main__': | |
/* Make dummy exception */ | |
ux=UnicodeDecodeError('hitchhiker', b"", 42, 43, 'the universe and everything else') | |
/* This is how to use the method : */ | |
print enniceUnicodeError(ux) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton(type): | |
""" | |
Comme discuté sur la liste [email protected] (accès restreint à la communauté ESR) | |
https://listes.services.cnrs.fr/wws/arc/python/2015-04/msg00006.html | |
- Solution pour singleton co(?)-production Loïc Gouarin, Konrad Hinsen et al. | |
""" | |
_instances = {} | |
def __call__(self, *args, **kwargs): | |
key = (str(self), args, str(kwargs)) | |
if key not in self._instances: |