Skip to content

Instantly share code, notes, and snippets.

@upsuper
upsuper / bind-backup.sh
Last active Apr 13, 2021
Script to automatically bind and unbind external USB drive on Synology NAS
View bind-backup.sh
#!/bin/bash
SERIAL="00000000"
echo "Looking for device with serial $SERIAL..."
for d in /sys/bus/usb/devices/*-*; do
if [[ -f "$d/serial" ]]; then
serial=$(<"$d/serial")
if [[ "$serial" = "$SERIAL" ]]; then
device="$(basename $d)"
View commodity_par.py
#!/usr/bin/env python3
# Copyright (C) 2021 Xidorn Quan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public 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,
@upsuper
upsuper / tree.md
Created Apr 28, 2012 — forked from hrldcpr/tree.md
一行 Python 实现树
View tree.md

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!

@upsuper
upsuper / complex.cpp
Created Jun 27, 2011
Complex class in C++
View complex.cpp
#include <iostream>
using namespace std;
template<typename T>
class Complex {
private:
T m_real;
T m_imag;
public:
Complex<T>(T real=0.0, T imag=0.0)
@upsuper
upsuper / transform.yaml
Last active Oct 5, 2020
An example transformation file for translated Simplified Chinese result of 2020 State of Rust survey. See https://github.com/upsuper/csv-transformer
View transform.yaml
---
- transform: timestamp
column: "C: End time"
header: "Timestamp"
from: "%d-%b-%Y %H:%M:%S"
to: "%d/%m/%Y %H:%M:%S"
- "E: Do you use Rust?"
- "F: How long did you use Rust before you stopped?"
- "G: How long ago did you stop using Rust?"
- transform: join
@upsuper
upsuper / rbtree.hpp
Last active Apr 1, 2020
A Red-Black Tree implemented in C++ (need C++11)
View rbtree.hpp
#ifndef RBTREE_RBTREE_H_
#define RBTREE_RBTREE_H_
#include <cstddef>
#include <cassert>
#include <utility>
namespace upsuper {
namespace learning {
@upsuper
upsuper / RevokeWoSign_FirefoxOSX.sh
Last active Sep 28, 2019
Script to revoke WoSign-related certificates on Firefox for OS X
View RevokeWoSign_FirefoxOSX.sh
#!/bin/bash
CERTUTIL="/usr/local/opt/nss/bin/certutil"
if [ ! -f "$CERTUTIL" ]; then
echo "certutil is not found." >&2
echo "You can install it via 'brew install nss'." >&2
exit 1
fi
RCC_DIR=RevokeChinaCerts
@upsuper
upsuper / Cargo.toml
Last active Jul 11, 2019
Verify whether there is any MD5 conflict in all possible Chinese mobile numbers https://twitter.com/upsuper/status/1148222832540672001
View Cargo.toml
[package]
name = "cnmobile-md5"
version = "0.1.0"
authors = ["Xidorn Quan <me@upsuper.org>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
lto = true
@upsuper
upsuper / bgmrank.rb
Last active May 14, 2019
统计 Bangumi 上一个用户的收藏的评分分布情况,已移至 https://github.com/upsuper/bgmrank
View bgmrank.rb
#!/usr/bin/env ruby
require 'optparse'
require 'net/http'
CATEGORIES = [:anime, :book, :music, :game, :real]
STATES = [:wish, :collect, :do, :on_hold, :dropped]
progress = true
options = {
@upsuper
upsuper / split-servo.py
Created Aug 3, 2018
A filter script of `hg transplant` for coordinated landing for Stylo development
View split-servo.py
#!/usr/bin/env python
# - * - coding: UTF-8 - * -
import sys
from subprocess import Popen, PIPE
SERVO_PATH = r'c:\\mozilla-source\\servo'
msg = sys.argv[1]