Skip to content

Instantly share code, notes, and snippets.

View peter-bloomfield's full-sized avatar

Peter Bloomfield peter-bloomfield

View GitHub Profile
@peter-bloomfield
peter-bloomfield / cfStringToStdString.cpp
Created November 8, 2019 16:34
A function to convert a CFString (macOS / OS X) to a UTF-8 std::string in C++.
#include <CoreFoundation/CoreFoundation.h>
#include <string>
#include <vector>
/**
* Converts a CFString to a UTF-8 std::string if possible.
*
* @param input A reference to the CFString to convert.
* @return Returns a std::string containing the contents of CFString converted to UTF-8. Returns
* an empty string if the input reference is null or conversion is not possible.
@peter-bloomfield
peter-bloomfield / dshow-video-player.cpp
Created September 19, 2019 21:33
Very basic example code for playing a video using DirectShow in C++.
#include <windows.h>
#include <Dshow.h>
#include <iostream>
using namespace std;
// Macro to report success or failure, and return on failure (lazy shorthand... bad habit! :-)
#define REPORT_OUTCOME(hr) if (FAILED(hr)) { cout << "failed" << endl; return false; } cout << "success" << endl;
// Data
@peter-bloomfield
peter-bloomfield / print_with_colour.sh
Last active April 27, 2020 11:29
A bash function to echo coloured log messages.
#!/usr/bin/env bash
# Function echo text to the screen.
# There are two ways to invoke this:
#
# print LEVEL MESSAGE
# print MESSAGE
#
# In the first case, LEVEL can be one of: DEBUG, INFO, SUCCESS, WARNING, or ERROR.
# This determines the colour used to display the message. If the level is not recognised then it defaults to INFO.