Skip to content

Instantly share code, notes, and snippets.

@Tokubara
Tokubara / get-yasnippet-expansion-by-name.el
Last active July 26, 2023 19:25
emacs yasnippet nested snippet
(defun my/get-yasnippet-content-by-name(snippet-name &optional mode)
(yas--template-content (yas--get-template-by-uuid (yas--table-get-create (or mode major-mode) ) snippet-name)))
(defun my/get-yasnippet-expansion-by-name(snippet-name &optional mode)
(let ((mode (or mode major-mode)) start-point snippet-expansion)
(save-excursion
;; (funcall mode)
(unless yas-minor-mode (yas-minor-mode))
(goto-char (point-max))
(insert "\n")
@Tokubara
Tokubara / my-delete-current-yasnippet-file.el
Created July 20, 2023 12:44
delete-yasnippet-snippet
(defun my/get-yasnippet-snippet-name ()
"Get the name of the Yasnippet defined in the current buffer."
(save-excursion
(goto-char (point-min))
(forward-line)
(when (looking-at "# name: \\(.*\\)$")
(match-string-no-properties 1))))
(defun my/get-yasnippet-mode ()
(when (eq major-mode 'snippet-mode)
@Tokubara
Tokubara / lunar.py
Created December 9, 2022 07:45
农历(阴历)/公历(阳历) 转换
#!/usr/bin/env python3.9
import sxtwl
import argparse
import datetime as dt
DATE_FORMAT = "%Y-%m-%d"
parser = argparse.ArgumentParser(description='convert between lunar and solar calendar')
parser.add_argument('date', metavar='date', type=str, nargs='?', default=dt.datetime.today().strftime(DATE_FORMAT),
help='date to convert')
parser.add_argument('-s', dest='is_solar', action='store_const',
@Tokubara
Tokubara / marktex_postprocess.pl
Created March 13, 2022 14:27
use MarkTex to convert obsidian markdown to latex
# 去除代码块后面的%
$enter_code = 0;
while(<>) {
if(/\\begin\{langbox\}/) {
$enter_code = 1;
} elsif(/\\end\{langbox\}/) {
$enter_code = 0;
}
if($enter_code) {
s/%(\s*)$/$1/;
@Tokubara
Tokubara / Makefile
Created July 3, 2021 09:59
不用libc, 使用汇编实现的memcpy
AS = gcc
CC = gcc
LD = ld
ASFLAGS += -g -m32
CFLAGS += -g -O0
CFLAGS += -march=i386 -m32 -fno-stack-protector
CFLAGS += -fcf-protection=none # remove endbr32 in Ubuntu 20.04 with a CPU newer than Comet Lake
LDFLAGS += -melf_i386
main: main.o memcpy.o
$(LD) $(LDFLAGS) -o main $^
@Tokubara
Tokubara / cm2u.sh
Created May 30, 2021 08:22
把mac的剪切板传输到ubuntu
cm2u () {
host=parallels@10.211.55.10
port=22
# tmp_file_path=$(mktemp -t clipboard.XXXXXX)
tmp_file_path=/tmp/clipboard.m2h
pbpaste > $tmp_file_path
scp -q -P $port $tmp_file_path $hpc_host:/tmp/
ssh -X -p $port $host "xclip -i -sel c < $tmp_file_path"
}
@Tokubara
Tokubara / barber.c
Created May 16, 2021 12:02
理发师问题的信号量实现
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define CHAIR_NUM 3
#define SOFA_NUM 4
#define CAPACITY 20
#define CUSTOMER_NUM 20
@Tokubara
Tokubara / jybc.sh
Created April 17, 2021 06:43
jupyter notebook的.ipynb格式的转换脚本
# 希望, jc a.ipynb, 得到a_ipynb.R, -f或者--format, 指定是得到md
# 反过来, jc a_ipynb.R能得到a.ipynb
# {{{1 全局变量
format=python # 默认是python
target_filename=""
# {{{1 print_usage
print_usage() {
@Tokubara
Tokubara / Makefile
Created March 28, 2021 02:40
多个markdown文件合并为一个markdown或者pdf文件
include_dir=build
source=~/Downloads/100-gcc-tips/md/src/*.md
title='gcc-100'
filename='gcc-100'
all: html epub rtf pdf mobi
markdown:
awk 'FNR==1{print ""}{print}' $(source) > $(filename).md
@Tokubara
Tokubara / gutentags.vim
Created March 17, 2021 08:19
对gutentags的设置
let g:gutentags_modules = ['ctags']
" config project root markers.
let g:gutentags_project_root = ['.git', 'Makefile', '.root']
" generate datebases in my cache directory, prevent gtags files polluting my project
let g:gutentags_cache_dir = expand('~/.cache/tags')
" change focus to quickfix window after search (optional).
let g:gutentags_plus_switch = 1