Skip to content

Instantly share code, notes, and snippets.

View pps83's full-sized avatar

Pavel P pps83

View GitHub Profile
# By default, enforce LF line-endings on all text files
* text=auto eol=lf
*.c text eol=lf
*.h text eol=lf
*.cpp text eol=lf
*.hpp text eol=lf
# Visual Studio
*.sln eol=crlf
*.vcxproj eol=crlf
@pps83
pps83 / fix-line-endings.sh
Last active March 27, 2025 01:14
Bash script to rewrite git history of a master branch making sure that line endings are changed to LF
#use https://github.com/newren/git-filter-repo
git-filter-repo --file-info-callback '
contents = value.get_contents_by_identifier(blob_id)
ext = filename.lower().split(b".")[-1]
if ext not in [b"c", b"cpp", b"h", b"hpp"] or \
value.is_binary(contents):
# Make no changes to the file; return as-is
return (filename, mode, blob_id)
@pps83
pps83 / umul128.cpp
Last active February 13, 2025 06:07
umul128
#include <stdint.h>
#include <intrin.h>
// based on XXH_mult64to128 from xxHash https://github.com/Cyan4973/xxHash/blob/dev/xxhash.h#L4464
uint64_t umul128(uint64_t x, uint64_t y, uint64_t* hi)
{
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__wasm__) \
&& defined(__SIZEOF_INT128__) \
|| (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
// gcc/clang __uint128_t
@pps83
pps83 / rand.h
Created November 22, 2019 05:53
pcg-based rand32() and rand64()
// pcg-based rand32() and rand64()
#include <stdint.h>
struct pcg32_random_t
{
uint64_t state;
};
static const uint64_t inc = 997;
static struct pcg32_random_t rndState = {99991};
// check TCP connect to port/host
var sock = require('net').connect({ port: 443, host: '127.0.0.1' }).on('connect', () => { console.log('connect OK'); sock.end(); }).on('error', (e) => { console.log('connect error (code:'+e.code+')'); })
// listen for TCP connect on port/host
var server = require('net').createServer((sock) => { console.log('client connected'); sock.end(); }).listen({ port: 443, host: '127.0.0.1' });
run node server.js
then build and run curl-test.cpp
Everything will be ok:
```
CURLINFO_ACTIVESOCKET, ret:0 sockWs:276
curl_easy_send ret:0 sentSize:194
curl_easy_recv ret:0 recvSize:167
CURLINFO_ACTIVESOCKET, ret:0 sockWs:296
curl_easy_send ret:0 sentSize:194
curl_easy_recv ret:0 recvSize:167
@pps83
pps83 / main.cpp
Created June 10, 2019 02:01
Test simdfastpfor128
#undef NDEBUG
#include "compositecodec.h"
#include "simdfastpfor.h"
#include "variablebyte.h"
#include <stdlib.h>
#include <vector>
// typedef for simdfastpfor128 codec from FastPFor
typedef FastPForLib::CompositeCodec<FastPForLib::SIMDFastPFor<4>, FastPForLib::VariableByte> IntCodec;
@pps83
pps83 / computeHash
Created July 11, 2018 03:21
Compute sha1/md5/hmac-sha1/hmac-md5 using windows API
#ifdef _WIN32
#include <windows.h>
#if !defined(PLATFORM_XBOX) && !defined(PLATFORM_UWP)
#include <wincrypt.h>
#else
#include <bcrypt.h>
#pragma comment(lib, "bcrypt.lib")
#endif
int computeHash(const void* data, unsigned dataSize, unsigned char hashBuf[64], const void *hmacSecret, unsigned hmacSecretSize, bool isMD5)
@pps83
pps83 / ctz_clz.cpp
Last active March 31, 2025 16:21
__builtin_ctz (ctzl, ctzll) and __builtin_clz (clzl, clzll) for Visual Studio
// Note, bsf/bsr are used by default.
// Enable /arch:AVX2 compilation for better optimizations
#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
#include <limits.h>
#if (defined(__cplusplus) && (__cplusplus >= 202002L)) || \
(defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L))
#include <type_traits>
#define _WS2DEF_
#include "inaddr.h"
#include "MSTcpIP.h"
void startServer();
void startClient_6_to_4(short xxport);
void startClient_4_to_4(short xxport);
void startClient_6_to_6(short xxport);
short xxport = 8112;