<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Cheatsheet on</title><link>https://zhanghb55.github.io/docs/cheatsheet/</link><description>Recent content in Cheatsheet on</description><generator>Hugo -- gohugo.io</generator><lastBuildDate>Tue, 06 Oct 2020 08:48:23 +0000</lastBuildDate><atom:link href="https://zhanghb55.github.io/docs/cheatsheet/index.xml" rel="self" type="application/rss+xml"/><item><title>Misc</title><link>https://zhanghb55.github.io/docs/cheatsheet/misc/</link><pubDate>Thu, 12 Jan 2023 18:34:30 +0800</pubDate><guid>https://zhanghb55.github.io/docs/cheatsheet/misc/</guid><description>Bash # A nice cheatsheet: https://devhints.io/bash
Zip and unzip tar -czf abc.tar.gz files --exclude=pattern # gz -cjf # bz2 tar -xzf abc.tar.gz -C path Absolute path of current file script_dir=$(dirname $(readlink -f &amp;#34;$0&amp;#34;)) Test if variable is set # From https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash if [ -z ${var+x} ]; then echo &amp;#34;var is unset&amp;#34;; else echo &amp;#34;var is set to &amp;#39;$var&amp;#39;&amp;#34;; fi Remove artifacts mis-installed by ninja xargs rm &amp;lt; install_manifest.txt Python # Read file line by line (using walrus operator)</description></item><item><title>Git</title><link>https://zhanghb55.github.io/docs/cheatsheet/git/</link><pubDate>Thu, 04 May 2023 20:09:42 +0800</pubDate><guid>https://zhanghb55.github.io/docs/cheatsheet/git/</guid><description> Checkout a specific commit to another folder
git --work-tree=/path/to/folder checkout HEAD -- . Remove file from history
git filter-branch -f --tree-filter &amp;#39;rm -rf /path/to/file&amp;#39; HEAD Deinitialize submodule [link]
git submodule deinit -f path/to/submodule rm -rf .git/modules/path/to/submodule git rm -f path/to/submodule git checkout -- .</description></item><item><title>Cmake</title><link>https://zhanghb55.github.io/docs/cheatsheet/cmake/</link><pubDate>Sun, 26 Feb 2023 12:58:14 +0800</pubDate><guid>https://zhanghb55.github.io/docs/cheatsheet/cmake/</guid><description>Quick Start # target_include_directories(target PRIVATE ${directories}) target_link_libraries(target ${library_paths}) target_link_options(target PRIVATE LINKER:-rpath,${library_path}) Variables # Tutorial # https://cliutils.gitlab.io/modern-cmake/ Directory Variables # CMAKE_SOURCE_DIR: Top-level CMakeLists.txt file&amp;rsquo;s dir. CMAKE_CURRENT_SOURCE_DIR: This CMakeLists.txt files&amp;rsquo; dir. PROJECT_SOURCE_DIR: Most recent CMakeLists.txt file that defines a project projectName_SOURCE_DIR: Directory of the projectName For binary directories, replace SOURCE with BINARY Snippets # Iterate all targets # https://stackoverflow.com/questions/37434946/how-do-i-iterate-over-all-cmake-targets-programmatically
function(get_all_targets var) set(targets) get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR}) set(${var} ${targets} PARENT_SCOPE) endfunction() macro(get_all_targets_recursive targets dir) get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES) foreach(subdir ${subdirectories}) get_all_targets_recursive(${targets} ${subdir}) endforeach() get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS) list(APPEND ${targets} ${current_targets}) endmacro() get_all_targets(all_targets) message(&amp;#34;All targets: ${all_targets}&amp;#34;) Custom commands # https://stackoverflow.</description></item><item><title>C++</title><link>https://zhanghb55.github.io/docs/cheatsheet/cpp/</link><pubDate>Wed, 08 Feb 2023 17:42:23 +0800</pubDate><guid>https://zhanghb55.github.io/docs/cheatsheet/cpp/</guid><description>Split string # std::vector&amp;lt;std::string&amp;gt; split(const std::string &amp;amp;s, const std::string &amp;amp;delim=&amp;#34;&amp;#34;){ std::string rr = &amp;#34;\\s+&amp;#34;; if(delim != &amp;#34;&amp;#34;){ rr = delim + &amp;#34;+&amp;#34;; } std::regex ws_re(rr); // whitespace std::vector&amp;lt;std::string&amp;gt; v( std::sregex_token_iterator(str.begin(), str.end(), ws_re, -1), std::sregex_token_iterator()); return v; } Binary file IO # void readbin(const std::string &amp;amp;filename, void *buffer) { std::ifstream fin(filename, std::ios::binary); LIZ_CHECKOPEN(fin, filename); std::copy( std::istreambuf_iterator&amp;lt;char&amp;gt;(fin), std::istreambuf_iterator&amp;lt;char&amp;gt;(), (char *)buffer); fin.close(); } void readbin_another_way(const std::string &amp;amp;filename, void *buffer){ std::ifstream fin(filename, std::ios::binary); LIZ_CHECKOPEN(fin, filename); fin.</description></item><item><title>Compilation</title><link>https://zhanghb55.github.io/docs/cheatsheet/compile/</link><pubDate>Thu, 12 Jan 2023 18:34:30 +0800</pubDate><guid>https://zhanghb55.github.io/docs/cheatsheet/compile/</guid><description>GDB # Debugging LLVM OPT # # Run gdb gdb opt # Set breakpoint break llvm::Pass::preparePassManager # Run pass run -load ./mypass.so -hello &amp;lt; hello.bc &amp;gt; debug.log Clang # Clang Get IR # clang -S -emit-llvm CUDA Related # Compiling CUDA with clang: official document, in short:
clang++ helloworld.cu -o helloworld --cuda-gpu-arch=&amp;lt;arch&amp;gt; \ -L&amp;lt;CUDA install path&amp;gt;/&amp;lt;lib64 or lib&amp;gt; \ -lcudart_static -ldl -lrt -pthread Linker # GLIBCXX # Check if a string exists in the shared library</description></item></channel></rss>