Skip to content

Instantly share code, notes, and snippets.

View alexanderchuranov's full-sized avatar

Alexander Churanov alexanderchuranov

View GitHub Profile
@alexanderchuranov
alexanderchuranov / container-view.cc
Created July 10, 2024 01:38
The container/view in C++20
#include <cassert>
#include <string>
#include <type_traits>
#include <utility>
template <typename T>
class View {
public:
View() = default;
@alexanderchuranov
alexanderchuranov / expose-const.cc
Last active July 4, 2024 20:53
Container exposes methods to mutate the values only if its template parameter is a non-const type
#include <iostream>
#include <type_traits>
// The C++11 implementation.
namespace cxx11 {
template <typename T>
class ConstView {
public:
ConstView() = default;
@alexanderchuranov
alexanderchuranov / replace-audio.sh
Created October 5, 2023 19:38
Replace audio streams in a video file using ffmpeg, creates a new file
#!/bin/sh
USAGE='usage: replace-audio <orig-videofile> <new-audio> <output-file>'
[ $# -ne 3 ] && { echo "${USAGE}" 2>&1; exit 1; }
ORIG_VIDEO="$1"
NEW_AUDIO="$2"
OUTPUT_FILE="$3"
@alexanderchuranov
alexanderchuranov / extract-audio.sh
Created October 5, 2023 19:37
Extract multichannel audio from a video file using ffmpeg
#!/bin/sh
USAGE='usage: extract-audio <filename> <streamno>'
[ $# -ne 2 ] && { echo "${USAGE}" 2>&1; exit 1; }
VIDEOFILE="$1"
STREAM_NO="$2"
LAYOUT_7_1='7.1[FL][FR][FC][LFE][BL][BR][FLC][FRC]'
@alexanderchuranov
alexanderchuranov / local-variable-lifetime.cc
Created October 25, 2022 11:49
Demonstrates that local variables in C++ are not destroyed before the return expression is evaluated.
// Output:
//
// creating A
// using A where A.s = 'valid test value'
// destroying A where A.s = 'valid test value'
@alexanderchuranov
alexanderchuranov / two-equals-one.cc
Last active December 25, 2019 16:39
C++ The floating-point expression gets evaluated as 2.0, becomes 1.0 when converted to an integer :--))
#include <iostream>
// Typical output:
// num_samples (double) = 2.000000e+00
// num_samples (int) = 1
// product = 31
int main()
{
double start = 17.3;
double end = 17.5;
@alexanderchuranov
alexanderchuranov / note-beat-match.py
Created November 21, 2019 12:54
Finds a combination of a note and musical tempo so that the note wave cycle is best aligned with the tempo.
#!/usr/bin/python
# Finds a combination of a note and musical tempo so that the note
# wave cycle is best aligned with the tempo.
# Input: MIDI note number
# Output: Frequency in Hz
def note_freq(midi_note_number):
return 440 * (2 ** ((midi_note_number - 69)/12.0))
@alexanderchuranov
alexanderchuranov / Numark DJ2Go and Akai MPK for Traktor Pro.tsi.xml
Created July 21, 2019 12:33
Dual controller configuration for Traktor Pro, Numark DJ2Go and Akai MPK
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<NIXML><TraktorSettings><Entry Name="DeviceIO.Config.Controller" Type="3" Value="RElPTQAOIqpESU9JAAAABAAAAAFERVZTAA4ilgAAAAJERVZJAAcZAAAAAAwARwBlAG4AZQByAGkAYwAgAE0ASQBEAElEREFUAAcY3ERESUYAAAAEAAAAAERESVYAAAAaAAAACQAyAC4AMAAuADEAIABEAGUAdgAAACJERElDAAAALAAAABQATgB1AG0AYQByAGsAIABEAEoAMgBHAE8AIABNAGEAcABwAGkAbgBnRERQVAAAAHQAAAAbAE4AdQBtAGEAcgBrACAARABKADIARwBvACAAKABOAHUAbQBhAHIAawAgAEQASgAyAEcAbwApAAAAGwBOAHUAbQBhAHIAawAgAEQASgAyAEcAbwAgACgATgB1AG0AYQByAGsAIABEAEoAMgBHAG8AKUREREMABvfYRERDSQADe+QAABAQRENEVAAAAC4AAAALAEMAaAAwADEALgBDAEMALgAwADAAMAAAAAcAAAAAQv4AAAAAAAH/////RENEVAAAAC4AAAALAEMAaAAwADEALgBDAEMALgAwADAAMQAAAAcAAAAAQv4AAAAAAAH/////RENEVAAAAC4AAAALAEMAaAAwADEALgBDAEMALgAwADAAMgAAAAcAAAAAQv4AAAAAAAH/////RENEVAAAAC4AAAALAEMAaAAwADEALgBDAEMALgAwADAAMwAAAAcAAAAAQv4AAAAAAAH/////RENEVAAAAC4AAAALAEMAaAAwADEALgBDAEMALgAwADAANAAAAAcAAAAAQv4AAAAAAAH/////RENEVAAAAC4AAAALAEMAaAAwADEALgBDAEMALgAwADAANQAAAAcAAAAAQv4AAAAAAAH/////RENEVAAAAC4AAAALAEMAaAAwADEALgB
@alexanderchuranov
alexanderchuranov / parse-integer.cc
Last active January 24, 2018 01:58
A comparison of 3 standard ways to parse a string into an integer in C++. Results: use std::istringstream for error reporting.
// A comparison of 3 standard ways to parse a string into an integer
// in C++.
//
// Requirements:
// - parse into a signed at-least-32-bit 'int' type.
// - communicate errors.
//
// Test results: both atol() and strtol() fail to communicate an
// out-of-range condition in all cases. The istringstream is the most
// robust parser. All implementations stop at the first non-numeric
@alexanderchuranov
alexanderchuranov / sync-google-calendars.js
Last active November 1, 2018 14:28
Sync your work Google Calendar with your personal Google Calendar by blocking time in Personal Calendar whenever there is an event in Work Calendar.
// This script solves the problem of bidirectional syncing of
// work and personal Google Calendars.
//
// Google Calendar is amazing software, but we often want to book some
// time for personal use (e.g. appointment to a doctor), invite friends
// and relatives (e.g. visiting with a spouse) and have this time booked
// at work calendar too (so that no-one schedules a 1:1 meeting for that
// interval). This is often done by inviting your work account to the
// personal event.
//