Skip to content

Instantly share code, notes, and snippets.

View quantum5's full-sized avatar

Guanzhong Chen quantum5

View GitHub Profile
@quantum5
quantum5 / instant-debian
Created October 20, 2021 06:05
Script to instantly create a temporary fresh install of Debian, no root access required (needs fakechroot, fakeroot, debootstrap)
#!/bin/bash
set -euo pipefail
assure_command() {
if ! command -v "$1" &> /dev/null; then
echo "$1 is required to run this script"
echo "Run: apt install $1"
exit 1
fi
}
@quantum5
quantum5 / wbscal.py
Created February 4, 2020 04:49
Wilderness Warbands calendar event generator (for RuneScape)
import argparse
import sys
import time
import uuid
from datetime import datetime, timedelta, timezone
ICAL_TIME = '%Y%m%dT%H%M%SZ'
def generate(f, begin=None, alarms=None, opaque=True, duration=15):
@quantum5
quantum5 / proof.md
Last active October 10, 2021 02:21

Keybase proof

I hereby claim:

  • I am quantum5 on github.
  • I am quantum5 (https://keybase.io/quantum5) on keybase.
  • I have a public key whose fingerprint is 1497 6D29 4E79 978E 1336 CF7E 3DC5 5F49 1A67 0BED

To claim this, I am signing this object:

@quantum5
quantum5 / winbackground.py
Created November 7, 2017 08:13
Let WSL use synchronize with Windows backgrounds
#!/usr/bin/env python
from __future__ import division
import time
import os
import threading
import subprocess
from wand.image import Image
from watchdog.events import FileSystemEventHandler
@quantum5
quantum5 / cert-expire-warn.py
Last active July 8, 2017 19:27
Certificate Expiration Warning Cron Program
import subprocess
import requests
import argparse
import time
import sys
import os
import re
from datetime import datetime, timedelta
from textwrap import dedent
@quantum5
quantum5 / requirements.txt
Last active December 12, 2015 03:24
DMOJ full setup requirements.txt
chardet==2.3.0
Django==1.9
django-appconf==1.0.1
django-compressor==1.6
django-cprofile-middleware==0.1
django-debug-toolbar==1.4
django-extensions==1.5.9
django-mailgun==0.8.0
-e git://github.com/django-mptt/django-mptt.git@b41869a9c7bbbdddd9112d684c9430b118b81e31#egg=django-mptt
django-newsletter==0.6.dev0
@quantum5
quantum5 / mode-turing.js
Created December 7, 2015 23:33
mode-turing.js to add to ace installation, based on https://github.com/yingted/ace
define("ace/mode/turing", [
"require", "exports", "module", "tokenizer", "ace/lib/oop",
"ace/mode/turing_highlight_rules", "ace/mode/folding/coffee"
], function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var TuringHighlightRules = require("./turing_highlight_rules").TuringHighlightRules;
var FoldMode = require("./folding/coffee").FoldMode;
import os
def download(file, source, target):
size = int(source.info().getheaders('Content-Length')[0])
print('Downloading {}, Size: {:,d}'.format(file, size))
downloaded = 0
block = 65536
timer = [time.time, time.clock][os.name == 'nt']
start = timer()
while True:
@quantum5
quantum5 / killback.py
Created December 17, 2013 21:55
Remove image background.
import pgmagick
def remove_background(image, background=None):
"""Returns a copy of `image` that only contains the parts that is distinct
from the background. If background is None, returns parts that are
distinct from white."""
if background is None:
background = pgmagick.Image(image.size(), 'white')
elif isinstance(background, pgmagick.Image):
blob = pgmagick.Blob()
@quantum5
quantum5 / SMTP.java
Last active October 12, 2017 04:46
Easy to use SMTP Library.
/**
* Copyright (c) 2013 Quantum
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the