Skip to content

Instantly share code, notes, and snippets.

@bigdavedev
bigdavedev / sfml_chrono.diff
Created October 22, 2019 13:33
Patch to add `std::chrono` to SFML
diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp
index 50a8f1ea..846930fa 100644
--- a/examples/island/Island.cpp
+++ b/examples/island/Island.cpp
@@ -226,7 +226,7 @@ int main()
// Update and draw the HUD text
osstr.str("");
- osstr << "Frame: " << clock.restart().asMilliseconds() << "ms\n"
+ osstr << "Frame: " << clock.restart().asMilliseconds().count() << "ms\n"
@bigdavedev
bigdavedev / when_are_my_eight_hours_up.cpp
Last active November 23, 2016 12:51
When are my eight hours up?!
#include <chrono>
#include <iostream>
#include <sstream>
#include <tuple>
using namespace std::chrono_literals;
auto const get_minutes(std::string const& string)
{
std::stringstream stream{ string };
@bigdavedev
bigdavedev / brightness.cpp
Last active November 2, 2016 19:47
Simple toy program to set the brightness on my laptop. Mostly for gaining a little exposure to the filesystem library
#include <experimental/filesystem>
#include <fstream>
#include <string>
namespace fs = std::experimental::filesystem;
using namespace std::string_literals;
fs::path const get_backlight_dir(std::string const& path)
{
auto const iterator = fs::directory_iterator{fs::path{path}};
#include <chrono>
#include <iostream>
#include <system_error>
#include <ctime>
using namespace std::chrono_literals;
namespace std
{
namespace chrono
@bigdavedev
bigdavedev / cat.cpp
Last active November 3, 2016 05:20
GNU Core Utils cat in less than 100 lines of code
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <regex>
#include <vector>
#include <unistd.h>
namespace {
@bigdavedev
bigdavedev / README.md
Created March 29, 2016 20:51
Smallest exe for OpenGL window with shader

Download main.c and empty.vcxproj to your PC. Download Crinkler 2.0 from http://crinkler.net/crinkler20.zip and extract it to tools/ in your project folder and rename it to link.exe.

You should then be able to open the project in MSVC 2015 and compile and run it!

Many small cheats are used here to make the code as small as possible. Straight of the bat we never specify more than dwFlags in PIXELFORMATDESCRIPTOR. This struct actually required us to fill in a size field, but that costs four bytes and doesn't appear to do anything horrendous when left out...

In the Fragment Shader we do nothing in the main function. On my machine this implies that the gl_FragColor is black, but YMMV.

Stripping the entrypoint of it prologue and epilogue means that we save on bytes, but we must put some sort of prologue in. The asm on line seven is just the magic we need.