Skip to content

Instantly share code, notes, and snippets.

View mrkline's full-sized avatar

Matt Kline mrkline

View GitHub Profile
@mrkline
mrkline / summary
Created October 12, 2021 20:45 — forked from phaedryx/summary
Loyalty and Layoffs by David Brady
Original text here: https://whydavewhy.com/2013/08/16/loyalty-and-layoffs/
@mrkline
mrkline / parent-polymorphism.cpp
Last active May 13, 2022 08:08
Sean Parent's polymorphism demo
// See http://sean-parent.stlab.cc/presentations/2016-10-10-runtime-polymorphism/2016-10-10-runtime-polymorphism.pdf
// or an earlier version, "Inheritance Is The Base Class of Evil"
#include <iostream>
#include <memory>
#include <string>
#include <vector>
using namespace std;
@mrkline
mrkline / llswap.cpp
Last active August 29, 2015 14:21
Swapping linked list pairs with two pointers
#include <cstdio>
struct Node {
int data;
Node* next;
};
Node* makeList(int count)
{
Node* const head = new Node();
// MSVC apparently doesn't have C's getline
// This is a poor man's implementation of it using fgets.
// See the man page at
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html
size_t getline(char** buf, size_t* bufLen, FILE* f)
{
if (buf == nullptr || bufLen == nullptr)
{
errno = EINVAL;
return -1;
@mrkline
mrkline / exceptions.md
Last active August 29, 2015 14:04
Why Exceptions?

Exceptions are used over return codes/errnos to handle errors, as they are the idiomatic error handling mechanism in modern C++ code.

  • First and foremost, an uncaught exception exits the program. This is a Good Thing™. Exceptions should only be thrown in the first place when an problem occurs that cannot be handled in the current scope. If this problem is not handled at some scope above the current one, the program should exit, regardless of what error handling paradigm is being used.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@mrkline
mrkline / c_sharp_for_python.md
Last active March 9, 2024 20:09
An intro to C# for a Python developer. Made for one of my coworkers.

C# For Python Programmers

Syntax and core concepts

Basic Syntax

  • Single-line comments are started with //. Multi-line comments are started with /* and ended with */.

  • C# uses braces ({ and }) instead of indentation to organize code into blocks. If a block is a single line, the braces can be omitted. For example,

@mrkline
mrkline / nix_on_windows.md
Last active November 4, 2020 20:36
An overview of setting up *nix tools on Windows using MSYS

*nix on Windows

Options

If you would like to use *nix tools on Windows, you have two main options:

  • Cygwin offers your typical Linux toolset (bash, ls, cd, grep, and the other core utilities) and a DLL that provides some Linux system emulation (signals, etc.). However, Cygwin tends to take the "everything but the kitchen sink" approach, so I generally prefer the second option, MSYS.
@mrkline
mrkline / git_intro.md
Last active October 12, 2015 08:18
Git usage

##The Basics

###Installation

####Windows Users

First off, get msysgit (download here). It is the official Windows Git distribution, and comes with a terminal that has your standard bash commands as well as Git.