Skip to content

Instantly share code, notes, and snippets.

View cbeuw's full-sized avatar
:octocat:
Nolite Te Bastardes Carborundorum

Andy Wang cbeuw

:octocat:
Nolite Te Bastardes Carborundorum
View GitHub Profile
@cbeuw
cbeuw / lahav.rs
Last active July 13, 2022 22:49
Read-dont-modify-write miscompilation
// From https://github.com/llvm/llvm-project/issues/56450#issuecomment-1183695905
use std::sync::atomic::fence;
use std::sync::atomic::Ordering::Acquire;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::atomic::Ordering::Release;
use std::{sync::atomic::AtomicI32, sync::atomic::AtomicBool, thread};
#[no_mangle]
pub fn rdmw(storing: &AtomicI32, sync: &AtomicI32, loading: &AtomicI32) -> i32 {

Before:

flowchart TB
    classDef default text-align:left
    direction TB
    STDNode("<b>Rust</b>
    The Rust standard library")
    subgraph VCRuntimeSubgraph["VCRuntime (Requires Visual Studio licence at build time)"]
        direction TB
        VCStartupNode("<b>VCStartup</b>
@cbeuw
cbeuw / http_redirector.py
Last active January 26, 2022 14:42
Universal HTTP to HTTPS redirector
import http.server
class Redirector(http.server.BaseHTTPRequestHandler):
def do_GET(self):
host = self.headers["Host"]
secure_uri = f"https://{host}{self.path}"
self.send_response(301)
self.send_header("Location", secure_uri)
self.end_headers()
@cbeuw
cbeuw / shadowsocks-ck-release.sh
Created February 13, 2019 09:26
Install shadowsocks-libev from package manager and install Cloak server from Github releases
#!/usr/bin/env bash
# Forked and modified by cbeuw from https://github.com/teddysun/shadowsocks_install/blob/master/shadowsocks-all.sh
PATH=$PATH:/usr/local/bin
export PATH
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
@cbeuw
cbeuw / shadowsocks-ck-build.sh
Last active March 13, 2019 15:20
Download source, compile and install shadowsocks-libev and Cloak
#!/usr/bin/env bash
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/go/bin:/usr/local/sbin:~/bin
export PATH
#
# Auto compile install Shadowsocks Server with Cloak
#
# Copyright (C) 2016-2018 Teddysun <[email protected]>
#
# Forked and modified by cbeuw from https://github.com/teddysun/shadowsocks_install/blob/master/shadowsocks-all.sh
#
@cbeuw
cbeuw / shadowsocks-gq-build.sh
Last active August 15, 2022 18:34
Download source, compile and install shadowsocks-libev and GoQuiet
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/go/bin:/usr/local/sbin:~/bin
export PATH
#
# Auto compile install Shadowsocks Server with GoQuiet
#
# Copyright (C) 2016-2018 Teddysun <[email protected]>
#
# Forked and modified by cbeuw from https://github.com/teddysun/shadowsocks_install/blob/master/shadowsocks-all.sh
#
@cbeuw
cbeuw / shadowsocks-gq-release.sh
Last active June 19, 2024 21:00
Install shadowsocks-libev from package manager and install GoQuiet server from Github releases
#!/usr/bin/env bash
# Forked and modified by cbeuw from https://github.com/teddysun/shadowsocks_install/blob/master/shadowsocks-all.sh
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1
@cbeuw
cbeuw / Y_combinator.py
Last active February 16, 2018 14:10
Anonymous Y combination implementation for Python. Derived from https://rosettacode.org/wiki/Y_combinator#Python but more elegant
Y = lambda f:(lambda y: f(lambda n: y(y)(n)))(lambda y: f(lambda n: y(y)(n)))
"""
Proof:
Y = lambda f:(lambda y: f(lambda n: y(y)(n)))
(lambda y: f(lambda n: y(y)(n)))
Y(g) = (lambda y: g(lambda n: y(y)(n))
(lambda y: g(lambda n: y(y)(n))
Y(g) = g(
lambda n: (
(lambda y: g(lambda n: y(y)(n)))