Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / delayqueue.cpp
Last active July 29, 2023 14:59
C++ delay queue - unbound blocking queue with delay of element deque (like Java's java.util.concurrent.DelayQueue)
// delayqueue.cpp -- C++ delay queue
// Copyright (c) 2018 yohhoy
//
// Boost Software License, Version 1.0
// https://www.boost.org/LICENSE_1_0.txt
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <utility>
#include <vector>
@yohhoy
yohhoy / ffmpeg_tb.md
Last active April 10, 2023 07:36
time-base in FFmpeg

https://www.ffmpeg.org/doxygen/trunk/dump_8c_source.html#l00454

  • fps = st->avg_frame_rate
  • tbr = st->r_frame_rate
  • tbn = st->time_base
  • tbc = st->codec->time_base

AVStream::avg_frame_rate

Average framerate.

  • demuxing: May be set by libavformat when creating the stream or in avformat_find_stream_info().
  • muxing: May be set by the caller before avformat_write_header().
@yohhoy
yohhoy / mdspan-test.cpp
Created March 4, 2023 14:38
mdspan constructors & deduction guides
#include <cassert>
#include <array>
#include <span>
#if 1
#include <https://raw.githubusercontent.com/kokkos/mdspan/single-header/mdspan.hpp>
using namespace std::experimental;
#else
#include <mdspan>
using namespace std;
#endif
@yohhoy
yohhoy / mm.c
Last active September 22, 2022 04:44
// https://groups.google.com/g/golang-nuts/c/Gze1TRtdLdc/m/RoD2AxssDgAJ
// http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/
int main() {
int x = 0;
atomic_int int y = 0;
{{{ { x = 1;
y.store(1);
x = 1;
y.store(1); }
||| { y.load().readsvalue(0);

Full barrier

P: =p0=\ /----\ /=p1=\ /----\ /=
        *      *      *      *
C: ----/ \=c0=/ \----/ \=c1=/ \-

Half barrier

P: p0=\--------/=p1=\--------/=
@yohhoy
yohhoy / oledd.c
Created July 5, 2012 12:17
OLE Drag & Drop sample code
/*
* OLE Drag and Drop module
*
* Copyright(c) 2001 yoh(yohhoy)
*/
#define STRICT
#define NONAMELESSUNION
#define COBJMACROS
#include <windows.h>
#include "oledd.h"
@yohhoy
yohhoy / vlafib.c
Last active July 5, 2022 10:27
Fibonacci with VLA on C99
#include <stdio.h>
size_t f(size_t, char [][*]);
size_t f(size_t n, char r[][2 < n ? f(n-2, 0) + f(n-1, 0) : 1])
{
return sizeof(*r);
}
int main()
@yohhoy
yohhoy / aac_parser.py
Last active May 22, 2022 21:43
Parse AAC/ADTS header
#!/usr/bin/env python3
import sys
import struct
if len(sys.argv) < 2:
print("Usage: aac_parer.py <target.aac>")
exit()
aacfile = open(sys.argv[1], 'rb')
frame_no = 1
@yohhoy
yohhoy / chrono_io.hpp
Last active December 15, 2021 04:38
Ad-hoc std::ostream support for <chrono>
#include <ctime>
#include <chrono>
#include <iostream>
#include <iomanip>
namespace std {
// https://timsong-cpp.github.io/cppwp/n4868/time.cal.ymd.nonmembers#14
// "yyyy-mm-dd"
inline ostream& operator<<(ostream& os, const chrono::year_month_day& ymd) {
@yohhoy
yohhoy / takumi-nick.go
Last active October 28, 2021 13:47
Nickname generator for TAKUMI
//
// Nickname generator for TAKUMI
//
package main
import (
"bufio"
"fmt"
"math/rand"
"net/http"