Skip to content

Instantly share code, notes, and snippets.

View JPGygax68's full-sized avatar

Hans-Peter Gygax JPGygax68

View GitHub Profile
@JPGygax68
JPGygax68 / traits.cpp
Last active December 23, 2020 07:20
How to implement custom #traits (C++11)
#include <type_traits>
#include <iostream>
using std::enable_if;
using std::is_same;
using std::declval;
using std::integral_constant;
template <typename T>
using Invoke = typename T::type;
@JPGygax68
JPGygax68 / utf8-utf32.cpp
Last active July 15, 2022 08:13
#Unicode conversion: UTF-8 to UTF-32 in C++11
#include <codecvt>
using namespace std;
#if _MSC_VER >= 1900
wstring_convert<codecvt_utf8<int32_t>, int32_t> utf32conv;
auto utf32 = utf32conv.from_bytes("The quick brown fox jumped over the lazy dog.");
// use reinterpret_cast<const char32_t *>(utf32.c_str())
#else
wstring_convert<codecvt_utf8<char32_t>, char32_t> utf32conv;
@JPGygax68
JPGygax68 / CMakeLists.txt
Last active September 18, 2017 19:23
#CMakeLists.txt #project #top-level file
cmake_minimum_required(VERSION 3.0)
#------------------------------------------------
# Project + basics
#
project(GPCFontRasterizer)
set(${PROJECT_NAME}_MAJOR_VERSION 0)
set(${PROJECT_NAME}_MINOR_VERSION 1)
@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 / 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 / local_webserver_Gruntfile.js
Last active September 18, 2017 20:58
Using #grunt-express as a local web server during development #tags: web server, grunt-server
"use strict";
var path = require('path');
module.exports = function(grunt) {
grunt.initConfig({
express: {
defaults: {
options: {
port: 3000,
@JPGygax68
JPGygax68 / require_config.html
Last active September 18, 2017 19:33
Copy-paste example of a #require_js configuration, including loading require.js from the "scripts" subdirectory.Indented two levels (2 spaces per level) for correct insertion in the document header.
<script type="text/javascript" src="scripts/require.js" data-main="app/main"></script>
<script>
requirejs.config({
paths: {
'underscore': 'lib/underscore',
'jquery' : 'lib/jquery-2.0.3',
'backbone' : 'lib/backbone',
'relational': 'lib/backbone-relational',
'css' : 'lib/css.min'
},
@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': {
@JPGygax68
JPGygax68 / backbone-single-reflow.js
Last active September 18, 2017 19:35
Oz Katz' (thanks!) single-reflow #Backbone #collection render()
render: function() {
this.$el.empty();
var container = document.createDocumentFragment();
// render each subview, appending to our root element
_.each(this._views, function(subview) {
container.appendChild(subview.render().el)
});
this.$el.append(container);
}
@JPGygax68
JPGygax68 / promisechain.js
Last active September 18, 2017 19:35
How to create a dynamic #promise chain.
// var index = ... hash of id => filename
return _.reduce(index, function(seq, filename, id) {
return seq.then( function() { return fs.read(filename); } )
}, Q.resolve());