Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 {
int main() {
std::vector<int> foo;
}
@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) {
@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))
@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 / 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:6c0b803e2cf836cdd5b9
Created January 29, 2016 19:08
undefined behavior is cool
➜ scratch cat both.c
#include <stdio.h>
int main(void) {
int a;
if (!(a == 0)) puts("ha");
if (!(a != 0)) puts("ho");
return 0;
}
➜ scratch ~/Documents/svnroot/llvm/build/bin/clang -O1 both.c
#include <iostream>
#include <string>
#include <vector>
class Base1 {
public:
void foo() {
std::cout << "Base1" << std::endl;
}
};