Skip to content

Instantly share code, notes, and snippets.

Avatar

Dmitry Loginov qrealka

  • Huawei Research Lab
  • Dublin
  • Twitter @dloginov
View GitHub Profile
@qrealka
qrealka / add.sh
Created Oct 26, 2020 — forked from ArseniyShestakov/add.sh
My compiler alternatives
View add.sh
# 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 Jun 15, 2020 — forked from MattPD/cpp.std.coroutines.draft.md
C++ links: Coroutines (WIP draft)
View cpp.std.coroutines.draft.md
@qrealka
qrealka / inplace_rle.cpp
Created May 5, 2020
leetcode inplace rle
View inplace_rle.cpp
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]) {
View rle_encode.cpp
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 Feb 17, 2020
compare generic struct
View refl_compare.cpp
// 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 Jan 18, 2020 — forked from willurd/web-servers.md
Big list of http static server one-liners
View web-servers.md

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 Jan 7, 2020
uniform random float generation
View rand_double.c
/*-
* 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 Jan 7, 2020 — forked from Leandros/random.h
C++ Pseudo Random Number Generators
View random.h
/* 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; }
@qrealka
qrealka / int_to_bytes.cpp
Created Nov 16, 2019
struct binding for bitwise
View int_to_bytes.cpp
#include <cstdint>
#include <iostream>
#include <tuple>
#include <type_traits>
template <typename T>
using unsigned_of = std::conditional_t<
(sizeof(T) == 1), uint8_t,
std::conditional_t<(sizeof(T) == 2), uint16_t,
std::conditional_t<(sizeof(T) == 4), uint32_t,
@qrealka
qrealka / before_greg_test.cpp
Last active Nov 11, 2019
test converters for days before 1582 (gergorian calendar)
View before_greg_test.cpp
#include <cstdio>
#include <chrono>
#include <cinttypes>
#include <ctime>
struct YMD
{
int y{};
unsigned m{};
unsigned d{};