Skip to content

Instantly share code, notes, and snippets.

View gyk's full-sized avatar

Yukun Guo gyk

  • Hangzhou, China
  • 22:19 (UTC +08:00)
View GitHub Profile
@gyk
gyk / random-file-name.clj
Created September 13, 2021 08:00
Generate random file name in Clojure
; Better to use test.check
(defn random-name
[]
(let [char-ranges [[\A \Z]
[\a \z]
[\0 \9]]
chars (->> char-ranges
(mapcat (fn [[from-char to-char]]
(map char (range (int from-char) (inc (int to-char))))))
(concat [\_ \space \-])
@gyk
gyk / bash-to-pwsh.md
Created July 7, 2021 09:00
Powershell equivalences of Bash commands
  • mkdir -> $null = mkdir -Force
  • cp -> cp -Force
  • tail -n $n -f $file -> Get-Content -Tail $n -Wait $file
@gyk
gyk / cargo_check.md
Created July 1, 2021 07:43
Accelerate cargo-check in VS Code

Method 1 (Better)

  • .vscode\settings.json

    {
        "rust-analyzer.checkOnSave.overrideCommand": [
            "cargo",
            "+nightly",

"check",

@gyk
gyk / config.edn
Created April 20, 2021 06:54
cljfmt config
{:remove-surrounding-whitespace? true
:remove-trailing-whitespace? true
:remove-consecutive-blank-lines? false
:insert-missing-whitespace? false
:align-associative? false
:indents {#"^:?(require|import)$" [[:block 0] [:inner 0]]
#"^\>def" [[:inner 0]] ; guardrails
#"^execute" [[:inner 0]] ; db
}}
$ ps -ef | rg swift
  501  9986     1   0  4Sep20 ??         0:00.00 (repl_swift)
  501 10019     1   0  4Sep20 ??         0:00.00 (repl_swift)
  501 12537     1   0  4Sep20 ??         0:00.00 (repl_swift)
  501 12420     1   0  4Sep20 ttys003    0:00.00 (repl_swift)
  501 13317     1   0  4Sep20 ttys006    0:00.00 (repl_swift)
  501 13466     1   0  4Sep20 ttys006    0:00.00 (repl_swift)
  501 13481     1   0  4Sep20 ttys006    0:00.00 (repl_swift)
 ...
@gyk
gyk / plots-jl-ffmpeg-deps.md
Created May 30, 2020 08:28
Plots.jl FFmpeg dependencies

Plots.jl/Makie.jl depends on FFmpeg for animation and other fancy features. Judging from the sizes of downloaded artifacts, FFmpeg is no light dependency and possibly takes a long time to install on a poor Internet connection.

 11M  artifacts/6b04ad7f71b1a29adad801f4fdd0d34b3535c638  OpenSSL_jll
1.2M  artifacts/8e4e002b058fdc78ba423fc2a8725d995c8ea9cd  libfdk_aac_jll
4.9M  artifacts/98a8bafb73ec75070d808b170e6aedbfc2ccf474  x264_jll
6.5M  artifacts/9cc8e706ab205ec16daa22d5f4a70711d5ff7885  x265_jll
792K  artifacts/e76f7afca0a2695352d27f767b750e6d997fa6d4  Bzip2_jll
@gyk
gyk / csharp.json
Last active March 10, 2020 09:32
VS Code C# snippet (~/.vscode/extensions/ms-vscode.csharp-$VERSION/snippets/csharp.json) that doesn't put a newline before the opening brace in control blocks.
{
"Attribute using recommended pattern": {
"prefix": "attribute",
"body": [
"[System.AttributeUsage(System.AttributeTargets.${1:All}, Inherited = ${2:false}, AllowMultiple = ${3:true})]",
"sealed class ${4:My}Attribute : System.Attribute",
"{",
" // See the attribute guidelines at",
" // http://go.microsoft.com/fwlink/?LinkId=85236",
" readonly string positionalString;",
@gyk
gyk / README.md
Created July 5, 2019 08:12
Decoded source

Decipher the stupid code posted by this script kiddie on Hacker News (his posts have been downvoted badly).

@gyk
gyk / mp4.c
Created April 15, 2019 09:23
VLC MP4_GetInterleaving, annotated source code
/* Analyzes chunks to find max interleave length
* sets flat flag if no interleaving is in use */
static void MP4_GetInterleaving( demux_t *p_demux, vlc_tick_t *pi_max_contiguous, bool *pb_flat )
{
demux_sys_t *p_sys = p_demux->p_sys;
*pi_max_contiguous = 0;
*pb_flat = true;
/* Find first recorded chunk */
mp4_track_t *tk = NULL;
z = a x + b y + c x y + d
x = 0, z = 1 => b y + d === 1
x = 1, z = y => a + b y + c y + d === y
b y + d === 1 => b == 0, d == 1
a + c y === y - 1 => c == 1, a = -1 => z = -x + x y + 1 => z = 1 + x * (y - 1)