mc protocol

python Python
b'\xfe\xfd\t\x00\x00\x00\x00\x00\x00\x00\x00\x0b' # bytearray
# 0xFEFD   9    00000000         00000000   11
# prefix | chalengeType | 0   | challenge | len

def write_varint(self, value):
    remaining = value
    ret = bytearray()
    for i in range(5):
        if remaining & ~0x7F == 0:
            ret.extend(struct.pack("!B", remaining))
            return ret
        ret.extend(struct.pack("!B", remaining & 0x7F | 0x80))
        remaining >>= 7
    raise ValueError("The value %d is too big to send in a varint" % value)

Minecraft status json

python Python
from mcstatus import MinecraftServer
import sys
import json

server = MinecraftServer.lookup(str(sys.argv[1]))

try:
  print(json.dumps(server.status().raw))

  print("Query :")
  print(json.dumps(server.query().raw))
except:
  print("{}")

Minecraft status

python Python
from mcstatus import MinecraftServer
import sys
import json

server = MinecraftServer.lookup(str(sys.argv[1]))

print("Status :")

status = server.status()
print(status.players.online)
print(status.players.max)
psname = []
psid = []

if status.players.sample is not None:
  for i in status.players.sample:
    psname.append(i.name)
    psid.append(i.id)

print(", ".join(psname))
print(", ".join(psid))

print(status.version.name)
print(status.version.protocol)

print(status.description["text"])
print(status.favicon)
print(status.latency)
print(json.dumps(status.raw))

print("Ping :")
print(server.ping())

print("Query :")
query = server.query()
print(query.players.online)
print(query.players.max)
print(", ".join(query.players.names))

print(query.software.version)
print(query.software.brand)
print(query.software.plugins)
print(json.dumps(query.raw))
print(query.motd)
print(query.map)

Wake on LAN script

python Python
#!/usr/bin/python
# envoi un packet avec 12 F plus 16 * l'address mac a une addres ip sur n'importe quelle port

import re
import socket
import struct

broadcast = "192.168.1.255"
mac = "30:9C:23:8F:86:6E"
port = 7

# debug
def debug(level, msg):
    print("%s" % msg)

def error(msg):
    debug(0, "ERREUR: %s" % msg)

def info(msg):
    debug(0, "INFO: %s" % msg)

# verification de l'adresse mac
nonhex = re.compile('[^0-9a-fA-F]')
mac = nonhex.sub('', mac)
if len(mac) != 12:
    error("L'adresse mac n'est pas bonne [%s]" % mac)
info("Envois du packet magique a : [%s]" % mac)

# 12 * F coller a 16 (ou +) * l'adresse mac
data = ''.join(['FFFFFFFFFFFF', mac * 16])

# data en binaire
send_data = ''
for i in range(0, len(data), 2):
    tmp_data = struct.pack('B', int(data[i: i + 2], 16))
    send_data = ''.join([send_data, str(tmp_data[0])])

# envoi
try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.sendto(send_data, (broadcast, port))
except:
    error("l'envois du packet n'a pas pus etre envoyer")

findUnicodeFont

py Python
#copy form https://superuser.com/questions/876572/how-do-i-find-out-which-font-contains-a-certain-special-character
import unicodedata
import os

fonts = []

for root,dirs,files in os.walk("/usr/share/fonts/"):
    for file in files:
       if file.endswith(".ttf"): fonts.append(os.path.join(root,file))
       if file.endswith(".otf"): fonts.append(os.path.join(root,file))

for root,dirs,files in os.walk("/home/charles/.local/share/fonts/"):
    for file in files:
       if file.endswith(".ttf"): fonts.append(os.path.join(root,file))
       if file.endswith(".otf"): fonts.append(os.path.join(root,file))

from fontTools.ttLib import TTFont

def char_in_font(unicode_char, font):
    for cmap in font['cmap'].tables:
        if cmap.isUnicode():
            if ord(unicode_char) in cmap.cmap:
                return True
    return False

def test(char):
    for fontpath in fonts:
        font = TTFont(fontpath)   # specify the path to the font in question
        if char_in_font(char, font):
            try:
                print(char + " " + unicodedata.name(char) + " in " + fontpath) 
            except ValueError as ve:
                print(char + " in " + fontpath)

test(u"●")
test(u"\u1F63A")
test(u"\u1F408")
test(u"")
test(u"")

Fish in Qt

py Python
#!/usr/bin/python3
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QPainter, QPixmap, QBitmap, QColor

MAX_SIZE = 250

class FishWindow(QWidget):
  def __init__(self):
    super().__init__()
    fishPixmap = self.loadFish("fish.png")

    self.setFixedSize(fishPixmap.size())

    # fishMask = fishPixmap.createMaskFromColor(QColor(0, 0, 0, 0), Qt.MaskOutColor)
    fishMask = fishPixmap.createMaskFromColor(QColor(0, 0, 0, 0), Qt.MaskInColor)
    # fishMask = fishPixmap.createHeuristicMask()
    self.setMask(fishMask)

    self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowMaximizeButtonHint)
    self.setAttribute(Qt.WA_TranslucentBackground, True)
    self.dragPosition = QPoint(0, 0)
    self.fishPixmap = fishPixmap
    self.windows = list()

  def loadFish(self, fileName):
    fishPixmap = QPixmap("fish.png")
    fishSize = fishPixmap.size()

    if fishSize.height() > fishSize.width():
      height = MAX_SIZE
      width = int(MAX_SIZE * fishSize.width() / fishSize.height())
    else:
      width = MAX_SIZE
      height = int(MAX_SIZE * fishSize.height() / fishSize.width())

    fishPixmap = fishPixmap.scaled(width, height, Qt.KeepAspectRatio)
    return fishPixmap

  def paintEvent(self, event):
    painter = QPainter(self)
    painter.drawPixmap(0, 0, self.fishPixmap)

  def mouseReleaseEvent(self, event):
    if event.button() == Qt.LeftButton:
      event.accept()
      self.newFish()

  def mousePressEvent(self, event):
    if event.button() == Qt.LeftButton:
      # self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
      self.dragPosition = self.mapFromGlobal(event.globalPos())
      event.accept()

  def mouseMoveEvent(self, event):
    if event.button() == 0:
      self.move(event.globalPos() - self.dragPosition)
      event.accept()
  def newFish(self):
    window = FishWindow()
    window.move(QPoint(500, 500))
    window.show()
    self.windows.append(window)

if __name__ == '__main__':
  app = QApplication([])
  fishWindow = FishWindow()
  fishWindow.show()
  app.exec_()