Skip to content

Instantly share code, notes, and snippets.

View mnvr's full-sized avatar
☀️

Manav Rathi mnvr

☀️
View GitHub Profile
@mnvr
mnvr / pq.js
Created November 22, 2024 06:05
A simple promise queue in JavaScript to serialize the execution of a bunch of promises
// A promise queue
const q = []
const add = (task) => {
let handlers;
const p = new Promise((...args) => (handlers = args));
q.push({task, handlers});
if (q.length == 1) next();
return p;
@mnvr
mnvr / App.vue
Created September 16, 2024 07:13
Vue mini-cheatsheet gleaned from tutorial (https://vuejs.org/tutorial/)
<!-- npm create vue@latest, VSCode install Volar -->
<script setup>
import { reactive } from "vue";
import { ref } from "vue";
const counter = reactive({
count: 0,
});
const someClass = ref("some");
@mnvr
mnvr / void-tags.md
Last active November 7, 2024 09:37
HTML void tags (aka "self closing tags", "auto closing tags")
area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr

The spec calls these void elements. These do not require a closing slash.

@mnvr
mnvr / index.html
Last active May 2, 2024 15:15
Electron Fiddle to test webUtils.getPathForFile behaviour on Windows
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Paths</title>
</head>
<body>
<input type="file" />
<script>
const input = document.querySelector("input")
@mnvr
mnvr / index.html
Created April 16, 2024 08:19
Electron Fiddle to demonstrate malformed streams with Electron 30.x etc. Send always works (shasum /tmp/myscheme.txt = d269175ac71ed60bb96f08881c39453c8e8d7020). Stream doesn't. Uncommenting the wait makes the stream also work.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"> -->
<title>Stream</title>
</head>
<body>
<button id="send">Send</button><br/>
@mnvr
mnvr / Modify-Xcode-Templates.md
Created January 1, 2024 02:56
Change the template file that Xcode uses when creating a new Swift/SwiftUI file.

Last verified to work with Xcode 15.1.

Ten years later and I still find myself doing this on a new machine. I'd written a script and gist-ed it earlier to save myself time on new machines, but that script and gist got lost to the sands of time, so here's another one.

Open

~/Library/Developer/Xcode
@mnvr
mnvr / cycle.swift
Last active December 22, 2023 15:30
/// All the ways to zip.
///
/// The Swift standard library doesn't seem to have a way to cycle an element so
/// that it can be paired with something else in a zip. These are the ways I've
/// found to achieve the same effect. The last one, `.map({($0, z)})` might be
/// the most idiomatic Swift (and is also the shortest one to express in Swift).
let xs = [1, 2, 3]
let y = 1...10
// Persist the scope window's position across restarts (by default,
// it always starts centered on the screen on each restart).
//
// Usage
// -----
//
// Open the Stethoscope in your startup file, e.g.
//
// s.scope;
//

Building SuperCollider from Source

macOS

SuperCollider's documentation for building on macOS is in the README_MACOS.md file in the SuperCollider. These are additional notes for the way I did it.

Install CMake. This will generate the Xcode project files for building SuperCollider.

@mnvr
mnvr / main.dart
Last active January 2, 2023 02:22
Minimal example demonstrating Flutter InheritedWidgets with mutable state
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyWidget(),
);