Skip to content

Instantly share code, notes, and snippets.

View rdnvndr's full-sized avatar

Andrey Rodionov rdnvndr

View GitHub Profile
@opsJson
opsJson / cmdl.c
Created June 7, 2023 01:22
Pipe output of any command line program to buffer in C.
#ifndef CMDL_H_
#define CMDL_H_
#ifdef _WIN32
#include <windows.h>
static const char *cmdl_errlist[] = {
"No Error.",
"CreatePipe() failed: could not create a pipe.",
"CreateProcessA() failed: could not create child process.",
@SanariSan
SanariSan / readme.md
Last active November 14, 2024 04:01
Telegram HTTP bot API via CURL | Send text, photos, documents, etc.

Here are some examples on how to use Telegram bot api via CURL

Prerequisites

For getting messages in private chat with bot

  • Create a bot using @BotFather, get it's token
  • Start conversation with bot
  • Run following curl command
curl https://api.telegram.org/bot/getUpdates | grep -Po '"from":{"id":.+?,'
@opsJson
opsJson / segfault-check.c
Last active April 13, 2024 18:54
SegFault check
#include <stdlib.h>
#include <stdio.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <fcntl.h>
#define PIPE(X) _pipe(X, 2, O_RAW)
#else
#include <unistd.h>
#define PIPE(X) pipe(X)
#endif
@kjmph
kjmph / A_UUID_v7_for_Postgres.sql
Last active November 16, 2024 17:02
Postgres PL/pgSQL function for UUID v7 and a bonus custom UUID v8 to support microsecond precision as well. Read more here: https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
create or replace function uuid_generate_v7()
returns uuid
as $$
begin
-- use random v4 uuid as starting point (which has the same variant we need)
-- then overlay timestamp
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string
return encode(
@kassane
kassane / PQDBConn.h
Created February 23, 2020 17:34
Libpq Async
#pragma once
#include <libpq-fe.h>
#include <experimental/string_view>
#include "PQQuery.h"
#include "PQError.h"
#include <tuple>
@LazyRen
LazyRen / lock_free_bounded_queue.cpp
Created December 4, 2019 15:29
Implementation of simple lock free bounded queue in C++
#include <atomic>
#include <chrono>
#include <cinttypes>
#include <cstdio>
#include <thread>
using namespace std;
#define NUM_PRODUCER 4
#define NUM_CONSUMER NUM_PRODUCER
#define NUM_THREADS (NUM_PRODUCER + NUM_CONSUMER)
@kassane
kassane / Event_Loop.md
Created April 6, 2019 14:26
Explain Event Loop

Event Loop

In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program.

It works by making a request to some internal or external "event provider" (that generally blocks the request until an event has arrived), and then it calls the relevant event handler ("dispatches the event").

The event-loop may be used in conjunction with a reactor, if the event provider follows the file interface, which can be selected or 'polled' (the Unix system call, not actual polling).

The event loop almost always operates asynchronously with the message originator.

@antmd
antmd / addresssanitizergcc.md
Last active March 1, 2022 21:14
AddressSanitizer for GCC
@zanculmarktum
zanculmarktum / megafetch.sh
Last active October 20, 2024 08:05
Get download url from mega.nz
#!/bin/bash
# Copyright 2018, 2019, 2020 Azure Zanculmarktum
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
@yni3
yni3 / SimpleThread.cpp
Created January 27, 2018 13:12
[C++11] thread
/*
SimpleThread.cpp -- implement for SimpleThread.h
Copyright 2018 yni3
License : Public Domain (useful for copy and paste for your project)
*/
#include "SimpleThread.h"
#if defined(_UNIX) || defined(__ANDROID__) || defined(__APPLE__)
#include <pthread.h>