Skip to content

Instantly share code, notes, and snippets.

View cmpute's full-sized avatar
🏠
Working from home

Jacob Zhong cmpute

🏠
Working from home
View GitHub Profile
@cmpute
cmpute / create_bench2drive_videos.py
Created May 9, 2024 03:44
Generate videos for Bench2Drive data
import os, tarfile
from subprocess import check_call, DEVNULL
from tempfile import mkdtemp, TemporaryDirectory
def create_video(tar_path, out_path):
with TemporaryDirectory() as tmpd:
print("Reading tar:", os.path.basename(tar_path))
tar = tarfile.open(tar_path, "r:gz")
tar_members = tar.getmembers()
front_camera_imgs = [member for member in tar_members if member.name.split('/')[-2] == "rgb_front"]
@cmpute
cmpute / free_collector.py
Last active June 5, 2024 05:22
Data collector in Carla with autopilot ego and random generated vehicle and walkers
#!/usr/bin/env python
"""This script is modified from PythonAPI/examples/generate_traffic.py and PythonAPI/examples/automatic_control.py"""
from __future__ import print_function
import argparse
import collections
import datetime
import glob
@cmpute
cmpute / dedup.py
Created October 26, 2023 09:38
File deduplication
import sys, os, binascii
from imohash import hashfile
from pathlib import Path
from tqdm import tqdm
from collections import defaultdict
from time import time
from hashlib import md5
USE_HASH = True
@cmpute
cmpute / pm1.py
Last active April 2, 2023 14:55
Get PM1 and PP1 tasks from GIMPS
import argparse
from pathlib import Path
FACTOR_PATH = "progress_factor.csv"
MORE_FACTOR_PATH = "more_factors.csv"
def expect_b1(exp, mem):
# https://www.mersenneforum.org/showthread.php?t=27477
import math
base = 2.2**math.log2(20000000/exp)*1000000
@cmpute
cmpute / carla-prerequisite.dockerfile
Created February 8, 2023 00:58
Docker file to build Carla with ssh key
FROM ubuntu:18.04
USER root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update ; \
apt-get install -y wget software-properties-common && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - && \
apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main" && \
@cmpute
cmpute / rustdoc_index.md
Last active December 17, 2022 05:08
Proposal for rustdoc index

Index Design of the Rustdoc

  • This index section is only available for structs yet.
  • The whole index should be put under the type documentation of a struct in the documentation body, and collapsed by default.
  • Auto and blanket trait implementations are not separated from normal traits.
  • The pub modifier is omitted by default, maybe we can display it when --private-items flag is enabled.
  • Trait bounds for generic parameters are omitted
  • The type for const generic parameters are omitted.
  • Each table is not necessarily rendered as tables in HTML, they can be rendered like the summary of a module, and the headers are not necessary as well.
  • We might also add a button on the top right (beside the [+] button) for jumping to the index, in case the type documentation is too long.
@cmpute
cmpute / bag2video.py
Created October 29, 2022 19:19
Extract the images in a rosbag as a video
#!/usr/bin/env python3
import os
import rosbag
from cv2 import VideoWriter, VideoWriter_fourcc
from cv_bridge import CvBridge
import argparse
class RosbagVideoReader:
def __init__(self, args) -> None:
@cmpute
cmpute / shrink.bat
Created August 13, 2022 07:20
Shrink WSL2 virtual hard drive
wsl --shutdown
diskpart :: opening a separate window
select vdisk file="C:\Users\{user}\AppData\Local\Packages\…\ext4.vhdx"
attach vdisk readonly :: this step is necessary to prevent process conflict
compact vdisk
detach vdisk
exit
@cmpute
cmpute / lgcd.py
Created June 11, 2022 05:30
Python implementation of (extended) Lehmer's GCD algorithm
import math, random
def lgcd(x, y):
if x < y:
return lgcd(y, x)
shift = max(x.bit_length() // 64, y.bit_length() // 64)
xbar = x >> (shift * 64)
ybar = y >> (shift * 64)
while y > 2**64:
@cmpute
cmpute / gcd.rs
Last active May 10, 2022 20:19
Rust benchmark of Binary GCD algorithms
//! Benchmarking GCD algorithms on primitive integers
//!
//! Time consumption with my test (on a 64bit system):
//! u32 : gcd_bin < gcd_bin_bfree < gcd_bin_compact < gcd_euclid; gcd_euclid_ext < gcd_bin_ext;
//! u64 : gcd_bin_compact < gcd_bin_bfree < gcd_bin < gcd_euclid; gcd_euclid_ext < gcd_bin_ext;
//! u128: gcd_bin_compact < gcd_bin_bfree < gcd_bin < gcd_euclid; gcd_euclid_ext < gcd_bin_ext;
#[macro_use]
extern crate criterion;
use criterion::Criterion;