Skip to content

Instantly share code, notes, and snippets.

@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
View cpp-tricks.md

Tricks in Modern C++

is_specialization_of

Whether the type is a specialization of template T.

template <template <typename...> class T, typename U>
@sighingnow
sighingnow / bench-enum.hs
Created May 3, 2018
Benchmark on several implementations of `numericEnumFromThen` and `numericEnumFromThenTo`.
View bench-enum.hs
{-# 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 Apr 26, 2018
ghc treat certain kinds of warnings as errors when compile c source file.
View error-message
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 Dec 31, 2017 — forked from gyglim/tensorboard_logging.py
Logging to tensorboard with manually generated summaries (not relying on summary ops)
View tensorboard_logging.py
"""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 Jan 2, 2017
concatMap and filter using Foldable and Traversable.
View misc.hs
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)
@sighingnow
sighingnow / Makefile
Last active Dec 27, 2016
Expose C++ API to Haskell via FFI.
View Makefile
all: libacpp.dll app.exe
GHC := stack ghc --
%.o: %.cpp
$(CXX) -c $< -o $@
libacpp.dll: acpp.o acpp_capi.o
$(CXX) $^ -shared -o $@ # On Linux/Unix, -fPIC is needed.
@sighingnow
sighingnow / T.hs
Created Dec 27, 2016
Haskell's $ operator for types.
View T.hs
{-# LANGUAGE TypeOperators #-}
module T where
-- | Infix application.
--
-- @
-- f :: IO $ Maybe Int
-- =