Skip to content

Instantly share code, notes, and snippets.

@royratcliffe
royratcliffe / foo.sh
Last active November 3, 2024 18:43
Python
# Run a Python script in a virtual environment as superuser.
sudo -E env PATH=$PATH python script.py
cmake_minimum_required(VERSION 3.25)
project(polyinterp)
add_executable(polyinterp polyinterp.cpp)
@royratcliffe
royratcliffe / uniq.lua
Last active April 28, 2024 15:42
Unique Lua Pairs
--- Unique pairs.
-- @module uniq
-- @author Roy Ratcliffe <roy@ratcliffe.me>
-- @copyright 2023, 2024
-- @license MIT
local _M = {}
local unpack = table.unpack or unpack -- Lua 5.1 compatibility
--- Answers the next index and unique value.
-- See [Semantics of the Generic `for`](https://www.lua.org/pil/7.2.html) for
@royratcliffe
royratcliffe / devcontainer.json
Last active April 22, 2024 10:53
nordic-semiconductor.nrf-connect
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/rocker-org/devcontainer-features/rstudio-server:0": {},
"ghcr.io/meaningful-ooo/devcontainer-features/homebrew:2": {}
}
}
#include <cassert>
/*!
* \brief True if the first string ends with the second string.
* \param ends String with some required ending for which to test.
* \param with Ending to test the first string against.
*/
bool ends_with(const std::string &ends, const std::string &with) {
return ends.length() >= with.length() &&
ends.compare(ends.length() - with.length(), with.length(), with) == 0;
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
@royratcliffe
royratcliffe / diskpart.cmd
Last active October 27, 2023 16:39
diskpart
@REM wsl --shutdown docker-desktop
@REM wsl --shutdown docker-desktop-data
select vdisk file="C:\Users\..\AppData\Local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
@royratcliffe
royratcliffe / Makefile
Last active October 8, 2023 07:20
Buildroot Tarball on Docker ARM
rootfs:
docker run -it --rm -v rootfs:/mnt -v .:/home alpine tar -C /mnt -xf /home/rootfs.tar
rootfs-%:
docker run -it --rm -v rootfs:/mnt --privileged --platform linux/arm arm32v7/alpine $*
ash: rootfs-ash
# /etc/init.d/rcK
# /etc/init.d/rcS
@royratcliffe
royratcliffe / Config.in
Last active October 11, 2023 04:03
swipl-ffi-buildroot
config BR2_PACKAGE_SWIPL_FFI
bool "SWI-Prolog FFI"
depends on BR2_PACKAGE_SWIPL
depends on BR2_PACKAGE_LIBFFI
help
Dynamic calling C from Prolog.
This package deals with calling C functions from shared objects from Prolog without writing wrappers.