Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / rbtree.cc
Last active September 21, 2022 07:53
red black tree
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <random>
#include <vector>
enum Color { Black, Red };
enum Leaf { Left, Right };
@scturtle
scturtle / list.cc
Last active September 10, 2022 17:02
double linked list
#include <iostream>
struct ListNode {
void *m_prev = nullptr;
void *m_next = nullptr;
};
template <typename T> struct List {
private:
T *m_head = nullptr;
@scturtle
scturtle / build.sh
Last active October 23, 2023 03:06
build minimal emacs
# ubuntu/debian
# sudo apt install libjansson-dev texinfo gnutls-bin
# homebrew
brew install jansson texinfo
# build
CFLAGS="-O2 -DNDEBUG" ./configure \
--without-all --without-x --without-ns --without-libgmp \
--with-json --with-modules --with-threads \
@scturtle
scturtle / xrandr.sh
Created January 14, 2022 09:18
xrandr.sh
#!/bin/bash
# xrandr # to see infos
# arandr # gui
echo -n "builtin(1) external(2) sidebyside(3) mirror(4): "
read choice
BUI=`xrandr | grep ' connected' | awk 'NR==1 {print $1}'`
BUIMODE=`xrandr | grep $BUI -A1 | awk 'FNR==2 {print $1}'`
@scturtle
scturtle / qlocktwo.py
Last active August 11, 2021 15:26
qlocktwo in python
from datetime import datetime
t = datetime.now()
H, M = t.hour % 12, t.minute
HL, DK = '\033[0m', '\033[2m'
RESET = HL
MM = lambda *rgs: HL if any(a <= M < b for a, b in rgs) else DK
HH = lambda h: HL if (M < 35 and H == h) or (M >= 35 and H + 1 == h) else DK
print(f'''\
{HL}I T{DK} L {HL}I S{DK} A S T I M E
{MM((15, 20), (45, 50))}A{DK} C {MM((15, 20), (45, 50))}Q U A R T E R{DK} D C
@scturtle
scturtle / adventofcode.css
Last active December 5, 2020 01:56
adventofcode daylight mode css
body {
background: #fff;
color: #000;
}
a {
text-decoration: underline;
color: #000;
}
a:hover,
a:focus {
@scturtle
scturtle / crypt.py
Last active April 8, 2021 08:02
encrypt/dectypt file like vim blowfish2 in python
#!/usr/bin/env python
import struct
import hashlib
from binascii import b2a_hex
class Blowfish:
def __init__(self, key):
self.p_boxes = [0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B]
self.s_boxes = [[0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013, 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A, 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA3
BasedOnStyle: LLVM
IndentWidth: 4
BreakBeforeBraces: Custom
ColumnLimit: 80
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
@scturtle
scturtle / backup.sh
Last active March 14, 2020 00:49
script to backup file to dropbox
!/usr/bin/bash
DROPBOX_KEY='XXXXXX'
FILENAME=XXXXXX
cd XXXXXX
tar czf $FILENAME XXXXXX > /dev/null
/usr/bin/python - <<END
import dropbox
from dropbox.files import WriteMode
from os.path import getsize, basename
dbx = dropbox.Dropbox('$DROPBOX_KEY')
@scturtle
scturtle / autolock.sh
Last active July 24, 2020 06:44
手机插电脑解锁拔下来锁屏
#!/bin/bash -x
VENDOR="05ac:12a8"
SERIAL="XXXXXXXXXXXXXXXXX"
#LOCK="gnome-screensaver-command -l"
#UNLOCK="gnome-screensaver-command -d"
LOCK="slock"
UNLOCK="killall slock"
while true; do
# wait new device status
stdbuf -o0 udevadm monitor --udev | stdbuf -o0 grep usb | head -n1 > /dev/null