Skip to content

Instantly share code, notes, and snippets.

@zhuyifei1999
zhuyifei1999 / signbot.py
Last active April 15, 2022 14:53
Commons Signbot code
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# DUAL LICENSED: You are free to choose either or both of below licenses:
#
# 1.
#
# Published by zhuyifei1999 (https://wikitech.wikimedia.org/wiki/User:Zhuyifei1999)
# under the terms of Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
# https://creativecommons.org/licenses/by-sa/3.0/
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#
import sys
from PIL import Image
from PIL import ImageFile
ImageFile.MAXBLOCK = 1
#! /usr/bin/python
# -*- coding: UTF-8 -*-
#
# Tile merger
#
# Copyright (c) 2018 Zhuyifei1999
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@zhuyifei1999
zhuyifei1999 / build-root_fs.sh
Last active October 22, 2018 02:52
Build a Gentoo root_fs for QEMU/UML
#! /bin/bash
set -ex
TMPDIR=${TMPDIR:-/var/tmp}
IMAGE="$TMPDIR/root_fs"
STAGE3="$TMPDIR/stage3.tar"
ln -sf "$IMAGE" root_fs
# https://stackoverflow.com/a/49197786
@zhuyifei1999
zhuyifei1999 / ensure_clone_stack_slign.S
Created October 28, 2018 20:09
LD_PRELOAD glibc wrapper to make sure stacks pointers given to clone(2) wrapper are 16-aligned.
/*
* Make sure stacks pointers given to clone(2) wrapper are 16-byte aligned.
*
* Public Domain / CC0
*
* i386 glibc clone.S has:
* andl $0xfffffff0, %ecx
* x86-64 has no such sort and you hit
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838
* and sadness somtimes happens :(. Compile this with:
# Sources:
# https://unix.stackexchange.com/a/408628
# https://github.com/InBetweenNames/gentooLTO/issues/149#issuecomment-425747633
# date +%s > /root/world_rebuild/stage0
set -e
starttime="$(cat /root/world_rebuild/stage0)"
eix '-I*' --format '<installedversions:DATESORT>' | cut -f1,3 > /root/world_rebuild/stage1
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@zhuyifei1999
zhuyifei1999 / satanic.py
Created July 13, 2019 06:11
JS1 is utterly satanic, but so is Python... or is it?
# Inspired by:
# https://www.reddit.com/r/AskReddit/comments/ccbpzr/what_book_fucked_you_up_mentally/etmirvt/
import code
class NS(dict):
def __setitem__(self, key, val):
if key in self and hasattr(self[key], 'assign'):
return self[key].assign.__get__(self[key])(val)
@zhuyifei1999
zhuyifei1999 / Dockerfile
Last active September 20, 2019 22:07
Running gcc-with-cpychecker in Docker
# docker build -t gcc-with-cpychecker .
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y git g++-6 gcc-6-plugin-dev python3.7 libpython3.7 libpython3.7-dev python3-dev python3-six python3-pygments graphviz python3-lxml make
WORKDIR /usr/local/src
RUN git clone --branch v0.17 https://github.com/davidmalcolm/gcc-python-plugin.git gcc-python-plugin
WORKDIR /usr/local/src/gcc-python-plugin
RUN CC=gcc-6 CXX=g++-6 make PYTHON=python3 PYTHON_CONFIG=python3-config plugin
# WARNING:
# This code is thread-unsafe.
# This code may break dicts if any key __hash__ are mutated as a side effect.
# Don't use in production or with threads unless you know what you're doing.
import types
import ctypes
import sys
from queue import Queue