Skip to content

Instantly share code, notes, and snippets.

@upsuper
upsuper / delayed_balance.py
Created June 27, 2021 10:29
Beancount plugin to handle transactions geting delayed and not being included in the next bank statement
#!/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 / bind-backup.sh
Last active March 13, 2024 17:08
Script to automatically bind and unbind external USB drive on Synology NAS
#!/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)"
diff -ur a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp
--- a/CPP/7zip/Archive/Zip/ZipItem.cpp 2016-02-02 03:50:10.000000000 +1100
+++ b/CPP/7zip/Archive/Zip/ZipItem.cpp 2023-08-15 23:19:44.862769098 +1000
@@ -1,6 +1,7 @@
// Archive/ZipItem.cpp
#include "StdAfx.h"
+#include <iconv.h>
#include "../../../../C/CpuArch.h"
@upsuper
upsuper / directory_icon.c
Created January 24, 2012 16:57
Set directory icon on Mac
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <CoreServices/CoreServices.h>
#include "directory_icon.h"
int setDirectoryIcon(const char *dirName, const char *iconData, size_t iconSize)
{
const int kResidIcon = -16455;
const OSType kRsrcType = 'icns';
@upsuper
upsuper / tree.md
Created April 28, 2012 10:38 — forked from hrldcpr/tree.md
一行 Python 实现树

一行 Python 实现树

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

def tree(): return defaultdict(tree)

就是这样!

@upsuper
upsuper / import-playcount.py
Created February 12, 2023 11:01
Scripts to import from iTunes
#!/usr/bin/env python3
import plistlib
import sqlite3
import uuid
from collections import defaultdict
from datetime import datetime
from typing import NamedTuple
from urllib.parse import unquote
@upsuper
upsuper / complex.cpp
Created June 27, 2011 14:38
Complex class in C++
#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 / LICENSE
Last active July 15, 2022 03:02
A Java implementation of SHA-224 message digest algorithm with Provider
Copyright (c) 2012 Xidorn Quan
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
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@upsuper
upsuper / rbtree.hpp
Last active October 3, 2021 21:28
A Red-Black Tree implemented in C++ (need C++11)
#ifndef RBTREE_RBTREE_H_
#define RBTREE_RBTREE_H_
#include <cstddef>
#include <cassert>
#include <utility>
namespace upsuper {
namespace learning {
#!/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,