Skip to content

Instantly share code, notes, and snippets.

View foxcpp's full-sized avatar
📚
Busy with university projects. May be unavailable for extended periods of time.

Max Mazurov foxcpp

📚
Busy with university projects. May be unavailable for extended periods of time.
  • shtrafovnet.ru
  • Moscow, Russia
View GitHub Profile
@foxcpp
foxcpp / scmp-confine-w
Last active September 29, 2019 16:57
scmp-confine-w wrapper
#!/bin/bash
wrapped_name=scmp-confine
function wrapped {
flags=$1
shift
exec scmp-confine $flags "$@"
}
set -euo pipefail
@foxcpp
foxcpp / webfs.go
Last active September 29, 2019 17:04
Absolutely minimalistic webfs in Go
package main
import (
"errors"
"flag"
"log"
"net/http"
"os"
"path/filepath"
"strings"
@foxcpp
foxcpp / mmap_lll.c
Created August 19, 2019 15:48
The fastest Longest Line Length finding code in the West.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
void find_longest(const char *file, unsigned file_length,
const char **longest_start, unsigned *longest_len) {
@foxcpp
foxcpp / smtp_spin.go
Last active September 29, 2019 17:02
Shamelessly dumb SMTP server stress-tester
package main
import (
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/smtp"
@foxcpp
foxcpp / gobuilder.go
Last active September 29, 2019 17:18
Shameless HTTP wrapper for go get command
// Command gobuilder starts a HTTP-server that will build Go binaries based on the path given.
// Works only for Go 1.11+ (requires modules support).
//
// Usage:
// GET /importpath/revision
//
// Binaries are built for server OS and architecture by default, this can be changed
// using GOOS and GOARCH env. variables.
// gobuilder overrides following env. variables:
// GO111MODULE, GOPATH, GOBIN, GOCACHE, CGO_ENABLED.
@foxcpp
foxcpp / locked.hpp
Created January 27, 2020 19:03
std::shared_mutex + T value wrapper
#pragma once
#include <memory>
#include <shared_mutex>
/*
* std::shared_mutex + T value wrapper written out of boredom.
* Needs C++17 support to compile.
*
* It phohibits direct manipulation of T value without locking the mutex in
@foxcpp
foxcpp / utf8_iterator.hpp
Created February 2, 2020 20:55
UTF-8 decoder for C++11 implemented as an iterator
#pragma once
#include <stdexcept>
#include <iterator>
struct utf8_error : public std::runtime_error {
utf8_error(const char* v) : std::runtime_error(v) {}
};
#if defined(__cpp_exceptions) && !defined(UTF8_IT_NOEXCEPT)
@foxcpp
foxcpp / migrate.go
Created May 11, 2020 12:24
0.2 -> 0.3 imapsql DB migration script
package main
import (
"database/sql"
"fmt"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
)
@foxcpp
foxcpp / shuffer.c
Created June 11, 2020 15:21
High-performance stdin bitflip'er
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <time.h>
typedef union rnd_state_t {
uint64_t s64;
uint32_t s32[2];
uint16_t s16[4];