Skip to content

Instantly share code, notes, and snippets.

@71
71 / cpp-include-guard.code-snippets
Created October 16, 2023 14:08
C++ include guard VS Code snippet: replace special characters with _, make upper case
{
"New C++ header": {
"prefix": "newh",
"body": [
// VS Code snippets do not support recursive replacements so we must be
// creative: replace segments like `foo/`, `bar.` and `h<eos>` to `FOO_`,
// `BAR_` and `H_` such that `foo/bar.h` becomes `FOO_BAR_H_`.
"#ifndef PROJECT_${RELATIVE_FILEPATH/(\\w+)(?:\\.|\\/|$)/${1:/upcase}_/g}",
"#define PROJECT_${RELATIVE_FILEPATH/(\\w+)(?:\\.|\\/|$)/${1:/upcase}_/g}",
@71
71 / cgo.nu
Created August 25, 2023 09:00
`git checkout $branch`, but handles files that are assumed not to have changed.
# use cgo.nu
export def main [branch: string] {
let result = (do { git checkout $branch } | complete)
let stderr = $result.stderr
if $result.exit_code == 1 or ($stderr | str contains 'Your local changes to the following files would be overwritten by checkout') {
let files_to_save = ($stderr | rg '^\s+(.+)$' -r '$1' | lines)
let tmp_dir = (mktemp -d)
@71
71 / jj-completions.nu
Created May 1, 2023 10:15
Jujutsu completions for Nushell
# Usage:
# use jj-completions.nu *
# Jujutsu (An experimental VCS)
export extern jj [
--repository(-R): string # Path to repository to operate on
--ignore-working-copy # Don't snapshot the working copy, and don't update it
--at-operation: string # Operation to load the repo at
--at-op: string # Operation to load the repo at
--verbose(-v) # Enable verbose logging
/*
* Copyright (c) 2020 The ZMK Contributors
* Copyright (c) 2022 Innaworks Development Limited, trading as MoErgo
*
* SPDX-License-Identifier: MIT
*/
/* THIS FILE WAS GENERATED BY GLOVE80 LAYOUT EDITOR
@71
71 / OpenInSplitScreen.kt
Created November 27, 2022 15:43
Snippet to show a text box that, when long-pressed, allows Chrome to be dropped into a split-screen.
// Inspired by Launcher3:
// https://cs.android.com/android/platform/superproject/+/35157974d49e70f03687edb9408e5897d04ff845:packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java;l=293
// Jetpack Compose view with interoperability:
// https://developer.android.com/jetpack/compose/interop/interop-apis
AndroidView(factory = { context ->
TextView(context).apply {
text = "Drag me!"
// Drag and drop listener; see:
@71
71 / Code.gs
Created May 5, 2022 00:53
Generate a "Tags" folder in Google Drive with tags from all files.
function main() {
buildTagsDirectory(
DriveApp.getRootFolder(),
DriveApp.getFolderById("..."),
);
}
/**
* Builds a recursive tags structure in `tagsFolder` with all tags found in items in `rootFolder`.
*/
module Main
open FSharp.Data
open FSharp.Data.JsonExtensions
open Google.Cloud.Functions.Framework
open System
open System.Globalization
open System.Net
open System.Text.RegularExpressions
@71
71 / AUTOMATIC_LINKS.md
Last active June 16, 2020 12:59
Google Sheets: automatically link some specific patterns.
@71
71 / boorkmarklet.md
Last active April 18, 2024 19:39
Lists all participants in a Google Meet meeting.

The following bookmarket shows a popup with the name of the participants separated by newlines.

javascript:-function(maxStrLength = 2000) { try { function findParticipants(current, depth = 0) { if (depth > 7) return; if (typeof current !== "object" || current === null || current === window) return; const descriptors = Object.getOwnPropertyDescriptors(current); for (const prop in descriptors) { if (prop.startsWith('["spaces/')) return Object.values(current); const item = findParticipants(descriptors[prop].value, depth + 1); if (item !== undefined) return item; } } const rootState = Object.entries(window).find(x => x[0].startsWith("closure_lm_"))[1], participants = findParticipants(rootState), names = []; function findName(obj) { for (const prop in obj) { const value = obj[prop]; if (typeof value === "object" && value !== null && typeof value[1] === "string") return value[1]; } } for (let i = 0; i < participants.length; i++) { const name = findName(participants[i]); if (names.indexOf(name) === -1) names.
package main
// For lack of actual generics...
type Input interface{}
type Output interface{}
// CallWithCurrentContinuation returns a function k that can be used to invoke a
// continuation-passing-style function f as if it was a direct-style function.
func CallWithCurrentContinuation(f func(input Input, k func(output Output))) func(input Input) Output {
return func(input Input) Output {