Skip to content

Instantly share code, notes, and snippets.

View mmomtchev's full-sized avatar

Momtchil Momtchev mmomtchev

View GitHub Profile
@mmomtchev
mmomtchev / transform.js
Created March 18, 2024 16:40
Crude transformer for bison grammars to use named references
/**
* Transform a single bison item to named references
*
* For example to transform only "c_decl"
*
* node transform.js Source/CParse/parser.y c_decl Source/CParse/parser.y
*/
const fs = require('fs');
@mmomtchev
mmomtchev / msvc-exception-lambda-bug.cc
Last active September 8, 2023 22:15
msvc-exception-lambda-bug
#include <Magick++.h>
#include <exception>
#include <functional>
#include <string>
typedef std::function<const char *()> MakeErr;
class LambdaException : public std::exception {
MakeErr get_err;
@mmomtchev
mmomtchev / std_exception.cc
Created August 16, 2023 15:00
Copying `std::exception` with an error message
#include <iostream>
int main() {
auto err = std::logic_error("some error");
std::cout << err.what() << std::endl;
// using the derived copy constructor
std::logic_error err2 = err;
std::cout << err2.what() << std::endl;
<wps:Execute service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0/../wpsExecute_request.xsd" language="en-US">
<!-- template-version: 0.21 -->
<ows:Identifier>hello-nodejs</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>S</ows:Identifier>
<wps:Data>
<wps:LiteralData dataType="string">Garga</wps:LiteralData>
</wps:Data>
</wps:Input>
@mmomtchev
mmomtchev / 1webpack.config.js
Last active May 19, 2022 08:52
Bundling React Native for the Web with Webpack (medium story)
{
resolve: {
alias: {
'react-native$': 'react-native-web',
'../Utilities/Platform': 'react-native-web/dist/exports/Platform',
'../../Utilities/Platform': 'react-native-web/dist/exports/Platform',
'./Platform': 'react-native-web/dist/exports/Platform'
}
}
}
@mmomtchev
mmomtchev / reproduce_v8_bug.js
Last active April 1, 2022 13:41
V8 optimizer bug
const fns = [
(x) => x + 1.1,
(x) => x + 1.1,
];
const array = new Float64Array(1e3);
for (let i = 0; i < array.length; i++)
array[i] = -5 + 10 * (i / (array.length - 1));
let r;
@mmomtchev
mmomtchev / free_lunch.js
Last active March 31, 2022 14:43
Code for the medium story Free Lunch
const input = new Float64Array(1e6);
const output = new Float64Array(1e6);
// We are applying this function to every element from
// input to output
const fn = (x) => x * x + 2 * x + 1;
// This also serves as a cache warm-up
for (let i = 0; i < input.length; i++)
input[i] = i;
@mmomtchev
mmomtchev / srcval.cc
Last active February 23, 2022 11:44
GDAL type casting: macro vs template vs ptr vs lambda
#include <functional>
#include <stdio.h>
#include <gdal/gdal.h>
#include <chrono>
inline double GetSrcVal(const void *pSource, GDALDataType eSrcType, size_t ii) {
switch (eSrcType) {
case GDT_Unknown: return 0;
case GDT_Byte: return static_cast<const GByte *>(pSource)[ii];
case GDT_UInt16: return static_cast<const GUInt16 *>(pSource)[ii];
@mmomtchev
mmomtchev / mutable_lambda.cc
Created February 10, 2022 19:31
The First Commandment of the C++ Committee: Thou shalt not make a rule that prevents C++ programmers from shooting themselves in the foot.
#include <stdio.h>
#include <vector>
struct S {
int a;
};
int main() {
std::vector<S> v;
@mmomtchev
mmomtchev / import-loop.ts
Created March 15, 2021 11:12
Medium article - Making examples with webpack
for (const ex of Object.keys(examples)) {
examples[ex].component = import(/* webpackPrefetch: true */
`./examples/${examples[ex].file}.tsx`)
.then((comp) => comp.default);
examples[ex].code = import( /* webpackPrefetch: true */
`!!raw-loader!./examples/${examples[ex].file}.tsx`)
.then((code) => code.default);
}