Skip to content

Instantly share code, notes, and snippets.

View gwy15's full-sized avatar

gwy15 gwy15

  • Bytedance
View GitHub Profile
@gwy15
gwy15 / hdr-converter
Last active March 1, 2024 08:20
swift script that converts adobe generated HDR avifs compatible with iOS and mac devices
@gwy15
gwy15 / chained-cow.rs
Created November 6, 2023 11:21
Rust Cow chained map, avoids extra allocations. Useful for chained regex::replace
use std::borrow::Cow;
use regex::Regex;
lazy_static::lazy_static! {
static ref R1: Regex = Regex::new("(a)").unwrap();
static ref R2: Regex = Regex::new("(b)").unwrap();
static ref R3: Regex = Regex::new("(c)").unwrap();
}
@gwy15
gwy15 / skip-reader.rs
Created April 4, 2023 09:25
A skippable reader wrapper for Rust
pub struct SkipReader<R> {
inner: R,
skip: usize,
skipped: bool,
}
impl<R> SkipReader<R> {
pub fn new(reader: R, skip: usize) -> Self {
Self {
inner: reader,
skip,
use std::{
marker::PhantomData,
ops::{Deref, DerefMut},
};
const EXTRA_MASK: u64 = 0xFFFF_0000_0000_0000;
const POINTER_MASK: u64 = 0x0000_FFFF_FFFF_FFFF;
pub struct Pointer<T> {
ptr: *mut (),
_marker: PhantomData<T>,
#![feature(test)]
extern crate test;
use rand::prelude::*;
use std::{io::Error, panic::catch_unwind};
use test::Bencher;
fn main() {}
const TARGET: i32 = 30;
#!/bin/bash
sudo apt update
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce
fn close_test4() {
let string_postfix = "456";
let closure = move |mut s: String| {
s.push_str(string_postfix);
s
};
let mut vec_of_closures = Vec::new();
// vec_of_closures.push(closure);
push_closure_to_vec(closure, &mut vec_of_closures);
fn find_collatz(number: u64, cache: &mut Vec<i32>) -> i32 {
let n = cache.len() as u64;
let index = number as usize;
if number < n && cache[index] != 0 {
// cache hit
cache[index]
} else {
// cache miss
let result = match number {
import gzip as compressLib
import json
import hashlib
import asyncio
from pathlib import Path
import dataclasses
import requests
import aiohttp
import async_pool
{
"callback":"http://localhost:11913/weibo"
}