Skip to content

Instantly share code, notes, and snippets.

@amtlib-dot-dll
amtlib-dot-dll / flatpak-prune.py
Last active October 8, 2019 12:58
Remove unused Flatpak references, use `flatpak uninstall --unused` instead
import subprocess
from collections import defaultdict
from configparser import ConfigParser
def run(*args):
return subprocess.run(args, stdout=subprocess.PIPE, check=True, text=True).stdout
apps = set(run('flatpak', 'list', '--columns=ref', '--app').splitlines())
#!/usr/bin/env python3
import gi # NOQA: E402
gi.require_versions({
'Gtk': '3.0',
'Soup': '2.4'
}) # NOQA: E402
import sys
import asyncio
@amtlib-dot-dll
amtlib-dot-dll / versatileObject.js
Created November 23, 2018 09:04
A versatile object logging arbitrary methods
log = [];
return ((logger) => {
versatileFunction = new Proxy((() => {
obj = () => 0;
obj[Symbol.toPrimitive] = function (hint) {
switch (hint) {
case 'number':
return 0;
case 'string':
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
template<class F>
void split_string(const std::string& str, F&& pred, std::ostream& out) {
auto iter = str.cbegin();
decltype(iter) begin;
goto start;
@amtlib-dot-dll
amtlib-dot-dll / 基于动态规划的文件树的差分算法.md
Last active May 11, 2018 15:25
基于动态规划的文件树的差分算法

前提

  1. 有两个文件树(目录),记为原状态和新状态,代表同一个文件夹在两个时刻的状态快照
  2. 依 Windows 的表达习惯,文件夹下有两种项目,子文件夹和文件
  3. 文件夹的属性包括它的名称
  4. 文件的属性包括它的名称和文件内容
    • 文件内容不可访问,仅可获取文件的散列指纹
    • 当且仅当两个文件的散列指纹相等时,认为这两个文件的内容相同
  5. 当两个文件的名称和文件内容相等时,认为这两个文件相等
#include <algorithm>
#include <array>
#include <chrono>
#include <climits>
#include <iostream>
#include <iterator>
#include <numeric>
#include <random>
#include <vector>
import ctypes.util
from struct import pack
from ctypes import Structure, c_int, c_uint, c_uint8, c_uint32, c_uint64, c_char_p, c_void_p, POINTER
# /usr/include/seccomp.h
SCMP_ACT_KILL = 0x00000000
SCMP_ACT_TRAP = 0x00030000
SCMP_ACT_ERRNO = lambda x: (0x00050000 | (x & 0x0000ffff))
SCMP_ACT_TRACE = lambda x: (0x7ff00000 | (x & 0x0000ffff))
SCMP_ACT_LOG = 0x7ffc0000
line CODE JT JF K
=================================
0000: 0x20 0x00 0x00 0x00000004 A = arch
0001: 0x15 0x00 0x3e 0xc000003e if (A != ARCH_X86_64) goto 0064
0002: 0x20 0x00 0x00 0x00000000 A = sys_number
0003: 0x15 0x57 0x00 0x00000065 if (A == ptrace) goto 0091
0004: 0x15 0x56 0x00 0x00000067 if (A == syslog) goto 0091
0005: 0x15 0x55 0x00 0x00000086 if (A == uselib) goto 0091
0006: 0x15 0x54 0x00 0x00000087 if (A == personality) goto 0091
0007: 0x15 0x53 0x00 0x0000009a if (A == modify_ldt) goto 0091
@if (false)==(false) @cscript //nologo //e:jscript "%~dpnx0" %* & goto :eof @end
var shell = new ActiveXObject('Shell.Application');
var enumerator = new Enumerator(shell.BrowseForFolder(0, 'Please select the source folder', 0).Items());
var powerpoint = new ActiveXObject('PowerPoint.Application');
powerpoint.Visible = true;
destination = powerpoint.Presentations.Add();
destination.Slides.Add(1, 12);
destination.PageSetup.SlideSize = 15;
for (; !enumerator.atEnd(); enumerator.moveNext()) {
source = powerpoint.Presentations.Open(enumerator.item().Path);
FROM registry.fedoraproject.org/fedora-minimal
RUN for repo in /etc/yum.repos.d/*; \
do sed -i 's/metalink/#metalink/' $repo; \
sed -i 's/#baseurl=http:\/\/download.fedoraproject.org\/pub\/fedora\/linux/baseurl=https:\/\/mirrors.kernel.org\/fedora/' $repo; \
done; \
microdnf update --nodocs && microdnf install openssh-server passwd --nodocs && microdnf clean all; \
mkdir -p /var/run/sshd; \
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''; \
useradd -u $(( ( RANDOM % 10 ) + 70000 )) -U -m user; \
echo -e "password\npassword" | (passwd --stdin user); \