Skip to content

Instantly share code, notes, and snippets.

View KmolYuan's full-sized avatar
🦀
Rust programmer!

Yuan Chang KmolYuan

🦀
Rust programmer!
  • National Taiwan University (Ph.D. Student)
  • Taipei, Taiwan
  • 20:29 (UTC +08:00)
View GitHub Profile
@KmolYuan
KmolYuan / number.py
Last active September 24, 2018 14:39
number synthesis
from itertools import product
def Max(NL, NJ):
"""Find max number of joint on each link.
+ NL <= NJ and NJ <= (2 * NL - 3)
+ (2 * NL - 3) <= NJ and NJ <= (NL * (NL - 1) / 2)
+ other exceptions (return -1).
"""
@KmolYuan
KmolYuan / longtable.diff
Created May 15, 2019 06:47
Latex longtable.sty patch for the error of table overflow.
--- /usr/share/texmf/tex/latex/tools/longtable.sty 2001-09-27 06:50:51.000000000 -0400
+++ longtable.sty 2003-03-09 15:34:04.000000000 -0500
@@ -160,7 +160,7 @@
\ifdim \dimen@>\z@\vfil\break\fi
\global\@colroom\@colht
\ifvoid\LT@foot\else
- \advance\vsize-\ht\LT@foot
+ \global\advance\vsize-\ht\LT@foot
\global\advance\@colroom-\ht\LT@foot
\dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
@KmolYuan
KmolYuan / micfeedback.sh
Last active September 18, 2023 19:19
Microphone feedback on Linux.
#!/usr/bin/env bash
# Directs audio input (e.g. mic) to audio output (e.g. speakers),
# then sleeps forever. Stops audio redirection when it is killed.
# So, for example, plug your phone into the PC's mic, run 'listen',
# and listen to phone audio through your computer's speakers.
set -e
module=$(pactl load-module module-loopback latency_msec=50)
@KmolYuan
KmolYuan / .clang-format
Last active September 1, 2020 07:56
My C ++ writing habits.
BasedOnStyle: Google
Language: Cpp
ColumnLimit: 80
IndentWidth: 4
PointerAlignment: Right
UseTab: Never
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceAfterTemplateKeyword: false
@KmolYuan
KmolYuan / rust_install.md
Last active August 22, 2022 01:34
Install Rust for Msys2.

在 Msys2 上安裝最新版 Rust

  1. 安裝 Msys2:https://www.msys2.org/

  2. 安裝後啟動 msys2.exe 執行以下命令安裝 GNU toolchain。(如官方說明所示)

    pacman -S --needed base-devel mingw-w64-x86_64-toolchain
@KmolYuan
KmolYuan / addsrt.bat
Created March 25, 2020 08:47
Add subtitle.
@echo off
REM Usage:
REM addsrt "video_name"
REM (video_name.mp4 + video_name.srt) => video_name_new.mp4
ffmpeg -y -i "%1.mp4" -vf subtitles="%2.srt" -c:s mov_text "%1_new.mp4"
@KmolYuan
KmolYuan / newton_method.py
Last active July 11, 2020 01:42
A basic Newton method prototype.
# -*- coding: utf-8 -*-
"""Newton method to solve three equations.
x^2 + y^2 = 800
y^2 + z^2 = 1300
x^2 + z^2 = 1300
[x = 20, y = 20, z = 30]
"""
from typing import Sequence, Callable
@KmolYuan
KmolYuan / struct2bin.cpp
Created July 17, 2020 12:13
Save structure to a binary file.
#include <cstdio>
#include <fstream>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
using array1d = vector<double>;
using array2d = vector<array1d>;
using array3d = vector<array2d>;
@KmolYuan
KmolYuan / swappable_pair.hpp
Last active October 8, 2020 05:55
A swappable pair container for STL set or map.
#include <iostream>
#include <set>
#include <map>
template<typename T>
struct SwappablePair {
T field1, field2;
inline auto operator==(const SwappablePair &rhs) const -> bool {
return (field1 == rhs.field1 && field2 == rhs.field2) ||
@KmolYuan
KmolYuan / tablet.sh
Last active December 12, 2020 04:52
Huion tablet using Wacom driver in Linux Krita.
#!/bin/bash
# Wait for the GUI to be ready
while [[ ! $(pgrep plasmashell) ]]; do sleep 1; done
xsetwacom set "HID 256c:006d Pad pad" button 1 key 2
xsetwacom set "HID 256c:006d Pad pad" button 2 key Ctrl S
xsetwacom set "HID 256c:006d Pad pad" button 3 key -
xsetwacom set "HID 256c:006d Pad pad" button 8 key +
xsetwacom set "HID 256c:006d Pad pad" button 9 key Ctrl Shift Z