Skip to content

Instantly share code, notes, and snippets.

View mjschutz's full-sized avatar
🏠
Working from home

Mauro Joel Schütz mjschutz

🏠
Working from home
View GitHub Profile
@mjschutz
mjschutz / WrapMethod.cpp
Created November 5, 2023 15:49
Wrap a Derived Class method to pass to a closed API call using templated function
#include <iostream>
using namespace std;
struct A {
// Use this to wrap method from a derived class
template <typename Class, void (Class::*method)()>
void makeCall() {
(dynamic_cast<Class*>(this)->*method)();
}
// https://stackoverflow.com/a/60505243/4952028
function hexToUtf8(s)
{
return decodeURIComponent(
s.replace(/\s+/g, '') // remove spaces
.replace(/[0-9a-f]{2}/g, '%$&') // add '%' before each 2 characters
);
}
<script src="http://cdn.jsdelivr.net/g/filesaver.js"></script>
<script src="https://cdn.jsdelivr.net/npm/exceljs@4.3.0/dist/exceljs.min.js" integrity="sha256-wJUdjGj95YIQF7RrY8E0M/aU998QyfG6xYKtQLp05/I=" crossorigin="anonymous"></script>
<script>
function SaveAsFile(t,f,m) {
try {
var b = new Blob([t],{type:m});
saveAs(b, f);
} catch (e) {
window.open("data:"+m+"," + encodeURIComponent(t), '_blank','');
}
@mjschutz
mjschutz / ReactXML.tsx
Last active October 30, 2020 08:35
Generate a XML on React from ReactElements/Nodes
import React from 'react';
import {create as createXML} from 'xmlbuilder2';
import { XMLBuilder, XMLBuilderCreateOptions, DefaultBuilderOptions, XMLWriterOptions } from "xmlbuilder2/lib/interfaces";
function renderXMLElement(root: XMLBuilder, {type, props}: React.ReactElement) {
let node = root;
if (typeof type !== 'symbol') {
const elementName = typeof type == 'function' ? type.name: type;
@mjschutz
mjschutz / iframe-print.js
Last active November 9, 2019 23:09
Function to print some HTML content on NW.js using a iFrame
function printR(htmlContent) {
let doc = nw.Window.get().window.document;
let iframe = doc.createElement("iframe");
iframe.style.display = 'none';
doc.body.appendChild(iframe);
iframe.onload = () => {
console.log('loaded');
if (typeof htmlContent === 'function') {
htmlContent(iframe);
@mjschutz
mjschutz / msvs_env.bat
Last active July 23, 2019 18:11
CEF project need to update their msvs_env.bat file to search for the VS2019 vcvars
@echo off
:: Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
:: reserved. Use of this source code is governed by a BSD-style license
:: that can be found in the LICENSE file.
:: Set up the environment for use with MSVS tools and then execute whatever
:: was specified on the command-line.
set RC=
/*
* This is a C++ translation/adaptation of
* A fast javascript implementation of simplex noise by Jonas Wagner
* Copyright 2018 Mauro Joel Schütz <maurojoel@gmail.com>
Based on a speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
Which is based on example code by Stefan Gustavson (stegu@itn.liu.se).
With Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
Better rank ordering method by Stefan Gustavson in 2012.
@mjschutz
mjschutz / scratch-lang.c
Created January 24, 2018 04:54
C version of scratch-lang from scratch-lang.notimetoplay.org
// C version of
// Part 1: numbers and words — DRAFT 2 — 2008-09-06
// http://scratch-lang.notimetoplay.org/scratch-lang.js
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct _stack {
@mjschutz
mjschutz / HiddenInterface.cpp
Last active October 31, 2015 23:13
Hidden Interface Implementation on C++
#include <iostream> // std::cout
class Interface {
public:
class HiddenInterface;
static inline Interface* of(Interface::HiddenInterface* hInterface);
static inline Interface& of(Interface::HiddenInterface& hInterface);
virtual void show(char const* const msg) const =0;
@mjschutz
mjschutz / StdIteratorExample.cpp
Last active September 20, 2022 17:34
Example implementation of std::iterator
#include <iterator> // std::iterator,std::input_iterator_tag
#include <iostream> // std::cout
template <typename T, size_t N>
class SampleVector
{
T vector[N];
public:
class iterator : public std::iterator<std::input_iterator_tag, T>
{