Skip to content

Instantly share code, notes, and snippets.

@glebov21
glebov21 / WSController.cs
Created April 8, 2024 13:41
asp.net core websockets example via controller
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.WebSockets;
namespace WebAPI.Controllers
{
[Route("/ws")]
[ApiController]
@glebov21
glebov21 / AudioAndVideoRecording.cs
Last active February 15, 2024 13:59
Audio and video recording from screen (output audio. Not microphone input)
//1) Add projects: Captura.Base, Captura.Bass, Captura.SharpAvi, Screna from this repository:
https://github.com/MathewSachin v8.0.0
//2) Copy bass.dll & bassmix.dll from x64 folder:
//http://www.un4seen.com/files/bassmix24.zip
//http://www.un4seen.com/files/bass24.zip
recordTask = new Task((cancelationToken) =>
{
@glebov21
glebov21 / UnityExtensions.cs
Last active January 13, 2024 05:08
unity extensions
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public static class UnityExtensions
{
@glebov21
glebov21 / ffmpegCaptureApplication.cs
Created December 7, 2023 11:28
ffmpeg c# capture application with multiple monitors (screens) (no black screen)
private string AppName = "MyApp";
public void StartRecording()
{
StopRecording();
WinProcess.OnGetAllWindowsResult += WinProcess_OnGetAllWindowsResult;
WinProcess.GetAllWindows(); //user32 EnumWindows
}
private void WinProcess_OnGetAllWindowsResult()
@glebov21
glebov21 / pcmTowav.cs
Created November 13, 2023 09:14
PCM to WAV C#
private void WriteWavHeader(MemoryStream stream, bool isFloatingPoint, ushort channelCount, ushort bitDepth, int sampleRate, int totalSampleCount)
{
stream.Position = 0;
// RIFF header.
// Chunk ID.
stream.Write(Encoding.ASCII.GetBytes("RIFF"), 0, 4);
// Chunk size.
stream.Write(BitConverter.GetBytes(((bitDepth / 8) * totalSampleCount) + 36), 0, 4);
@glebov21
glebov21 / KalmanFilterGps.cs
Created June 19, 2018 11:49
Kalman filter c# for Gps
/*
using:
private KalmanLatLong filter = new KalmanLatLong(1);
...
var latitude = Android.LocationInfo.GetLatitude();
var longitude = Android.LocationInfo.GetLongitude();
var accuracyGeoData = Android.LocationInfo.GetAccuracy();
filter.Process(latitude, longitude, accuracyGeoData, (long)AppConstants.TrackerUpdateTimeSec * 1000);
//Set filtered latLon
latitude = filter.get_lat();
@glebov21
glebov21 / Color.cs
Created September 29, 2023 11:25
c# Contrast formula RGB
var contrast = 30; //[-255;+255]
float factor = (259f * (contrast + 255f)) / (255f * (259f - contrast));
Color.r = (byte)Math.Clamp(factor * (Color.r - 128) + 128, 0, 255);
Color.g = (byte)Math.Clamp(factor * (Color.g - 128) + 128, 0, 255);
Color.b = (byte)Math.Clamp(factor * (Color.b - 128) + 128, 0, 255);
@glebov21
glebov21 / SelectGameObjectsWithMissingScripts.cs
Last active June 12, 2023 14:40
Find all missing scripts in unity3d scene
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.SceneManagement; //3
public class SelectGameObjectsWithMissingScripts : Editor
{
[MenuItem("Tools/WPAG Utilities/Select GameObjects With Missing Scripts")]
static void SelectGameObjects()
{
@glebov21
glebov21 / smb.conf
Created April 19, 2023 12:09
samba + active directory
#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
@glebov21
glebov21 / stm32VL53L0X.c
Last active March 20, 2023 19:56
stm32 VL53L0X CONTINUOUS RANGING mode
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.