Skip to content

Instantly share code, notes, and snippets.

@amidvidy
amidvidy / gist:ba5647f087863f2d5497
Last active August 29, 2015 14:17
std::mutate example
#include <type_traits>
#include <iostream>
namespace std {
template <typename T>
using mut = typename std::remove_reference<T>::type&;
template <typename T>
constexpr mut<T> mutate(T& t) {
int main() {
std::vector<int> foo;
}
@amidvidy
amidvidy / gist:c001313dd4b9c4860246
Last active August 29, 2015 14:07
UDP name server
#include <string>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
using boost::asio::ip::udp;
namespace {
@amidvidy
amidvidy / gist:b4883a84a7ac17f0d37a
Created October 10, 2014 22:03
Simple boost::asio Hello world udp server
#include <string>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
using boost::asio::ip::udp;
namespace {
class HelloWorldServer {
@amidvidy
amidvidy / capped_example.cpp
Created September 2, 2014 14:13
C++ driver example
#include <cstdlib>
#include <list>
#include "mongo/client/dbclient.h"
#include "mongo/bson/bson.h"
namespace bson {
typedef mongo::BSONElement Element;
typedef mongo::BSONObj Obj;
typedef mongo::BSONObjBuilder Builder;
@amidvidy
amidvidy / either.cpp
Created August 6, 2014 22:18
attempt at Either w/ c++ 11
// C++11 only
#if __cplusplus <= 201103L
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <functional>
#include <memory>
#include <type_traits>
@amidvidy
amidvidy / todo.rs
Last active January 4, 2016 01:39
my first rust program: a really crappy todo list
use std::io::buffered::BufferedReader;
use std::io;
#[deriving(Clone)]
struct Todo {
desc: ~str,
completed: bool
}
impl Todo {
@amidvidy
amidvidy / gist:5342673
Last active December 15, 2015 23:49
bloom http example
module BloomHttpAPIExample
state do
http(:req, :resp) :hello_world, [:query_param1, :query_param2, ...]
end
bloom do
# we could also use some kind of template mechanism
hello_world.resp <= hello_world.req { |r| [["<html><p>Your ip is #{r.remote_addr}</p></html>"]] }
end
end
@amidvidy
amidvidy / threadtest.cpp
Created November 26, 2012 11:14
C++11 std::thread example
// compile with g++-4.7 -std=c++11 -pthread threadtest.cpp -o threadtest
#include <iostream>
#include <thread>
#include <cstdlib>
#include <chrono>
static const int num_threads = 10;
int main() {
@amidvidy
amidvidy / peano.scm
Created December 12, 2011 12:46
peano in scheme
; O is a natural number.
(define zero 'zero)
; For every number n, (succ n) is a natural number.
(define (succ n)
(lambda () n))
; A few numbers
(define one
(succ zero))