Skip to content

Instantly share code, notes, and snippets.

View JPGygax68's full-sized avatar

Hans-Peter Gygax JPGygax68

View GitHub Profile
@JPGygax68
JPGygax68 / gulp_textfile_wrapper.js
Last active August 29, 2015 13:59
This is a Gulp "pipe" that wraps the content of text files into CommonJS modules exporting that content as a string.
var gulp = require('gulp');
var gutil = require('gulp-util');
var through = require('through2');
/* Wrap the content of text files into CommonJS modules exporting that content as JS strings.
*/
function textFileToCommonJS(filename, options) {
var lines = [];
@JPGygax68
JPGygax68 / main.cpp
Created April 26, 2013 09:40
Minimal C++ main.cpp
#include <iostream>
using namespace std;
int
main (int argc, char *argv[])
{
cout << "Press ENTER to continue....." << endl << endl;
cin.ignore(1);
}
@JPGygax68
JPGygax68 / Aspect_composition.cpp
Last active May 17, 2016 21:23
Use C++11 template template parameters to add pseudo-aspects via chained inheritance
#include <iostream>
/*=======================================================================
* ASPECT COMPOSITION
*======================================================================*/
template<class Parent>
struct Nil_aspect: public Parent
{
void tell() {} // no-op, and ends the chain
#include <iostream>
/*=======================================================================
* ASPECT COMPOSITION
*======================================================================*/
/* This is the base class to be specialized via CRTP.
*
* It must provide all the methods that aspects can override as no-ops.
*/
@JPGygax68
JPGygax68 / find_next_nal_unit.cpp
Last active September 18, 2017 19:03
Function that finds the next #NALU inside #H264 bitstream data.
/*
* Find next NAL unit from the specified H.264 bitstream data.
*/
static auto find_next_nal_unit(const uint8_t *start, const uint8_t *end) -> const uint8_t *
{
const uint8_t *p = start;
/* Simply lookup "0x000001" pattern */
while (p <= end - 3 && (p[0] || p[1] || p[2] != 1))
++p;
@JPGygax68
JPGygax68 / opengl_rectangle.hpp
Last active September 18, 2017 19:04
Defining and drawing a rectangle with #OpenGL using a #VAO (vertex array object) and a vertex buffer.
/* Example class for rendering a rectangle using OpenGL 4, using a vertex buffer and a
* vertex array object and the triangle strip primitive.
*
* Note: GL calls are wrapped into a variadic macro of the form GL(func, arg1, arg2,...).
*/
class opengl_rectangle {
public:
void get_resources()
@JPGygax68
JPGygax68 / pipe.cpp
Last active September 18, 2017 19:04
How to support #piping (input/output redirection) in C++
ifstream ifs;
ofstream ofs;
istream *is = nullptr;
ostream *os = nullptr;
if (!input_file.empty()) {
ios_base::sync_with_stdio(false);
ifs.open(input_file, ios::binary);
is = &ifs;
}
@JPGygax68
JPGygax68 / readfile.cpp
Last active September 18, 2017 19:06
C++: read a whole #file into a string.
using namespace std;
ifstream fs(filename);
string s;
fs.seekg(0, ios::end);
s.reserve( (size_t) fs.tellg() );
fs.seekg(0, ios::beg);
s.assign( istreambuf_iterator<char>(fs), istreambuf_iterator<char>() );
@JPGygax68
JPGygax68 / getWindowsErrorString.cpp
Last active September 18, 2017 19:07
Retrieve the text associated with a #Windows #error code, and return it as a std::string
static const std::string
getWindowsErrorString(int err = 0)
{
LPSTR s;
if (err == 0) err = GetLastError();
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
err,
@JPGygax68
JPGygax68 / binding.gyp
Last active September 18, 2017 19:09
#Node: How to specify build-specific library directories for #node-gyp (binding.gyp)
{
'targets': [
{
'target_name': 'lsexcel_node',
'include_dirs': [ 'support/' ],
'sources': [ 'bindings.cc', 'support/utils.cc' ],
'configurations': {
'Debug': {
'msvs_settings': {
'VCLinkerTool': {