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 / 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 / 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 / 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.
@glebov21
glebov21 / svgtopdf.js
Created March 17, 2023 11:10
Save svg to pdf by jspdf
let svgEl = drawdiv.children[1];
//Если черный квадрат, то убрать прозрачность на none
svg2pdf(svgEl, pdf, {
xOffset: this.pdfPageDefaultOffsetX,
yOffset: pdfOffsetY,
scale: divToPdfRatio
});
let prevFontSize = pdf.internal.getFontSize();
@glebov21
glebov21 / OpenFileDialog.cs
Created June 16, 2022 11:46
C# OpenFileDialog with multiselect OFN_ALLOWMULTISELECT lpstrFile
var ofn = new NativeMethods.OpenFileName();
ofn.lStructSize = Marshal.SizeOf(ofn);
if (Filter != null)
ofn.lpstrFilter = Filter.Replace('|', '\0') + "\0\0";
var maxFilePathLength = 250;
var maxFilesForMultiselect = 100;
ofn.nMaxFile = 1 * maxFilePathLength;
if (AllowMultiSelect)
{
ofn.Flags |= (
@glebov21
glebov21 / web.config
Last active September 9, 2021 15:24
Allow to download all files from iis folder (applicationHost.config -> allowSubDirConfig="false")
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="ForDownload" allowOverride="false" inheritInChildApplications="false">
<system.webServer>
<security>
<authorization>
<!-- Allow all users access to the Public folder -->
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="*" roles="" />
</authorization>