Skip to content

Instantly share code, notes, and snippets.

@shifujun
shifujun / thinking-about-mut-in-rust.md
Created June 12, 2022 09:52
A brain-burning question about 'mut' keyword in learning Rust

When I learn Rust's mut keyword and references types, everything seemed logical. Basicly without mut decleared, any member of a struct cannot change.

Until I read to this: https://doc.rust-lang.org/rust-by-example/fn/closures/capture.html

    let mut count = 0;
    // A closure to increment `count` could take either `&mut count` or `count`
    // but `&mut count` is less restrictive so it takes that. Immediately
    // borrows `count`.
 //
@shifujun
shifujun / foo.main.kts
Created February 10, 2022 09:06
a kotlin script use ktor client and shell command
#!/usr/bin/env kotlin
@file:Repository("https://mirrors.tencent.com/nexus/repository/maven-public/")
@file:DependsOn("io.ktor:ktor-client-core-jvm:1.6.7")
@file:DependsOn("io.ktor:ktor-client-cio-jvm:1.6.7")
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.features.*
import io.ktor.client.request.*
@shifujun
shifujun / vendor-repo-demo.sh
Created May 19, 2021 06:23
make a vendor repo with shallow clone
#!/usr/bin/env sh
cd $(mktemp -d)
echo "\n\n"
echo Step1: use temp dir: $(pwd)
echo "\n\n"
echo Step2: init main-repo
(
mkdir main-repo
@shifujun
shifujun / note.md
Created March 25, 2021 06:35
Background run command and interval check it until finished
sleep 1000 & export job=$! && until ! ps -p $job > /dev/null; do echo running && sleep 2; done && wait $job

explanation:

  • sleep 1000: a long time no output command.
  • &: put command background.
  • export job=$!: $! is pid of command.
  • ! ps -p $job > /dev/null: if command has finished.
  • echo running && sleep 2: every 2 seconds, output running.