Skip to content

Instantly share code, notes, and snippets.

@boxdot
boxdot / async.rs
Last active November 9, 2022 12:03
Async stdin reading with thread and futures in Rust
extern crate futures;
use std::io::{self, BufRead};
use std::thread;
use futures::{Future, Sink, Stream};
use futures::stream::BoxStream;
use futures::sync::mpsc::channel;
fn stdin() -> impl Stream<String, io::Error> {
@boxdot
boxdot / static_polymorphism.cpp
Created April 17, 2017 08:52
Static polymorphism
#include <mapbox/variant.hpp>
#include <cstdlib>
#include <iostream>
struct A {
int x = 0;
};
struct B {
### Keybase proof
I hereby claim:
* I am boxdot on github.
* I am boxdot (https://keybase.io/boxdot) on keybase.
* I have a public key ASA3uOn3iwMZiWKugu5uWg99hm4BWMw3PqUMYmI28KULDAo
To claim this, I am signing this object:
#include <iostream>
template<typename... Fn>
struct overload;
template<typename F, typename... Fn>
struct overload<F, Fn...> : F, public overload<Fn...>::type
{
using type = overload;
#include <boost/asio.hpp>
#include <thread>
#include <iostream>
int main(int argc, char const *argv[])
{
boost::asio::io_service service;
boost::asio::io_service::work work(service);
std::thread thread([&service](){ service.run(); });
@boxdot
boxdot / .block
Last active July 6, 2016 15:35
Gantt Chart
license: MIT
height: 500
@boxdot
boxdot / socket.cpp
Created June 13, 2016 22:20
Simple socket example in OSX
// Compile with:
// c++ -std=c++11 socket.cpp -o socket
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <vector>
#include <iostream>
@boxdot
boxdot / thread_local.cpp
Created May 11, 2016 07:33
Thread local test on mac
// Compile with: c++ -std=c++1y -stdlib=libc++ -pthread thread_loc.cpp
#include <thread>
#include <future>
#include <iostream>
#include <mutex>
namespace {
# openssl req -nodes -x509 -new -keyout server.key -out server.crt
# brew install openssl
# pip install pyOpenSSL
from flask import Flask
app = Flask(__name__)
@app.route('/')
@boxdot
boxdot / wittgenstein.py
Last active April 12, 2016 07:32
A very simple and sometimes mean bot for telegram based on chatterbot.
import requests
from flask import Flask, request
from chatterbot import ChatBot
app = Flask(__name__)
TOKEN = "PUT YOUR TOKEN STRING HERE"