Skip to content

Instantly share code, notes, and snippets.

import sys
import os
import socket
import importlib
import subprocess
def _install_and_import(package,
alias=None,
version=None,
package_name=None,
import asyncio
import yt_dlp
def progress_hook(d):
if d['status'] == 'downloading':
print(f"Downloaded {d['downloaded_bytes']} bytes of {d['total_bytes']} bytes")
async def download_video(url):
ydl_opts = {
'format': 'best',
@aliakseis
aliakseis / gist:8ae52a9aa41f6f714a835c3852c30b1b
Created February 22, 2025 16:06
MSVC exception stack trace
LONG WINAPI VectoredHandler(EXCEPTION_POINTERS* ExceptionInfo) {
// Filter out only C++ exceptions
if (ExceptionInfo->ExceptionRecord->ExceptionCode == 0xE06D7363) { // MSVC C++ exception code
CONTEXT context = *ExceptionInfo->ContextRecord;
HANDLE process = GetCurrentProcess();
HANDLE thread = GetCurrentThread();
SymInitialize(process, NULL, TRUE);
STACKFRAME64 stackFrame;
@aliakseis
aliakseis / gist:93ff3b9c41ed82e20992606dee4a7ae1
Created May 27, 2024 10:34
This could be a part of a meta-programming framework in C++ that uses macros and templates to generate metadata about classes.
#define BEGIN_META_MAP(classname) \
template<int id, int> friend struct CDescriptor; \
private: \
enum { ID_REFERENCE_POINT = __COUNTER__ }; \
typedef classname TheClass; \
template<int id, int=id> struct CDescriptor \
{ \
}; \
template<int id> struct CDescriptor<id, 0> \
{ \
@aliakseis
aliakseis / gist:3f92a73da2ea6c85683b58e9dced604c
Last active May 22, 2024 19:43
Improved fast atan2 and hypot approximations
double fast_atan(double x) {
return x / (1 + 0.3211 * x * x);
}
double do_fast_atan2(double y, double x, bool abs_x_lt_abs_y) {
if (abs_x_lt_abs_y) {
double z = x / y;
double atan_z = fast_atan(z);
if (y > 0.0) {
inline double fast_atan(double x) {
// http://www-labs.iro.umontreal.ca/~mignotte/IFT2425/Documents/EfficientApproximationArctgFunction.pdf.
//constexpr auto scaling_constant = 0.28086;
//constexpr auto N2 = 0.273;
constexpr auto scaling_constant = 0.274;
constexpr auto N2 = 0.258;
return ((M_PI_4 + N2) / 2. - (N2 / 2.) * std::abs(x)) * x
+ x / (2. + (scaling_constant * 2.) * x * x);
@aliakseis
aliakseis / main.html
Last active November 4, 2022 13:28
This is a copy/paste example streaming the webcam from the mobile browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>libdatachannel media receiver example</title>
</head>
<body>
<p>Please enter the offer provided to you by the receiver application: </p>
<textarea cols="80" rows="25"></textarea>
///////////////////////////////////////////////////////////////////////////////////
// //
// Blitz 2D //
// //
// Code to make easy use of DirectX / GDI+ to draw 2D graphics //
// //
// By Sean O'Connor 2010 //
// //
// Thanks to: //
// Wendy Jones - for the book "Beginning DirectX 9" //
@aliakseis
aliakseis / gist:bb3d5b5e32604ee88418475b4c13c537
Created June 2, 2022 15:02
ROS changes to build on Windows
Edit: C:\opt\ros\noetic\x64\share\catkin\cmake\all.cmake
test/catkin_download_test_data
# test/gtest
test/nosetests
Edit: C:\opt\ros\noetic\x64\share\ros\core\rosbuild\private.cmake
- check_same_directories.py => check_same_directories
- added string(REPLACE "\\" "/" _pyl "${_pyl}")
- _rosbuild_cmakelist_to_pylist calls modified
macro(_rosbuild_cmakelist_to_pylist _cmakelist _pylist)
@aliakseis
aliakseis / ansi2utf8.cpp
Created May 18, 2021 09:29
Converting a file from ANSI to utf8
// ansi2utf8.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <string>
#include <fstream>
#include <streambuf>
#include <atlcore.h>