Skip to content

Instantly share code, notes, and snippets.

View BenEmdon's full-sized avatar
🏁

Ben Emdon BenEmdon

🏁
View GitHub Profile
@BenEmdon
BenEmdon / Singleton.h
Created March 17, 2019 21:37
C++ Singletons which don't leak
class Singleton {
public:
// Lazily get reference to a static instance of Singleton.
// The benifit of the following inplementation:
// * It lazily creates a Singleton.
// * It creates the Singleton on the global stack, so when the program ends
// the Singleton is automatically deallocated and it's deconstructor is invoked.
static Singleton& getInstance() {
// The following line (starting with `static`) only executes once,
// no matter how many times this function executes.
@BenEmdon
BenEmdon / Obfuscated.js
Last active May 28, 2020 01:50
Shows how one could obfuscate the underlying details of some functionality in JS. Execute this in your browser to see what happens. I promise this is safe 😇
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+
@BenEmdon
BenEmdon / C++TemplatedLinkedList.cpp
Last active April 20, 2017 00:10
C++ Example of a templated linked list
// Example of how to implement a templated linked list
#include <iostream>
#include <string>
using namespace std;
class Cat {
public:
Cat(string name = "unnamed", int age = 0): name(name), age(age) { }
const string name;
int age;
@BenEmdon
BenEmdon / MemberInitializerSyntax.md
Created April 19, 2017 21:49
A brief overview of member initializer syntax in C++

C++ Member Initializer Syntax

Member initializer syntax is a great way to give data members initial values on object initialization.

"All other things being equal, your code will run faster if you use initialization lists rather than assignment." - isocpp.org

For the purposes of this example let's pretend we have the class Cat:

#include <iostream>
#include <string>
using namespace std;
@BenEmdon
BenEmdon / C++Arrays.md
Last active April 19, 2017 21:49
A brief explanation of the 4 basic types of arrays in C++

The Basic 4 types of Arrays in C++

For the purposes of these examples let's pretend we have the class Cat:

#include <iostream>
#include <string>
using namespace std;

class Cat {
public:
	Cat(string name = "unnamed") {