Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sighingnow's full-sized avatar
💭
typing...

Tao He sighingnow

💭
typing...
View GitHub Profile
@sighingnow
sighingnow / rootless-container-from-scratch.rs
Last active August 30, 2021 01:59
Rust version of "Rootless Containers From Scratch" by Liz Rice, https://www.youtube.com/watch?v=jeTKgAEyhsA
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 August 29, 2021 08:38
Rust version of "Containers From Scratch" by Liz Rice, https://www.youtube.com/watch?v=8fi7uSYlOdc
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 March 16, 2021 06:41
List live objects of certain type in current Python interpreter.
#!/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 June 30, 2019 02:31 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

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 March 27, 2019 09:38
Build docset for LLVM/Clang

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
@sighingnow
sighingnow / cpp-tricks.md
Last active February 26, 2024 12:03
C++ Tricks.

Tricks in Modern C++

is_specialization_of

Whether the type is a specialization of template T.

template  class T, typename U>
@sighingnow
sighingnow / bench-enum.hs
Created May 3, 2018 05:29
Benchmark on several implementations of `numericEnumFromThen` and `numericEnumFromThenTo`.
{-# LANGUAGE BangPatterns #-}
import Criterion.Main
import Weigh
numericEnumFromThen :: (Fractional a) => a -> a -> [a]
numericEnumFromThen n m = n `seq` m `seq` (n : numericEnumFromThen m (m+m-n))
numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a]
numericEnumFromThenTo e1 e2 e3
@sighingnow
sighingnow / error-message
Created April 26, 2018 14:06
ghc treat certain kinds of warnings as errors when compile c source file.
D:\Open>gcc test.c -Wall -c
test.c: In function 'g':
test.c:8:14: warning: passing argument 1 of 'f' from incompatible pointer type [-Wincompatible-pointer-types]
return f(cp);
^~
test.c:1:5: note: expected 'int *' but argument is of type 'char *'
int f(int *a) {
^
D:\Open>stack exec -- ghc -c test.c -Wall
@sighingnow
sighingnow / tensorboard_logging.py
Last active December 31, 2017 11:18 — forked from gyglim/tensorboard_logging.py
Logging to tensorboard with manually generated summaries (not relying on summary ops)
"""Simple example on how to log scalars and images to tensorboard without tensor ops.
License: Copyleft
"""
__author__ = "Michael Gygli, Tao He"
import tensorflow as tf
try:
from StringIO import StringIO
except:
@sighingnow
sighingnow / misc.hs
Created January 2, 2017 13:23
concatMap and filter using Foldable and Traversable.
concatMap :: (Foldable f, Monoid (f b)) => (a -> f b) -> f a -> f b
concatMap = foldMap
filter :: (Applicative f, Foldable f, Monoid (f a)) =>
(a -> Bool) -> f a -> f a
filter p = foldMap (\a -> if p a then pure a else mempty)