Skip to content

Instantly share code, notes, and snippets.

@weirane
weirane / lambda-calculus.py
Last active Apr 20, 2021
Source file for "Lambda Calculus from the Ground Up"
View lambda-calculus.py
# Source file for my blog "Lambda Calculus from the Ground Up"
# https://blog.ruo-chen.wang/r/10 (zh_CN)
# Bool
def TRUE(x):
return lambda y: x
def FALSE(x):
return lambda y: y
@weirane
weirane / facebook-convert.py
Last active Feb 14, 2021
Convert exported facebook JSON data to UTF-8 encoded
View facebook-convert.py
#!/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
System tray for email syncing state
View gtk-mailtray.py
#!/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 Feb 15, 2020
Simple countdown script
View countdown
#!/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 Jan 29, 2020
A tampermonkey script to disable redirections of Google search results by removing onmousedown event of <a> tags
View remove-onmousedown.user.js
// ==UserScript==
// @name Remove onmousedown in Google results
// @include https://www.google.*/search?*
// ==/UserScript==
// Much thanks to https://gist.github.com/3081371
(function() {
'use strict';
View leetcode669.rs
// 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 Dec 29, 2019
Mount drives using dmenu
View dmenu-mount.sh
#!/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"
View test.rs
use std::path::PathBuf;
fn main() {
let p = PathBuf::from("/home/user");
println!("{}", p.display());
}