Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
typing...

Tao He sighingnow

💭
typing...
View GitHub Profile
@sighingnow
sighingnow / PrintVariables.cmake
Last active Jun 5, 2022
Print all accessible variables in current context in CMake
View PrintVariables.cmake
function(print_cmake_variables)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
if (ARGV0)
unset(MATCHED)
string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
if (NOT MATCHED)
continue()
endif()
@sighingnow
sighingnow / PrintTargetProperties.cmake
Last active Jun 5, 2022
Print properties of a target in CMake
View PrintTargetProperties.cmake
# Get all propreties that cmake supports
if(NOT CMAKE_PROPERTY_LIST)
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
# Convert command output into a CMake list
string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
string(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
endif()
list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST)
@sighingnow
sighingnow / FindBrewOpenSSL.cmake
Created Oct 9, 2021
CMake: find brew-installed openssl on Mac
View FindBrewOpenSSL.cmake
macro(find_openssl_libraries)
if (APPLE)
# If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's
if (NOT OpenSSL_DIR)
find_program(HOMEBREW brew)
if (HOMEBREW STREQUAL "HOMEBREW-NOTFOUND")
message(WARNING "Homebrew not found: not using Homebrew's OpenSSL")
if (NOT OPENSSL_ROOT_DIR)
message(WARNING "Use -DOPENSSL_ROOT_DIR for non-Apple OpenSSL")
endif()
View strings 1 - Why COW is ungood for std string\strings 1 - Why COW is ungood for std string .md

Why COW was deemed ungood for std::string.

COW, short for copy on write, is a way to implement mutable strings so that creating strings and logically copying strings, is reduced to almost nothing; conceptually they become free operations like no-ops.

Basic idea: to share a data buffer among string instances, and only make a copy for a specific instance (the copy on write) when that instance's data is modified. The general cost of this is only an extra indirection for accessing the value of a string, so a COW implementation is highly desirable. And so the original C++ standard, C++98, and its correction C++03, had special support for COW implementations, and e.g. the g++ compiler's std::string implementations used COW.

So why was that support dropped in C++11?

In particular, would the same reason or reasons apply to a reference counted immutable string value class?

@sighingnow
sighingnow / rootless-container-from-scratch.rs
Last active Aug 30, 2021
Rust version of "Rootless Containers From Scratch" by Liz Rice, https://www.youtube.com/watch?v=jeTKgAEyhsA
View rootless-container-from-scratch.rs
use std;
use std::env;
use std::fs;
use std::io::Write;
use nix::mount;
use nix::sched;
use nix::sched::CloneFlags;
use nix::sys::signal::Signal;
use nix::sys::wait::waitpid;
@sighingnow
sighingnow / containers-from-scratch.rs
Created Aug 29, 2021
Rust version of "Containers From Scratch" by Liz Rice, https://www.youtube.com/watch?v=8fi7uSYlOdc
View containers-from-scratch.rs
use std::env;
use nix::sched;
use nix::sched::CloneFlags;
use nix::sys::signal::Signal;
use nix::sys::wait::waitpid;
use nix::unistd;
use cgroups_rs as cgroup;
use cgroups_rs::{Cgroup};
use cgroups_rs::cgroup_builder::{CgroupBuilder};
@sighingnow
sighingnow / list_live_objects.py
Last active Mar 16, 2021
List live objects of certain type in current Python interpreter.
View list_live_objects.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gc
def list_live_objects(ty=None):
def go(results, elements, bitset):
for elem in elements:
identity = id(elem)
@sighingnow
sighingnow / ffmpeg.md
Created Jun 30, 2019 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files
View ffmpeg.md

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@sighingnow
sighingnow / Docset for LLVM and Clang.md
Last active Mar 27, 2019
Build docset for LLVM/Clang
View Docset for LLVM and Clang.md

Build LLVM/Clang Docset

  1. Modify LLVM/Clang doxygen.config.in

    • GENERATE_DOCSET = YES
    • DISABLE_INDEX = YES
    • SEARCHENGINE = NO
    • GENERATE_TREEVIEW = NO
    • GENERATE_TAGFILE =
  • LLVM: @abs_top_builddir@/doxygen/llvm(clang).tag