Skip to content

Instantly share code, notes, and snippets.

@ksqsf
ksqsf / plot_arch.py
Created August 6, 2017 17:36
Plot the number of notices on the official site of Arch Linux
import urllib.request
from datetime import datetime
from collections import Counter
from threading import Thread
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
base_url_fmt = "https://www.archlinux.org/news/?page=%d"
max_page = 13
@ksqsf
ksqsf / bot-killer.py
Last active August 10, 2017 05:54
An addon for hexchat to remove the names of forwarding bots
#
# an addon for hexchat to remove the names of forwarding bots.
#
import hexchat
__module_name__ = 'bot-killer'
__module_version__ = '0.1.0'
__module_description__ = 'Eliminate the names of forwarding bots'
@ksqsf
ksqsf / acm-mode.el
Last active June 6, 2018 16:19
ACM Minor mode for Emacs
;
; ACM-Mode
;
; This is not a complete work.
; Be sure to tweak it as you like before you use this!
;
; NOTE: I won't update this Gist when I make improvements to my own ACM mode.
;
; This file belongs to Public Domain.
; Original author: ksqsf
@ksqsf
ksqsf / echo.rs
Created January 26, 2018 14:18
an echo server in Rust
use std::net::{TcpListener, TcpStream};
use std::io::prelude::*;
use std::io::{BufReader, Result, Write};
use std::thread;
fn handle_client(mut stream: TcpStream) -> Result<()> {
thread::spawn(move || {
println!("A new thread spawned for {:?}", stream);
let mut reader = BufReader::new(stream.try_clone().unwrap());
@ksqsf
ksqsf / ustc.py
Created January 29, 2018 20:58
USTC Web services
"""
the USTC module
NOTE: this is an incomplete framework! extend it as you like.
PS: don't expect to receive updates or changes from me! this is not intended to be published anyway. :-p
"""
from bs4 import BeautifulSoup
import requests
@ksqsf
ksqsf / move_music.py
Created May 29, 2018 08:58
Move MP3 files to a specific directory with tags modified, which can save me tremendous amount of time!
#!/usr/bin/python3
# This is an interactive program to help myself rename and move a bunch of
# music files.
#
# Written by ksqsf <i@ksqsf.moe>
import os
import glob
from pathlib import Path
@ksqsf
ksqsf / sigsegv.rs
Last active March 15, 2023 03:55
Catch SIGSEGV in Rust
#![feature(libc)]
extern crate libc;
use libc::*;
use std::panic::*;
use std::ptr::*;
fn main() {
unsafe {
@ksqsf
ksqsf / netease-cloud-music
Created June 12, 2018 13:07
解决网易云音乐无法启动的问题
#!/bin/sh
# 首先,将 netease-cloud-music 移动到 netease-cloud-music.bin
# 然后将本文件保存为 /usr/bin/netease-cloud-music 并设置可执行权限
FILE="$HOME/.ICEauthority"
BACKUP="$HOME/.ICEauthority.netease-cloud-music"
if [ -e $FILE ]
then
@ksqsf
ksqsf / region-ring.el
Last active December 2, 2018 13:33
Region ring
(defvar region-ring nil)
(defvar region-ring-max 60)
(defun push-region ()
"Push the current region into the global region ring. The
current mark will not be popped off the mark ring."
(interactive)
(let ((buffer (current-buffer))
(mark (copy-marker (mark-marker)))
(point (point-marker)))
@ksqsf
ksqsf / wc-ring.el
Last active December 2, 2018 13:33
Window Configuration Ring
(defvar wc-ring nil)
(defvar wc-ring-max 10)
(defun push-wc ()
(if (not (null (get-register ?9)))
(set-register ?0 (get-register ?9)))
(dolist (i '(?9 ?8 ?7 ?6 ?5 ?4 ?3 ?2))
(if (not (null (get-register (1- i))))
(set-register i (get-register (1- i)))))
(window-configuration-to-register ?1))