Skip to content

Instantly share code, notes, and snippets.

View avitevet's full-sized avatar

Avi Tevet avitevet

View GitHub Profile
@avitevet
avitevet / pad.coffee
Created September 24, 2013 09:22
general string left padding function in coffeescript
# val = the value to pad
# length = the length of the padded string
# padChar = the character to use for padding. Defaults to '0'
pad = (val, length, padChar = '0') ->
val += ''
numPads = length - val.length
if (numPads > 0) then new Array(numPads + 1).join(padChar) + val else val
@avitevet
avitevet / SimplexAlgorithmReferenceSheet.md
Last active July 28, 2019 08:44
A reference sheet for the terminology and formulas used in the Simplex Algorithm of linear programming problems

Simplex Algorithm Reference Sheet

The simplex algorithm is a method for maximizing or minimizing a linear equation given a set of linear constraints on the variables in the equation.

Definitions

Linear equality
f(x1, x2, .., xn) = b

Linear inequality

@avitevet
avitevet / accurateWindowsPerformanceMeasurement.cpp
Created March 10, 2017 08:10
How to perform accurate & high-resolution performance measurement in "recent" Windows on "recent" x86 processors
#include <Windows.h>
#include <iostream>
// Shows how to perform accurate performance measurements on modern Windows in application-level code
// on x86 processors.
//
// Mostly from https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx.
// The QueryPerformanceCounter is an abstraction around the processor time-stamp counter, which
// starts at zero when the processor is reset and increments monotonically each cycle.
//
@avitevet
avitevet / diet.cpp
Created April 6, 2017 00:05
Using linear programming/simplex method to solve the diet problem: given a set of foods with nutritional data, and a set of nutritional constraints, find the cheapest combination of foods that meets your nutritional needs.
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cassert>
using namespace std;
typedef double ElementType;
typedef vector<vector<ElementType>> matrix;
@avitevet
avitevet / accurateOSXPerformanceMeasurements.cpp
Last active January 23, 2018 22:59
How to perform accurate performance measurements on OS X
#include <mach/mach_time.h>
#include <iostream>
// Shows how to perform accurate performance measurements on modern OS X in application-level code
// on x86 processors.
//
// Performance monitoring on Intel processors is a challenge because the behavior of the internal
// processor counters has changed over the years. Also, processor frequency used to be fixed,
// but with the introduction of SpeedStep technology the processor frequency may change at