Skip to content

Instantly share code, notes, and snippets.

@heeh
heeh / rust-ios-build-with-cbindgen.md
Created December 5, 2025 15:25
[rust] ios build with cbindgen

Here’s a minimal, App Store–ready Rust → iOS dynamic framework setup, including the folder structure, header generation, shell build script, and framework layout. This is exactly how an industry team would structure a small Rust library for iOS.


1. Folder Structure

my_rust_lib/
├── Cargo.toml
├── cbindgen.toml
@heeh
heeh / pre-build-final.md
Last active December 5, 2025 15:11
Rust pre-build Check 251205

Here’s a fully working minimal Rust workspace ready to drop in CI, with cargo_enforce.sh, Clippy, audit, deny, build, and test rules all passing.


Directory Layout

rust_workspace/
 ├─ Cargo.toml
 ├─ rust-toolchain.toml
@heeh
heeh / pre-build-strict.bash
Created December 5, 2025 14:42
Rust pre-build Check (Strict)
#!/usr/bin/env bash
set -euo pipefail
echo "=== Enforced Rust Repo Checks ==="
# Require tools
required_tools=(
"cargo"
"cargo fmt"
"cargo clippy"
@heeh
heeh / pre-build.bash
Created December 5, 2025 14:39
Rust pre-build Checks
echo "=== Running Rust pre-build checks ==="
# 1. Format check
echo "[1/5] Checking formatting (cargo fmt)"
cargo fmt --all -- --check
# 2. Lints (Clippy)
echo "[2/5] Running Clippy with warnings as errors"
cargo clippy --all-targets --all-features -- -D warnings
(defun compileandrun()
(interactive)
(let* ((src (file-name-nondirectory (buffer-file-name)))
(exe (file-name-sans-extension src)))
(compile (concat "g++ -std=c++11 -Wshadow -Wall " src " -o " exe " -O2 -Wno-unused-result && ./" exe))))
@heeh
heeh / hamming_weight.rs
Last active June 5, 2021 15:24
Hamming Weight
fn countOnes(x: usize) -> usize {
let mut c = 0;
let mut x = x;
c = (x & 0x55555555) + ((x >> 1) & 0x55555555);
c = (c & 0x33333333) + ((c >> 2) & 0x33333333);
c = (c & 0x0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f);
c = (c & 0x00ff00ff) + ((c >> 8) & 0x00ff00ff);
c = (c & 0x0000ffff) + ((c >> 16) & 0x0000ffff);
return c;
}
@heeh
heeh / batch_predict.sh
Last active November 16, 2020 02:29
GNU Parallel Example
#!/bin/bash
if [ ! -d "targets" ]; then
mkdir targets
fi
if [ ! -d "frames" ]; then
mkdir frames
fi
word2target() {
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(setq pkgs
'(company
ido-vertical-mode
impatient-mode
use-package
@heeh
heeh / surfraw
Created May 4, 2020 02:25
This script enables surfraw to open chrome without address bar
#!/bin/sh
# Surfraw -- Shell Users' Revolutionary Front Against the World wide web
#
# Copyright (c) 2003-2018 The Surfraw-Devel Team
# <[email protected]>
# Copyright (c) 2000-2001 Julian Assange, placed into the public domain
# Copyright (c) 2000 Melbourne Institute for Advanced Study, placed into the public domain
#
# see the file COPYING for further copyright details
#