Skip to content

Instantly share code, notes, and snippets.

View KernelDeimos's full-sized avatar
💭
Probably using Gitea instead

Eric Dubé KernelDeimos

💭
Probably using Gitea instead
View GitHub Profile
@KernelDeimos
KernelDeimos / c_undefined_arithmetic_operand_order.js
Created July 22, 2023 19:35
Behaviour of arithmetic operand evaluation order as seen under different C compilers, imitated in a `.js` script.
const cases = [
['-', ['incr_post', 'c'], ['get', 'c']],
['-', ['incr_pre', 'c'], ['get', 'c']],
['-', ['get', 'c'], ['incr_post', 'c']],
['-', ['get', 'c'], ['incr_pre', 'c']],
];
const incr_post = (ctx, v) => {
const v_ = ctx.scope[v];
ctx.scope[v] += 1;
@KernelDeimos
KernelDeimos / test_exec.js
Created July 25, 2022 03:14
Something awful I had to do
/*
The situation was as follows:
- A project has a number of `.js` files under `dist/`
- they're bundled by webpack for the browser
- they're ES6 modules
- A `tools` folder contians commonjs `.js` files
- Want to run tests for files in `dist/` from a node script
- test.js fails because it can't import ES6 modules
@KernelDeimos
KernelDeimos / iframehell.js
Last active July 19, 2022 14:39
Nested iframe pushes message to root page (bad)
const express = require('express');
const dedent = require('dedent');
const scripts = {
TerminalPage: ({ app, route }) => {
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('action').addEventListener('click', () => {
const val = document.getElementById('message').value;
const ori = document.getElementById('origin').value;
console.log(`[${app.name}/${route}] sending message: ` + val)
@KernelDeimos
KernelDeimos / golang_errors.md
Last active May 26, 2018 23:38
An idea for error handling in Golang

Yet another idea for error handling in Go

Enter "trap block"

The trap block runs any time an error needs to be handled. Unlike catch in other languages, it does not divert the control flow to the end of the block. Instead, control flow is returned to the line immedately following where the error was "trapped".

Trapping an error follows a similar syntax to ignoring an error; instead of using _, use ?.