use std::{ffi::c_void, marker::PhantomData};
struct CBProxy<F, Sig>(PhantomData<(F, Sig)>);
impl<F, A1, A2, R> CBProxy<F, fn(A1, A2) -> R>
where
F: FnMut(A1, A2) -> R,
{
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use smoltcp::wire::{IpProtocol, Ipv4Packet, Ipv6Packet}; | |
| fn extract_udp_packet(packet: &[u8]) -> Result<UdpPacket, Box<dyn std::error::Error>> { | |
| if let Ok(ipv4_packet) = Ipv4Packet::new_checked(packet) { | |
| let src_addr = ipv4_packet.src_addr(); | |
| let dst_addr = ipv4_packet.dst_addr(); | |
| let protocol = ipv4_packet.next_header(); | |
| let payload = ipv4_packet.payload(); | |
| if protocol == IpProtocol::Udp { | |
| let udp_packet = smoltcp::wire::UdpPacket::new_checked(payload)?; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getinterfaceinfo#examples | |
| // | |
| // [target.'cfg(target_os="windows")'.dependencies] | |
| // windows = { version = "0.51", features = [ | |
| // "Win32_NetworkManagement_IpHelper", | |
| // "Win32_NetworkManagement_Ndis", | |
| // "Win32_Networking_WinSock", | |
| // "Win32_Foundation", | |
| // ] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // [dependencies] | |
| // mio = { version = "0.8", features = ["net", "os-ext", "os-poll"] } | |
| use mio::{ | |
| event::Event, | |
| net::{TcpListener, TcpStream}, | |
| Events, Interest, Poll, Token, | |
| }; | |
| use std::{cell::RefCell, collections::HashMap, io::Read, net::SocketAddr, rc::Rc}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| [dependencies] | |
| as-any = "0.3" | |
| erased-serde = "0.3" | |
| rustfmt = "0.10" | |
| serde = { version = "1", features = ["derive"] } | |
| serde_json = { version = "1" } | |
| uuid = { version = "1.2", features = ["v4", "serde"] } | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::sync::atomic::{AtomicBool, Ordering}; | |
| use tokio::{ | |
| signal::ctrl_c, | |
| sync::mpsc::{channel, Sender}, | |
| task::spawn, | |
| }; | |
| static STOP_FLAG: AtomicBool = AtomicBool::new(false); | |
| // worker function to be executed in a separate thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/bash | |
| # Please set the following parameters according to your environment | |
| BYPASS_IP=123.45.67.89 | |
| PROXY_IP=127.0.0.1 | |
| PROXY_PORT=1080 | |
| PROXY_TYPE=SOCKS5 | |
| # check if user is root | |
| function is_root() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| sudo dd if=/dev/zero of=/opt/swap bs=1024 count=2048000 | |
| sudo chmod 600 /opt/swap # ×¢Òâ¸ü¸Ä swap ÎļþµÄȨÏÞ | |
| sudo mkswap /opt/swap | |
| sudo swapon /opt/swap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{cmp::Ordering, result::Result}; | |
| /// find first index where arr[idx] >= v; assume arr is sorted | |
| pub trait LowerBound { | |
| type Item; | |
| fn lower_bound(&self, x: &Self::Item) -> Result<usize, usize>; | |
| } | |
| /// find first index where arr[idx] > v; assume arr is sorted | |
| trait UpperBound { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 最小紙幣找零算法 | |
| // 1. 用最大的紙幣找零 | |
| // 2. 用次大的紙幣找零 | |
| fn coin_change(coins: Vec<i32>, amount: i32) -> i32 { | |
| let mut coins = coins.iter().map(|&x| x as usize).collect::<Vec<_>>(); | |
| coins.sort(); | |
| let amount = amount as usize; | |
| let mut dp = vec![amount + 1; amount + 1]; | |
| dp[0] = 0; |