Skip to content

Instantly share code, notes, and snippets.

View amomchilov's full-sized avatar

Alexander Momchilov amomchilov

View GitHub Profile
@o11c
o11c / every-vm-tutorial-you-ever-studied-is-wrong.md
Last active December 15, 2025 04:41
Every VM tutorial you ever studied is wrong (and other compiler/interpreter-related knowledge)

Note: this was originally several Reddit posts, chained and linked. But now that Reddit is dying I've finally moved them out. Sorry about the mess.


URL: https://www.reddit.com/r/ProgrammingLanguages/comments/up206c/stack_machines_for_compilers/i8ikupw/ Summary: stack-based vs register-based in general.

There are a wide variety of machines that can be described as "stack-based" or "register-based", but not all of them are practical. And there are a lot of other decisions that affect that practicality (do variables have names or only address/indexes? fixed-width or variable-width instructions? are you interpreting the bytecode (and if so, are you using machine stack frames?) or turning it into machine code? how many registers are there, and how many are special? how do you represent multiple types of variable? how many scopes are there(various kinds of global, local, member, ...)? how much effort/complexity can you afford to put into your machine? etc.)

  • a pure stack VM can only access the top elemen
@amarcu5
amarcu5 / muteonsleep.swift
Last active March 5, 2021 01:35
Small macOS utility to ensure system is muted when asleep to prevent potential sounds during Power Nap; Addresses reddit issue: https://www.reddit.com/r/apple/comments/8t041u/my_macbook_creeps_me_out_by_starting_to_talk_in/
//
// MuteOnSleep
// Ensures system is muted when asleep to prevent potential sounds during Power Nap
//
// Install by pasting the following in a terminal prompt:
// curl https://s3.amazonaws.com/muteonsleep-tool/muteonsleep.tar.gz | tar xvz -C /usr/local/bin/; osascript -e 'tell application "System Events" to make login item at end with properties {path:"/usr/local/bin/muteonsleep", hidden:true}'; nohup /usr/local/bin/muteonsleep &
//
// Uninstall with:
// pkill muteonsleep; osascript -e 'tell application "System Events" to delete login item "muteonsleep"'; rm /usr/local/bin/muteonsleep
//
@chrisroos
chrisroos / README.md
Last active June 5, 2025 19:18
Example of using bundler/inline

I came across 'bundler/inline' in Bundler pull request 3440, which I'd found from Rails pull request 20429. This now has a little snippet on the What's new page of the Bundler site.

This little example demonstrates how I might use it to create a single file using minitest.

I've just noticed that this script was working for me because I already had minitest installed as a system gem. If I uninstall the gem then the script fails because it can't find minitest. The source code documents an option to install gems if they don't exist (gemfile(true) do) but that doesn't seem to work for me. I see the following error:

Fetching gem metadata from https://rubygems.org/...
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...

Using metaclass 0.0.4

@detunized
detunized / globals.rb
Created January 16, 2012 12:24
List global Ruby variables and their values
global_variables.sort.each do |name|
puts "#{name}: #{eval "#{name}.inspect"}"
end