Skip to content

Instantly share code, notes, and snippets.

View bwedding's full-sized avatar

bwedding

  • Sweden
View GitHub Profile
@bwedding
bwedding / ExecutionTimer.cpp
Last active May 6, 2019 20:57
High resolution, pure C++, auto-ranging execution timer. See examples in main(). This is modified slightly from the code by Code Blacksmith on Youtube
// ExecutionTimer.cpp
// original code by Code Blacksmith on Youtube
// https://www.youtube.com/watch?v=GV0JMHOpoEw
#include "stdafx.h" // remove if not needed
#include <algorithm>
#include <iostream>
#include <vector>
#include <chrono>
using namespace std::chrono;
@bwedding
bwedding / WinCPULoad.cpp
Created April 25, 2019 21:25
CPU Load measurement for Windows, found on StackOverflow
#include <Windows.h>
static float CalculateCPULoad(unsigned long long idleTicks, unsigned long long totalTicks)
{
static unsigned long long _previousTotalTicks = 0;
static unsigned long long _previousIdleTicks = 0;
unsigned long long totalTicksSinceLastTime = totalTicks-_previousTotalTicks;
unsigned long long idleTicksSinceLastTime = idleTicks-_previousIdleTicks;
@bwedding
bwedding / cheatsheet.cpp
Created April 1, 2019 20:20 — forked from satwikkansal/cheatsheet.cpp
C++ STL cheatsheet for competitive progrmming
/*
This a header file that includes every standard library.
You can use it to save time.
NOTE: This header file may not be recognized by compilers
other than gcc.
*/
#include <bits/stdc++.h>
/*
//Use this if the above header file doesn't work.
@bwedding
bwedding / step_iota.cpp
Last active March 29, 2019 18:56
C++ stepping iota template for ints and floats
// Use of lambda with std::accumulate to only add numbers that are n
#include <numeric>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <list>
#include <numeric>
#include <random>
#include <vector>
@bwedding
bwedding / picker.cpp
Last active September 27, 2018 01:39
#include <string>
#include <algorithm>
#include <functional>
#include <iostream>
#include <random>
#include <map>
// Percentage of pickers in each group
enum group {low, lowMid, hiMid, hi};
@bwedding
bwedding / msvc17parallel.cpp
Last active October 21, 2018 19:28
Testing Parallel sorting using MSVC 17 and C++17 parallel algorithms
// Be sure to set your project to use the ISO C++17 Standard (/std:c++17) under
// C++ Language Standard in Properties... C/C++... Language...
#include <string>
#include <iostream>
#include <algorithm>
#include <execution>
#include <random>
#include <chrono>
#include <iomanip>
#include <chrono>
#include <algorithm>
#include <functional>
#include <iostream>
#include <random>
#include <string>
// All this should be in a header, but I'm doing this for ease of use in a Gist
// Readability
using StrlenFunc = size_t(*const)(const char*);
#include <chrono>
#include <algorithm>
#include <functional>
#include <iostream>
#include <random>
#include <string>
// Return time in seconds as a double.
static std::chrono::high_resolution_clock::time_point GetTime(void)
{
@bwedding
bwedding / Program.cs
Created June 26, 2018 05:55 — forked from jankurianski/Program.cs
Example of LoadHtml with CefSharp.OffScreen
// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using CefSharp.Example;
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){function i(i,a){var o,l,d,r,c,u,h,p,f,m=this.data(),y=this.find("ul"),g=!1;if(m.vals&&0!==y.length){for(i||(i=m.seconds),m.intervalId&&(g=!0,clearTimeout(m.intervalId)),o=Math.floor(i/s),l=o*s,d=Math.floor((i-l)/n),l+=d*n,r=Math.floor((i-l)/60),l+=60*r,c=i-l,u=(o<100?"0"+(o<10?"0":""):"")+o+(d<10?"0":"")+d+(r<10?"0":"")+r+(c<10?"0":"")+c,h=m.vals.length-1,p=u.length-1;h>=0;h-=1,p-=1)f=parseInt(u.substr(p,1),10),m.vals[h]=f,y.eq(h).children().html(f);(g||a)&&(m.ttStartTime=t.now(),m.intervalId=setTimeout(e.bind(this),1e3),this.data("intervalId",m.intervalId))}}function e(i){var s,n,a,o,l,d,r,c=this,u=this.find("ul"),h=this.data();return h.vals&&0!==u.length?("undefined"==typeof i&&(i=h.iSec),s=h.tickCount+1,this.data("tickCount",s),n=h.vals[i],a=u.eq(i),o=a.children(),l=h.countdown?-1:1,o.eq(1).html(n),n+=l,"function"==typeof this.data("step")&&this.data("t