Skip to content

Instantly share code, notes, and snippets.

@zhangzhhz
zhangzhhz / caret-and-tilde-in-git.md
Last active November 21, 2024 16:49
caret (^) and tilde (~) in Git

Both ^ and ~ themselves mean the parent.

~ followed by a number works the same as putting the same number of ~. For example, my_commit~3 is the same as my_commit~~~ which refers to the 3rd parent of my_commit.

But ^2 only makes sense for a merge commit, i.e., merge_commit^2 means the second parent of the merge_commit, merge_commit^1 is the same as merge_commit^ or merge_commit~ or merge_commit~1.

On the other hand, repetitive ^ is the same as repetitive ~. For example, ~~~ is the same as ^^^, and the same as ~3.

Some examples:

@zhangzhhz
zhangzhhz / print_chars_randomly_1.py
Last active July 9, 2022 19:19
Print all English alphabets in order but at random positions on one line
#!/usr/bin/env python3
from string import ascii_lowercase, ascii_uppercase
from random import shuffle
from time import sleep
for letters in [ascii_lowercase, ascii_uppercase]:
l = list(range(26))
shuffle(l)
c_list = [" "] * 26
@zhangzhhz
zhangzhhz / print_chars_randomly_2.py
Last active July 9, 2022 19:21
Print all English alphabets randomly but in order on one line
#!/usr/bin/env python3
from string import ascii_lowercase, ascii_uppercase
from random import shuffle
from time import sleep
for letters in [ascii_lowercase, ascii_uppercase]:
l = list(range(26))
shuffle(l)
c_list = [" "] * 26
@zhangzhhz
zhangzhhz / dump_table.lua
Last active February 11, 2023 16:39
Dump a Lua table
#!/usr/bin/env lua
t = { a = 1, b = 2, h = "hello", x = { m = 1, n = "hello world" }, 3,
y = { "y", z = "hello there", aa = { a1 = 1, a2 = 2, x = "xyz" } },
bool = { b1 = true, b2 = false, [true] = true, [false] = false },
[100] = "one hundred", ["hello world"] = 100, f = function() return "Returned from a function" end }
function dump(t, indentLevel)
local indentLevel = indentLevel or 1
local str = "{\n"
@zhangzhhz
zhangzhhz / create_data_file_filled_with_0x00.md
Last active November 25, 2023 15:33
create a binary file of 50MB size, all 0x00

python

with open("50M.dat", "wb") as outfile:
    outfile.write(b'\x00' * 50 * 1024 * 1024)
    # outfile.write(bytes(50 * 1024 * 1024))

go

package main