Skip to content

Instantly share code, notes, and snippets.

View qookei's full-sized avatar
🤔
hmm

Kacper Słomiński qookei

🤔
hmm
  • Poland
  • 09:30 (UTC +02:00)
View GitHub Profile
@qookei
qookei / term-img.cpp
Created May 7, 2020 15:02
Terminal image viewer using Imlib2
#include <iostream>
#include <Imlib2.h>
int main(int argc, char **argv) {
if(argc != 2) {
fprintf(stderr, "%s: usage: <image>\n", argv[0]);
return 1;
}
Imlib_Image img;
template <typename T>
concept requires_checksum = requires (T a, void *b, ptrdiff_t c, size_t d) {
{ a.do_checksum(b, c, d) } -> std::same_as<void>;
};
template <typename ...Args>
mem::buffer build_packet(Args &&...args) {
size_t total_size;
auto parts = frg::make_tuple(std::forward<Args>(args)...);
#include <iostream>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <time.h>
#include <inttypes.h>
#include <unistd.h>
#include <atomic>
#include <sys/wait.h>
struct timerfd final : file {
static auto create_timer(reactor *rtor_) {
return new timerfd{rtor_};
}
timerfd(reactor *rtor)
: file{rtor, timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK)}, current_{} { }
// ----------------------------------------------------------------------------------
// Sleep boilerplate.
struct line_iterator {
line_iterator(std::string_view sv)
: sv_{sv} {}
struct iter {
iter &operator++() {
std::string_view sv = o_->sv_.substr(i_);
auto newl = sv.find('\n');
n_++;
#include <iostream>
#include <string_view>
#include <cctype>
#include <array>
#include <cassert>
struct insn {
uint8_t op = 0;
uint8_t arg = 0;
/*
* compile with: g++ gorbitsa.cpp -o gorbitsa -ftemplate-depth=99999999 -std=c++2a
* Tested with GCC 10.1, does *not* work with Clang 10
*/
#include <iostream>
#include <string_view>
#include <cctype>
#include <array>
#include <type_traits>
while (sock->connected()) {
auto b = co_await sock->recv();
frg::string_view req{static_cast<char *>(b.data()), b.size()};
size_t newl = req.find_first('\n');
auto http_req = req.sub_string(0, newl);
auto s1 = http_req.find_first(' ');
auto s2 = http_req.find_last(' ');
/*
Requires compiler with C++20 concept support (GCC 10.1/Clang 10 or newer)
*/
#include <unordered_map>
#include <concepts>
#include <iostream>
#include <variant>
#include <string>
#include <vector>
/*
* compile with: g++ gorbitsa.cpp -o gorbitsa -ftemplate-depth=99999999 -std=c++2a
* Tested with GCC 10.1, does *not* work with Clang 10
*/
#include <iostream>
#include <string_view>
#include <cctype>
#include <array>
#include <type_traits>