Skip to content

Instantly share code, notes, and snippets.

@windoze
windoze / hide_env_in_ps1.sh
Created July 17, 2024 06:46
Disable Conda active env in shell prompt, could be useful when you're using other tool to show env name, e.g. starship
conda config --set changeps1 false
@windoze
windoze / console_holder.rs
Last active July 13, 2024 14:02
Access console when a GUI program starts from console.
/// Attach console from parent process and hold it until being dropped.
/// Used to access console in Windows GUI application when it's started from console.
/// Does nothing if it's started from GUI because `AttachConsole` will fail.
/// ```no_run
/// // Add this line at the beginning to suppress console window
/// #![windows_subsystem = "windows"]
/// // ...
/// fn main() {
/// // Attach console from parent process, if any
/// let c = ConsoleHolder::new();
@windoze
windoze / fstab
Created May 4, 2024 17:34
Share `.ssh` between windows and wsl2
# `.ssh` must not be readable or writable by others
# Run `apt install bindfs` first
/mnt/c/Users/UserName/.ssh /home/wsluser/.ssh fuse.bindfs defaults,force-user=wsluser,perms=0000:u+rwD 0 0
@windoze
windoze / musl.sh
Created December 5, 2023 21:18
Rust musl cross compile script
#!/bin/bash
# Usage:
# /path/to/musl.sh some-rust-target-name cargo subcommand --options ...
# E.g. musl.sh aarch64-linux-unknown-musl cargo build --release
#
# Note:
# Linking C++ libs doesn't work, as we don't have musl version of C++ std libs
TARGET=$1
@windoze
windoze / dsl_gen_test.py
Created November 26, 2022 05:05
DSL generator test
from feathr import AvroJsonSchema
from feathr import KafKaSource
from feathr import KafkaConfig
from typing import List
import os
import random
from datetime import datetime, timedelta
from feathr import (BOOLEAN, FLOAT, INPUT_CONTEXT, INT32, STRING,
DerivedFeature, Feature, FeatureAnchor, HdfsSource,
@windoze
windoze / dsl_generator.py
Created November 26, 2022 05:04
DSL generator for transformer
import re
from enum import Enum
from typing import List
from feathr.definition.feature import Feature
from feathr.definition.feature_derivations import DerivedFeature
from feathr.definition.transformation import ExpressionTransformation, WindowAggTransformation
class Token:
def __init__(self, name, value):
@windoze
windoze / musl-cargo-macos.sh
Created January 1, 2022 10:17
Cross build rust on macOS
#!/bin/sh
export DOCKER_HOST="YOUR_DOCKER_ENDPOINT:2375"
docker volume create data-volume
docker run -d -v data-volume:/data --name helper ubuntu sleep 1000000
tar --exclude=./target -c -v -f - . | docker exec -i helper bash -c 'tar -x -v --strip-components 1 -f - -C /data'
docker kill helper
docker rm helper
docker run -v data-volume:/home/rust/src --name cargo messense/rust-musl-cross:x86_64-musl cargo "$@"
# Support lib for RobotBit from [KittenBot](https://www.kittenbot.cn/), works on Micro:bit and Adafruit CLUE
import busio
import neopixel
import pulseio
from adafruit_motor import servo, motor, stepper
from adafruit_pca9685 import PCA9685
from board import SCL, SDA, P0, P16
class RobotBit:
@windoze
windoze / install-dropbox.sh
Last active March 13, 2021 02:30
Install Dropbox on Headless Ubuntu 20.04
#!/bin/sh
sudo apt install -y libxdamage1 libxcb-glx0 libglapi-mesa libxcb-dri2-0 libxcb-dri3-0 libxcb-present0 libxcb-sync1 libxshmfence1 libxxf86vm1 libxfixes3
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
wget -O ~/bin/dropbox.py 'https://www.dropbox.com/download?dl=packages/dropbox.py'
chmod +x ~/bin/dropbox.py
~/.dropbox-dist/dropboxd
# ~/bin/dropbox.py autostart
@windoze
windoze / randstr.py
Created February 6, 2020 08:40
Generate random string
#!/usr/bin/python3
import string
import random
import itertools
import argparse
IDENT_FIRST = string.ascii_letters + '_'
IDENT_LAST = string.ascii_letters + string.digits + '_'