Skip to content

Instantly share code, notes, and snippets.

View berkus's full-sized avatar
🎯
Haptic drift

Berkus Decker berkus

🎯
Haptic drift
View GitHub Profile
@berkus
berkus / gist:6594742
Created September 17, 2013 14:03
Original, non-working sketch of virtual classes base on examples in CaesarJ http://caesarj.org/index.php/ProgrammingGuide/VirtualClasses
#include <iostream>
using namespace std;
class Button
{
protected:
class Border {
public:
using Color = int;
@berkus
berkus / gist:6594822
Last active December 23, 2015 06:29
Final version of the virtual classes gist, working.
#include <iostream>
using namespace std;
class Button
{
protected:
class Border {
public:
using Color = int;
@berkus
berkus / gist:6594901
Created September 17, 2013 14:16
Boo
class A {
public:
int func() { return 21; }
};
class B : public A {
public:
int func() { return A::func(); }
};
@berkus
berkus / gist:6675271
Created September 23, 2013 19:01
Lambdaed
inline std::ostream& operator << (std::ostream& os, ssu::base_stream::packet const& pkt)
{
std::string packet_type = [](stream_protocol::packet_type type){
switch (type) {
case stream_protocol::packet_type::invalid: return "invalid";
case stream_protocol::packet_type::init: return "init";
case stream_protocol::packet_type::reply: return "reply";
case stream_protocol::packet_type::data: return "data";
case stream_protocol::packet_type::datagram:return "datagram";
case stream_protocol::packet_type::ack: return "ack";
@berkus
berkus / gist:6675817
Last active December 23, 2015 18:29
Hashmapped
inline std::ostream& operator << (std::ostream& os, ssu::base_stream::packet const& pkt)
{
static std::unordered_map<stream_protocol::packet_type,std::string> packet_types {
{stream_protocol::packet_type::invalid, "invalid"},
{stream_protocol::packet_type::init, "init"},
{stream_protocol::packet_type::reply, "reply"},
{stream_protocol::packet_type::data, "data"},
{stream_protocol::packet_type::datagram, "datagram"},
{stream_protocol::packet_type::ack, "ack"},
{stream_protocol::packet_type::reset, "reset"},
@berkus
berkus / palin.cpp
Last active December 25, 2015 00:09
#include <algorithm>
#include <locale>
#include <iostream>
using namespace std;
int main()
{
int i = 0;
string s;
@berkus
berkus / polymorph.cpp
Created October 18, 2013 13:27
From Sean Parent's presentation at GN13. Making a polymorphic document container with undo support.
//
// From GoingNative 2013 "Inheritance is the Base Class of Evil" talk.
//
#include <memory>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
@berkus
berkus / opus-streaming.cpp
Last active December 27, 2015 02:49
Routing module excerpt
uia::routing::internal::regserver_client regclient(host.get());
uia::routing::client_profile client;
client.set_host_name("myhost.local");
client.set_owner_name("Name");
client.set_city("City");
client.set_region("Region");
client.set_country("Country");
client.set_endpoints(set_to_vector(host->active_local_endpoints()));
regclient.set_profile(client);
In file included from test.cpp:1:
In file included from /usr/include/c++/v1/memory:603:
/usr/include/c++/v1/tuple:267:11: error: rvalue reference to type 'test::private_tag' cannot bind to lvalue of type
'test::private_tag'
: value(__t.get())
^ ~~~~~~~~~
/usr/include/c++/v1/tuple:385:8: note: in instantiation of member function 'std::__1::__tuple_leaf<0, test::private_tag &&,
false>::__tuple_leaf' requested here
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
^
> clang -c gistfile1.c
gistfile1.c:26:22: warning: duplicate 'const' declaration specifier
[-Wduplicate-decl-specifier]
static const int const oparray[]=
^
gistfile1.c:176:17: warning: format specifies type 'int *' but the argument has
type 'inst *' (aka 'unsigned long long *') [-Wformat]
READ_AND_SET_IMMV(1);
^~~~~~~~~~~~~~~~~~~~~
gistfile1.c:166:33: note: expanded from macro 'READ_AND_SET_IMMV'