Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
insaneyilin / ollama_object_detect.py
Created March 16, 2026 18:32
ollama_detect_object_in_image
#!/usr/bin/env python3
"""
Object detection using Ollama vision models.
Usage: python ollama_object_detect.py <input_image_file_path> <object_text> <output_dir>
Arguments:
- input_image_file_path: Path to the input image file
- object_text: Object category description to detect (e.g., "dog", "cat")
- output_dir: Output directory where detection results will be saved
@insaneyilin
insaneyilin / get_last_valid_pos_indices.py
Created October 11, 2025 05:17
Get the last valid position indices for each sequence sample
def get_last_valid_indices(valid_mask):
"""Get the last valid indices for each sample.
Args:
valid_mask (torch.Tensor): [B, seq_len], True if valid
Returns:
torch.Tensor: [B,], Last valid indices for each sample.
"""
# 反转mask
@insaneyilin
insaneyilin / img_steganography.py
Created June 16, 2025 18:33
image steganography
import argparse
from PIL import Image
def embed_message(image_path, message, output_path):
org_img = Image.open(image_path)
org_pixelMap = org_img.load()
enc_img = Image.new(org_img.mode, org_img.size)
enc_pixelsMap = enc_img.load()
#!/bin/bash
# Check number of arguments
if [ $# -ne 3 ]; then
echo "Usage: $0 <file1> <file2> <output_file>"
echo "Example: $0 file1.txt file2.txt differences.txt"
exit 1
fi
# Get command line arguments
@insaneyilin
insaneyilin / ffmpeg_mp4_to_gif.sh
Created July 12, 2024 16:09
ffmpeg_mp4_to_gif.sh
ffmpeg -ss 0 -t 3 -i input.mp4 \
-vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop 0 output.gif
@insaneyilin
insaneyilin / .gdbinit
Created November 10, 2023 14:25 — forked from guodongxiaren/.gdbinit
GDB coredump调试美化输出
# 保存到 ~/.gdbinit
python
import sys
sys.path.insert(0, '/usr/share/gcc-4.8.2/python') # 这个路径以实际情况为准
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
#
# STL GDB evaluators/views/utilities - 1.03
@insaneyilin
insaneyilin / torch_repeat_interleave_alternative.py
Created June 21, 2023 06:33
torch.repeat_interleave alternative
def tile_along_axis(x, dim, n_tile):
init_dim = x.size(dim)
repeat_idx = [1] * x.dim()
repeat_idx[dim] = n_tile
x = x.repeat(*(repeat_idx))
order_index = torch.tensor(
torch.cat([init_dim * torch.arange(n_tile, device=x.device) + i for i in range(init_dim)]),
dtype=torch.long, device=x.device)
return torch.index_select(x, dim, order_index)
@insaneyilin
insaneyilin / xdotool_click.sh
Created June 20, 2023 04:34
mouse click repeatedly
#!/bin/bash
while true
do
x=`xdotool getmouselocation | grep -oP '(?<=x:)\d+'`
y=`xdotool getmouselocation | grep -oP '(?<=y:)\d+'`
xdotool mousemove $x $y
xdotool click 1
sleep 1
done
@insaneyilin
insaneyilin / sort_by_another_vector.cc
Created June 15, 2023 02:16
c++ sort one vector based on another
vector <string> Names {"Karl", "Martin", "Paul", "Jennie"};
vector <int> Score{45, 5, 14, 24};
std::vector<int> indices(Names.size());
std::iota(indices.begin(), indices.end(), 0);
std::sort(indices.begin(), indices.end(),
[&](int A, int B) -> bool {
return Score[A] < Score[B];
});
@insaneyilin
insaneyilin / chamfer_dist.py
Created February 15, 2023 13:02
chamfer distance
import numpy as np
from scipy.spatial import KDTree
def chamfer_distance(s1, s2, direction='s2_to_s1'):
"""Chamfer distance between two point sets.
Args:
s1 (np.ndarray): [n_points_s1, n_dims]
s2 (np.ndarray): [n_points_s2, n_dims]