Skip to content

Instantly share code, notes, and snippets.

View lasty's full-sized avatar

Tristan Macdonald lasty

  • Adelaide, South Australia
View GitHub Profile
@lasty
lasty / observer.cpp
Last active May 2, 2017 06:39
Variation on Observer pattern, using C++11 move/copy
/*
Variation on the Observer design pattern.
I just want to keep a list of items, and call methods on them. (Similar to observer's notify)
But the items will always be in a list (ie, automatic registration)
Instead of the items requiring to be inside pointers or pointer wrappers, this handles stack allocated
items too, and items inside std containers, using copy and move semantics.
Uses C++11 features, compile with gcc -std=c++11 or equivalent
@lasty
lasty / gist:11318271
Last active August 29, 2015 14:00
2D map code hacked up for ludum dare 29
#include <map>
#include <vector>
#include <stdexcept>
class Cell
{
//... (Make sure its copy constructable, or moveable)
};
class Map
@lasty
lasty / tilejson.cpp
Created April 26, 2013 14:00
Wanted to see how easy it was to write a JSON parser.. got it in about 130 lines of code
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
using namespace std;
@lasty
lasty / .vimrc
Last active December 15, 2015 18:59
my .vimrc, including eclipse style alt-up alt-down block moves
set tabstop=4
set shiftwidth=4 "to make << and >> indent to the same size as tabstop
set guifont=DejaVu_Sans_Mono:h9:cANSI
set number
set nowrapscan "stop wraparound on searches, I frequently miss the message
syntax on
@lasty
lasty / vector_vs_lists.cpp
Created March 5, 2013 10:38
Are vectors or linked lists faster?
/***
Are vectors or linked lists faster?
Algorithm:
insert MAX_COUNT random numbers, sorting in place as we go
delete the (random between 0 and current size-1)th element MAX_COUNT times
@lasty
lasty / cxx11_features.cpp
Last active December 10, 2015 14:39
Testing some C++11 features (compile with -std=c++11 on clang 3.2+ or gcc 4.7+)
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
@lasty
lasty / palindrome.cpp
Created September 1, 2012 08:07
project euler problem 4
#include <iostream>
#include <sstream>
using std::cout;
using std::endl;
using std::string;
using std::stringstream;
bool IsPalindrome(const string &s)
@lasty
lasty / circle.cpp
Created April 24, 2012 04:52
Making a circle with just sine data (OpenGL, GLM)
void GenShape()
{
const float radius = 64.0f;
//const float sine[] = { 0.0f, 1.0f, 0.0f, -1.0f };
const float sine[] = { 0.0f, 0.7f, 1.0f, 0.7f, 0.0f, -0.7f, -1.0f, -0.7f };
//const float sine[] = { 0.0f, 0.4f, 0.7f, 0.9f, 1.0f, 0.9f, 0.7f, 0.4f, 0.0f, -0.4f, -0.7f, -0.9f, -1.0f, -0.9f, -0.7f, -0.4f };
const int segments = sizeof(sine) / sizeof(sine[0]);