Skip to content

Instantly share code, notes, and snippets.

View qrealka's full-sized avatar

Dmitry Loginov qrealka

View GitHub Profile
@qrealka
qrealka / Makefile
Created May 7, 2024 12:07 — forked from skeeto/Makefile
C Object Oriented Programming Example
CFLAGS = -std=c99 -Wall
main : main.o
.PHONY : test clean
test : main
./$^ "*regex*" "*vtable*" < main.c
clean :
@qrealka
qrealka / main.go
Last active February 22, 2024 12:51
PoC half-auto OTEL metrics creation
package main
import (
"context"
"fmt"
"log"
"sync/atomic"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
@qrealka
qrealka / add.sh
Created October 26, 2020 19:50 — forked from ArseniyShestakov/add.sh
My compiler alternatives
# Cleanup old alternatives
update-alternatives --remove-all cc
update-alternatives --remove-all c++
update-alternatives --remove-all gcc
update-alternatives --remove-all g++
update-alternatives --remove-all clang
update-alternatives --remove-all clang++
update-alternatives --remove-all icc
update-alternatives --remove-all icc++
@qrealka
qrealka / cpp.std.coroutines.draft.md
Created June 15, 2020 10:52 — forked from MattPD/cpp.std.coroutines.draft.md
C++ links: Coroutines (WIP draft)
@qrealka
qrealka / inplace_rle.cpp
Created May 5, 2020 00:09
leetcode inplace rle
class Solution {
public:
int compress(vector<char>& chars) {
int n = chars.size();
if (n <= 1) return n;
int j = 0, i = 0;
while (i < n) {
int k = i;
// skip duplicates
while ((k + 1 < n) && chars[k] == chars[k + 1]) {
@qrealka
qrealka / rle_encode.cpp
Created May 5, 2020 00:02
c++ RLE encoding
string compression(const string & str){
int i = str.size();
string letters;
for (int j = 0; j < i; ++j){
int count = 1;
while (str[j] == str[j+1]){
count++;
j++;
}
@qrealka
qrealka / refl_compare.cpp
Created February 17, 2020 10:06
compare generic struct
// based on https://stackoverflow.com/a/60080443
#define RETURNS(...) \
noexcept(noexcept(__VA_ARGS__)) \
-> decltype(__VA_ARGS__) \
{ return __VA_ARGS__; }
template<class T,
typename std::enable_if< !std::is_class<T>{}, bool>::type = true
>
@qrealka
qrealka / web-servers.md
Created January 18, 2020 09:55 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@qrealka
qrealka / rand_double.c
Created January 7, 2020 11:02
uniform random float generation
/*-
* Copyright (c) 2014 Taylor R. Campbell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@qrealka
qrealka / random.h
Created January 7, 2020 10:45 — forked from Leandros/random.h
C++ Pseudo Random Number Generators
/* Copyright (c) 2018 Arvid Gerstmann. */
/* This code is licensed under MIT license. */
#ifndef AG_RANDOM_H
#define AG_RANDOM_H
class splitmix
{
public:
using result_type = uint32_t;
static constexpr result_type (min)() { return 0; }