Skip to content

Instantly share code, notes, and snippets.

View goldsborough's full-sized avatar
🔨
Fixing things

Peter Goldsborough goldsborough

🔨
Fixing things
View GitHub Profile
Language: Cpp
Standard: Cpp11
BasedOnStyle: Google
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
# Your keymap
#
# Atom keymaps work similarly to style sheets. Just as style sheets use
# selectors to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts. Unlike style sheets however,
# each selector can only be declared once.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
"*":
Repl: {}
"activate-power-mode":
autoToggle: false
"atom-beautify":
general:
_analyticsUserId: "cd30efc3-4a40-427b-a456-0fecb9c02f29"
"atom-clock": {}
"autoclose-html": {}
"autocomplete-clang":
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing snip and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@goldsborough
goldsborough / generalized-pointer.hpp
Created January 2, 2017 01:30
A pointer that can own or simply point and deletes intelligently.
#include <algorithm>
#include <utility>
#ifndef GENERALIZED_POINTER_HPP
#define GENERALIZED_POINTER_HPP
template <typename T>
class GeneralizedPointer {
public:
GeneralizedPointer() noexcept : _is_owning(false), _pointer(nullptr) {
@goldsborough
goldsborough / Benchmark
Created December 5, 2016 11:27
A benchmarking macro for GoogleTest
#define Test(TestSuiteName, TestCaseName) void TestSuiteName##_##TestCaseName()
#define Benchmark_N(TestSuiteName, TestCaseName, numberOfIterations) \
void Benchmark_##TestSuiteName##_##TestCaseName(); \
Test(TestSuiteName, TestCaseName) {\
typedef std::chrono::high_resolution_clock clock_t;\
typedef std::chrono::duration<double, std::micro> duration_t;\
double totalDuration = 0; \
double squaredDuration = 0;\
for (std::size_t i = 0; i < numberOfIterations; ++i) {\
clock_t::time_point start = clock_t::now();\
@goldsborough
goldsborough / calculate.py
Created October 29, 2016 21:25
No idea what CTCI is finding hard here
import re
OPERATIONS = {
'*': lambda a, b: a * b,
'/': lambda a, b: a / b,
'+': lambda a, b: a + b,
'-': lambda a, b: a - b,
}
@goldsborough
goldsborough / lru.cpp
Created October 29, 2016 20:17
LRU Cache
template <typename Iterator>
class LastAccessed {
public:
using Pair = typename std::iterator_traits<Iterator>::value_type;
using Key = typename Pair::first_type;
using Value = typename Pair::second_type;
LastAccessed() : _is_valid(false) {
}
@goldsborough
goldsborough / bitset.go
Created October 23, 2016 19:01
A Bitset in Go
package bitset
import (
"fmt"
"math"
)
type Bitset struct {
data []byte
cardinality int
@goldsborough
goldsborough / heap.go
Created October 23, 2016 19:00
A heap in Go
package heap
type Heap struct {
data []int
compare func(int, int) bool
}
func New() *Heap {
return &Heap{
data: []int{-1},