Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
using std::cout, std::endl;
#include <string>
using std::string, std::to_string;
struct eat { constexpr eat(auto...){} };
constexpr auto Tree(auto left, long val, auto right) {
return [=](auto f) { return f(left, val, right); };
}
int vasprintf(char** strp, const char* format, va_list ap)
{
int len = _vscprintf(format, ap);
if (len == -1)
return -1;
char* str = (char*)malloc((size_t)len + 1);
if (!str)
return -1;
int retval = vsnprintf(str, len + 1, format, ap);
CStringA ConvertUnicodeToUTF8(const CStringW& uni)
{
if (uni.IsEmpty()) return ""; // nothing to do
CStringA utf8;
int cc = 0;
// get length (cc) of the new multibyte string excluding the \0 terminator first
if ((cc = WideCharToMultiByte(CP_UTF8, 0, uni, -1, NULL, 0, 0, 0) - 1) > 0)
{
@charlie-x
charlie-x / gist:33cdd141434a5526d49742418c1a1940
Created April 15, 2020 17:45
timur spin lock without RAII unlock non realtimesafe/overhead
#include <array>
#include <thread>
#include <atomic>
#include <emmintrin.h>
struct spin_mutex {
void lock() noexcept {
// approx. 5x5 ns (= 25 ns), 10x40 ns (= 400 ns), and 3000x350 ns
// (~ 1 ms), respectively, when measured on a 2.9 GHz Intel i9
constexpr std::array iterations = {5, 10, 3000};
@charlie-x
charlie-x / gist:f9d8b0f25cc1c7612cc58ab29901e9ec
Created November 1, 2019 20:28
install tesla win10 64 bit via powershell
$Path = $env:TEMP; $Installer = "426.23-tesla-desktop-win10-64bit-international.exe"; Invoke-WebRequest "http://us.download.nvidia.com/tesla/426.23/426.23-tesla-desktop-win10-64bit-international.exe" -OutFile $Path\$Installer; Start-Process -FilePath $Path\$Installer -Args "" -Verb RunAs -Wait; Remove-Item $Path\$Installer
@charlie-x
charlie-x / gist:b9c0e316154bd03d453ba89d1ae3f4a2
Created November 1, 2019 20:23
chrome install with powershell
$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $Path\$Installer; Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path\$Installer
{NOTE_D5, 600, 50},
{NOTE_E5, 600, 50},
{NOTE_G5, 150, 50},
{NOTE_REST, 100, 50},
{NOTE_G5, 150, 50},
{NOTE_REST, 100, 50},
{NOTE_G5, 150, 50},
@charlie-x
charlie-x / gist:e660af069777b0dfbcaf980e9b7f5501
Created September 26, 2018 04:38
building openssl1.1.0 windows x64
add rc.exe to path, windows sdk etc, default C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64
add nasm.exe https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win64/ default C:\Program Files\NASM
vcvars64.bat from 2017 folder default C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64
# no-shared for static libs
# inside openssl extracted source folder
perl configure VC-WIN64A --openssldir=C:\OpenSSL-Win64 no-asm no-shared
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
rem choco install visualstudio2013professional %1 -y
rem choco install visualstudio2015professional %1 -y
rem choco install teamviewer9 %1 -y
chocolatey install paint.net %1 -y
chocolatey install tortoisegit %1 -y
chocolatey install tortoisesvn %1 -y
chocolatey install autodesk-fusion360 %1 -y
chocolatey install f.lux %1 -y
chocolatey install sysinternals %1 -y
@charlie-x
charlie-x / layout.kbd.json
Last active September 7, 2017 03:27
Untitled Keyboard Layout
[
{
"backcolor": "#000000",
"switchMount": "cherry",
"switchBrand": "cherry",
"switchType": "MX3A-11Nx",
"pcb": true
},
[
{