Skip to content

Instantly share code, notes, and snippets.

@fudanchii
fudanchii / keybase.md
Created October 29, 2023 14:36
keybase

Keybase proof

I hereby claim:

  • I am fudanchii on github.
  • I am fdnch (https://keybase.io/fdnch) on keybase.
  • I have a public key whose fingerprint is 4220 A1EA D1FE 4E91 3B56 4774 C182 B356 90E2 6D66

To claim this, I am signing this object:

module github.com/fudanchii/ring
go 1.20
require (
github.com/samber/lo v1.38.1
github.com/zeebo/xxh3 v1.0.2
go.mongodb.org/mongo-driver v1.11.6
)
require 'openssl'
# ref: https://datatracker.ietf.org/doc/html/rfc6238
class TOTP
def initialize(secret:, t0: 0, x: 30, len: 10)
raise TOTP::Error::InvalidSecret if secret.nil?
@secret = secret
@t0 = t0
@x = x
#!/usr/bin/env bash
args=$@
if [[ $1 == "bundle-spec" ]]; then
docker run -i -t --rm \
-v $PWD:/app \
-v $HOME:$HOME \
-v /etc/passwd:/etc/passwd \
-e USER=$USER \
@fudanchii
fudanchii / Makefile
Last active December 19, 2020 22:58
generic Makefile for Go cross compilation to ios/arm64 from linux
CC = $(IOS_TOOLCHAIN_BIN)/arm64-apple-darwin14-clang
CGO_ENABLED = 1
IOS_SDK_FLAGS = -isysroot $(IOS_SDK_PATH)/iPhoneOS11.2.sdk
USE_LD_FLAG = -fuse-ld=$(IOS_TOOLCHAIN_BIN)/arm64-apple-darwin14-ld
TARGET_ARCH = -arch arm64
CGO_CFLAGS = $(IOS_SDK_FLAGS) $(TARGET_ARCH)
CGO_LDFLAGS = $(USE_LD_FLAGS) $(IOS_SDK_FLAGS) $(TARGET_ARCH)
GOOS = ios
GOARCH = arm64
GO = go1.16beta1

Ruby's Thread#raise, Thread#kill, timeout.rb, and net/protocol.rb libraries are broken

(NOTE: Due to an issue migrating my blog from one Google account to another, this URL now points at a copy of the original post. If you would like to add further comments, please do so there.)

I'm taking a break from some bug fixing to bring you this public service announcement: Ruby's Thread#raise, Thread#kill, and the timeout.rb standard library based on them are inherently broken and should not be used for any purpose. And by extension, net/protocol.rb and all the net/* libraries that use timeout.rb are also currently broken (but they can be fixed). I will explain, starting with timeout.rb. You see, timeout.rb allows you to specify that a given block of code should only run for a certain amount of time. If it runs longer, an error is raised. If it completes before the timeout, all is well. Sounds innocuous enough, right? Well, it's not. Here's the code:

def timeout(sec, exception=Error)
  return yi
#![no_std]
#![no_main]
use cortex_m_rt::entry;
use panic_halt as _;
use tomu::{prelude::*, Tomu};
#[entry]
fn main() -> ! {
let mut tomu = Tomu::take().unwrap();
require "rubygems"
require "bundler"
Bundler.require(:default)
def find_ref(body)
refs = body.split("\n").map do |line|
next unless line =~ /https:/
line.gsub(%r{.*(https://[^\s\)">]+).*}, '\1')
end
@fudanchii
fudanchii / luhn.imouto
Last active March 18, 2019 04:10
imouto language
(def-module luhn)
(use (Strings [reverse split parse])
(Funcs [map reduce_indexed])
(Funcs/Results [expect]))
(pub def-fn luhn (:: string bool) [bin]
(-<>> bin
(|> reverse)
(|> split <> "")
@fudanchii
fudanchii / dpss
Last active November 21, 2018 11:14
docker related scripts
#!/usr/bin/env bash
set -e
# change this to your seeds directory
base=$HOME/repo/quipper/seeds
startall() {
postgres.sh
mongodb.sh