Skip to content

Instantly share code, notes, and snippets.

@edgesider
edgesider / Python: delete all items of list.py
Created August 27, 2018 03:50
Python: delete all items of list
l = [[], (), {}]
del l[:]

使用kde的快速启动时,如果要加入其他目录,往.xprofile里面加是不行的,kde会在启动时执行~/.config/plasma-workspace/env/目录下的文件,所以只需要在里面写上export语句就行了。

export PATH=$HOME/.local/bin:$PATH
@edgesider
edgesider / crontab&notify-send.md
Created September 11, 2018 05:23
crontab 中 notify-send 不起作用

在crontab中直接使用notify-send不会起作用,因为在crontab执行的shell里,缺少一个$DBUS_SESSION_BUS_ADDRESS变量,运行时设置以下这个变量就行了。

export DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/1000/bus'
@edgesider
edgesider / forward.md
Last active December 18, 2018 09:33
使用ncat端口转发
tail -f server_output | ncat -l -p 8888 --keep-open | ncat localhost 8000 >> server_output

这行命令可以将来自8888端口的数据转发到localhost:8000

Update

mkfifo fifo
cat fifo | ncat -l -p 8888 | pv | ncat localhost 8000 > fifo
@edgesider
edgesider / random.sh
Created November 3, 2018 17:16
generate random characters from /dev/urandom on Linux
cat /dev/urandom | od -x | cut - -d ' ' -f 2- --output-delimiter ''
@edgesider
edgesider / rekde.sh
Created November 4, 2018 05:21
restart plasma
#! /usr/bin/bash
kquitapp5 plasmashell && kstart5 plasmashell
@edgesider
edgesider / bytes_struct.cs
Created November 24, 2018 18:57
C#: interconversion between bytes and struct
protected static TStruct BytesToStruct<TStruct>(byte[] bs, int bs_length) where TStruct : new()
{
int typeLen = Marshal.SizeOf(typeof(TStruct));
IntPtr tmp = Marshal.AllocHGlobal(typeLen); // 分配托管内存
Marshal.Copy(bs, 0, tmp, bs_length); // 将字节复制到托管内存
TStruct rv = (TStruct)Marshal.PtrToStructure(tmp, typeof(TStruct));
Marshal.FreeHGlobal(tmp); // 释放托管内存
return rv;
}
@edgesider
edgesider / autofeh.py
Created January 7, 2019 07:50
autofeh: auto wallpaper changer for i3wm
#! /usr/bin/env python3
# change wallpaper every argv[2] seconds
# photo folder is argv[1]
# use "kill -s 10 `/tmp/autofeh.pid`" to change by yourself
import os
import sys
import time
import signal
@edgesider
edgesider / args_test.md
Created March 21, 2019 07:08
arguments test of shell function
test "$VERSION" || return 2
test "$FILE_NAME" || return 3
@edgesider
edgesider / args_parse.md
Last active March 21, 2019 07:11
shell script arguments parsing
want_touch_pinch=1
want_debug=0
want_temp_profile=0
want_verbose=0
while [ $# -gt 0 ]; do
  case "$1" in
    -h | --help | -help )
      usage
 exit 0 ;;