Skip to content

Instantly share code, notes, and snippets.

View ksqsf's full-sized avatar
:atom:
std::atomic

ksqsf ksqsf

:atom:
std::atomic
View GitHub Profile
@ksqsf
ksqsf / fix-debian-wslinterop.sh
Last active September 6, 2024 08:06
Fix Debian WSLInterop "cannot execute binary file: Exec format error"
# Copied from https://www.reddit.com/r/bashonubuntuonwindows/comments/11vx61n/comment/jdh2ovy/
# This problem only happens when you enable systemd support in /etc/wsl.conf.
apt update && apt install binfmt-support -y
cat > /usr/lib/binfmt.d/WSLInterop.conf <<EOF
:WSLInterop:M::MZ::/init:PF
EOF
systemctl restart systemd-binfmt
@ksqsf
ksqsf / 1a2b.rs
Last active August 27, 2024 14:54
Parallel solver for the n-digit 1a2b (Bulls and Cows) game in Rust
// The 'rayon' crate is required for parallel computing.
use rayon::prelude::*;
use std::fmt;
use std::io;
use std::io::Write;
use std::mem;
use std::str;
const N: usize = 6;
@ksqsf
ksqsf / .zshenv
Last active January 15, 2024 17:58
My zsh config
# Kitchen-sink for setting PATHs and other environmental variables.
# Also read by Emacs's exec-path-from-shell, so it has to be very short and fast.
export HOMEBREW_NO_INSTALL_FROM_API=1
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
@ksqsf
ksqsf / logseq.py
Last active January 28, 2026 09:20
Python interface to Logseq remote API
import requests
import json
# Doc site: https://plugins-doc.logseq.com/ .
# This list is auto-generated from https://github.com/logseq/plugins/tree/master/docs .
apis = [
'logseq.settings',
'logseq.updateSettings',
'logseq.once',
'logseq.toggleMainUI',
@ksqsf
ksqsf / biliaudio.lisp
Created October 29, 2022 06:56
下载 Bilibili 音频
(ql:quickload :dexador) ;; HTTP
(ql:quickload :yason) ;; JSON
(defun download-bilibili-audio (audio-id)
(let* ((headers '(("User-Agent" . "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18")
("Referer" . "https://bilibili.com")))
(cover-json (yason:parse (dex:get (format nil "https://www.bilibili.com/audio/music-service-c/web/song/info?sid=~a" audio-id))))
(cover-url (gethash "cover" (gethash "data" cover-json)))
(cover-data (dex:get cover-url))
(audio-json (yason:parse (dex:get (format nil "https://www.bilibili.com/audio/music-service-c/web/url?sid=~a" audio-id))))
@ksqsf
ksqsf / biliaudio.rs
Created May 18, 2022 18:49
下载 Bilibili 音频
#!/usr/bin/env cargo play -q
//# anyhow = "*"
//# reqwest = {version="*", features=["gzip","blocking"]}
//# serde_json = "*"
fn main() -> anyhow::Result<()> {
let audio_id = "832257";
let client = reqwest::blocking::Client::new();
let body = client.get(format!("https://www.bilibili.com/audio/music-service-c/web/song/info?sid={}", audio_id)).send()?.text()?;
let resp = &serde_json::from_str::<serde_json::Value>(&body)?["data"]["cover"];
let cover_url = resp.as_str().unwrap();
@ksqsf
ksqsf / biliaudio.hs
Last active June 15, 2022 08:16
下载 Bilibili 音频
#!/usr/bin/env cabal
{- cabal:
build-depends: base, relude, aeson, microlens-aeson, microlens-platform, http-conduit, conduit, conduit-extra, async
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main where
import Control.Concurrent.Async
@ksqsf
ksqsf / biliaudio.py
Last active May 13, 2022 11:27
下载 Bilibili 音频(编号以 au 开头的投稿)
import requests
#
# *** 修改这个 ***
#
audio_id = '832257'
# 完事后会下载到一个 m4a 文件和一个 cover.jpg

Keybase proof

I hereby claim:

  • I am ksqsf on github.
  • I am ksqsf (https://keybase.io/ksqsf) on keybase.
  • I have a public key ASDeVaqf2TVkWAwoSMtQcBtMNhw8mKc7r-APIwQe8wSV2Ao

To claim this, I am signing this object:

@ksqsf
ksqsf / wordle.hs
Created January 23, 2022 02:53
Wordle assistant
{-
HOWTO: use 'tellWords' to find possible inputs, guess, and then update 'rules'.
-}
module Main where
import System.IO
import Control.Monad.ST
import Data.Array.MArray
import GHC.Arr