Skip to content

Instantly share code, notes, and snippets.

@weirane
weirane / lambda-calculus.py
Last active August 29, 2023 20:51
Source file for "Lambda Calculus from the Ground Up"
# Source file for my blog "Lambda Calculus from the Ground Up"
# https://blog.ruo-chen.wang/r/10 (zh_CN)
# How to play with it:
# First load this file into the python interpreter:
# $ python3 -i lambda-calculus.py
# Then try:
# >>> toint(FACT(FOUR))
# Bool
@weirane
weirane / facebook-convert.py
Last active February 14, 2021 01:35
Convert exported facebook JSON data to UTF-8 encoded
#!/usr/bin/python3
# Convert all JSON files inside directory `facebook`:
# $ fd --extension=json . facebook -x ./facebook-convert.py
import json
import sys
def parse(obj):
@weirane
weirane / gtk-mailtray.py
Created May 30, 2020 01:41
System tray for email syncing state
#!/usr/bin/python3
# System tray icon displaying email syncing state.
# Tell the tray that email is syncing:
# kill -USR1 $(cat $XDG_RUNTIME_DIR/mailtray.pid)
# Sync has completed and recalculate new emails:
# kill -USR2 $(cat $XDG_RUNTIME_DIR/mailtray.pid)
#
# However, the `Gtk.StatusIcon` used in this script has been deprecated and I haven't found a
# replacement.
@weirane
weirane / countdown
Last active February 15, 2020 15:16
Simple countdown script
#!/bin/bash
# Count down for a specified time
# Example (count down for 3 minutes and 30 seconds):
# $ countdown 3m 30s
shopt -s extglob
time=0
@weirane
weirane / remove-onmousedown.user.js
Last active January 29, 2020 11:58
A tampermonkey script to disable redirections of Google search results by removing onmousedown event of <a> tags
// ==UserScript==
// @name Remove onmousedown in Google results
// @include https://www.google.*/search?*
// ==/UserScript==
// Much thanks to https://gist.github.com/3081371
(function() {
'use strict';
@weirane
weirane / leetcode669.rs
Last active January 16, 2020 07:49
LeetCode 669
// This is a solution to a modified version of LeetCode 669. The original problem
// requires the modified root of the binary tree to be returned, while the solution
// below modifies it in place rather than returning the new root.
//
// https://leetcode.com/problems/trim-a-binary-search-tree/
// https://rust.cc/article?id=93bb5260-7e17-4d1c-bc42-08a9873f219c
use std::cell::RefCell;
use std::rc::Rc;
@weirane
weirane / dmenu-mount.sh
Created December 29, 2019 04:38
Mount drives using dmenu
#!/bin/sh
chosen=$(lsblk -rnpo "name,label,size,type,mountpoint" |
awk '/part $/ { printf "%s %s (%s)\n",$1,$2,$3 }' |
dmenu -i -l 10 -p "Mount which drive?" |
cut -d' ' -f1)
if [ $? = 0 ] && [ -n "$chosen" ]; then
msg=$(udisksctl mount -b $chosen)
notify-send '💻 Mount' "$msg"
use std::path::PathBuf;
fn main() {
let p = PathBuf::from("/home/user");
println!("{}", p.display());
}