Skip to content

Instantly share code, notes, and snippets.

View docker-htop.sh
#!/bin/bash
docker() {
case "$1" in
htop)
local container="$2"
if [ -z "$container" ]; then
echo -e '"docker htop" requires at least 1 argument.\n'
echo -e 'Usage:\n\tdocker htop CONTAINER [htop OPTIONS]'
return 1
View push_array.rs
// date: 2022-05-09
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
// author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
use std::mem::take;
fn push(buf: &mut &mut [u8], value: u8) {
buf[0] = value;
*buf = &mut take(buf)[1..];
}
@nanpuyue
nanpuyue / .gitignore
Last active Apr 30, 2022
executable-cdylib
View .gitignore
/target
Cargo.lock
View deserialize-colon-separated.rs
// date: 2022-04-24
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
// author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
use std::fmt::{self, Debug, Display, Formatter};
use std::iter::Peekable;
use std::str::Lines;
use std::{error, result};
use serde::de::{self, Visitor};
View gist:2798c214a97b0c017074e26ca24e59ad
use std::marker::PhantomData;
#[derive(Debug)]
struct S<'a> {
_pd: PhantomData<&'a mut &'a ()>
}
impl<'a> Drop for S<'a> { fn drop(&mut self) {} }
impl<'a> S<'a> {
View gist:df0b0c0386b8934d30af1b3d5b03b4a0
struct S<'a> {
a: &'a (),
}
impl<'a> S<'a> {
fn feed(&self, data: &'a [u8]) {
drop(data);
}
fn get_a(&self) -> &() {
View biliintl.js
let url = $request.url;
let body = $request.body;
url = url.replace(/&sim_code=[0-9]+/g,'');
body = body.replace(/&sim_code=[0-9]+/g,'');
$done({url, body});
View tcp-rdhup.c
// date: 2020-07-06
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
// author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/epoll.h>
View sha2_constants.rs
// date: 2020-01-10
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
// author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
#![feature(generators)]
#![feature(generator_trait)]
use std::ops::{Generator, GeneratorState};
use std::pin::Pin;
View prime_generator.rs
// date: 2019-01-10
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
// author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
#![feature(generators)]
#![feature(generator_trait)]
use std::ops::{Generator, GeneratorState};
use std::pin::Pin;