Skip to content

Instantly share code, notes, and snippets.

View qookei's full-sized avatar
🤔
hmm

Kacper Słomiński qookei

🤔
hmm
  • Poland
  • 13:13 (UTC +02:00)
View GitHub Profile
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(' ');
/*
* 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>
#include <iostream>
#include <string_view>
#include <cctype>
#include <array>
#include <cassert>
struct insn {
uint8_t op = 0;
uint8_t arg = 0;
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_++;
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.
#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>
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)...);
@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;
(defn do_bf_step [code stdin state]
(let [c (first code)
mem (get state :mem)
ind (get state :ind)]
(if (zero? (count code))
state
(cond
(= c \+) (do_bf_step (rest code) stdin {:mem (assoc mem ind (mod (+ (mem ind) 1) 256)) :ind ind})
(= c \-) (do_bf_step (rest code) stdin {:mem (assoc mem ind (mod (- (mem ind) 1) 256)) :ind ind})
(= c \.) (do (print (char (mem ind)))
#include <iostream>
#include <tuple>
#include <array>
#include <cstring>
namespace detail {
template<typename ...Ts>
struct concat_size;
template<typename ...Ts>