Skip to content

Instantly share code, notes, and snippets.

@mogenson
mogenson / pboard.lua
Last active December 18, 2023 07:41
Write to the MacOS clipboard from LuaJIT via FFI bindings to Objective-C
ffi = require("ffi")
C = ffi.C
ffi.cdef([[
typedef struct objc_object *id;
typedef struct objc_selector *SEL;
id objc_getClass(const char*);
SEL sel_registerName(const char*);
id objc_msgSend(id,SEL);
id NSPasteboardTypeString;
@mogenson
mogenson / serial.lua
Created November 20, 2022 16:55
serial terminal in lua + luv / libuv
#!/usr/bin/env lua
local uv = require("luv")
local port = arg[1] or "/dev/ttyUSB0"
local baud = arg[2] or 115200
local read_fd = assert(uv.fs_open(port, "r", tonumber("666", 8)))
local write_fd = assert(uv.fs_open(port, "w", tonumber("666", 8)))
os.execute("stty -F " .. port .. " " .. baud .. " raw -echo -echoe -echok")
@mogenson
mogenson / lua.nix
Created March 21, 2022 19:34
Croissant nix derivation
# lua.nix
{ config, lib, pkgs, ... }:
with pkgs; let
luaprompt = luajitPackages.buildLuarocksPackage {
pname = "luaprompt";
version = "0.7-1";
knownRockspec = (fetchurl {
url = "https://luarocks.org/luaprompt-0.7-1.rockspec";
@mogenson
mogenson / shell.nix
Created July 15, 2021 18:17
Nix shell to build CircuitPython on MacOS
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz") { }
, pkgs_x86_64 ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz") { localSystem = "x86_64-darwin"; }
}:
with pkgs.python38Packages;
let
cascadetoml = buildPythonPackage rec {
pname = "cascadetoml";
version = "0.3.0";
src = fetchPypi {
@mogenson
mogenson / color-clock.sh
Created March 2, 2020 02:02
A bash script to change the color of a Philips Wiz WiFi light bulb throughout the day
#!/bin/bash
IP=192.168.86.24
PORT=38899
while :
do
HOURS=$(date +"%-H")
MINUTES=$(date +"%-M")
MINUTES=$(($HOURS * 60 + $MINUTES))
@mogenson
mogenson / main.c
Last active December 15, 2019 22:05
Example: default value for optional macro argument
/* Copyright (c) 2019 Michael Mogenson
* MIT license https://opensource.org/licenses/MIT
*/
/* This contrived example demonstrates the use of the comma operator and
* variadic arguments to create a function-like macro that accepts an optional
* argument and provides a default value when no argument is supplied.
*
* C's comma operator will evaluate the statement to the left of the comma and
* return the value of the statement to the right. The line `if (i++, true)` is
@mogenson
mogenson / enums.dart
Last active August 29, 2019 18:35
dart enum problem
class EnumType {
static const int one = 1;
}
void printEnum(EnumType number) {
print(number);
}
void main() {
printEnum(EnumType.one);
@mogenson
mogenson / dell-5530-arch-install.md
Last active August 26, 2019 16:25
Dell 5530 Arch Linux Installation Guide

Dell 5530 Arch Linux Installation Guide

This following instructions install Arch Linux on a Dell 5530 laptop. This installation uses systemd for boot. It sets up a 30GB root partition and an encrypted user partition that is decrypted and mounted on login. Let's get started.

Base installation

Download and write the Arch Linux installation ISO to a flash drive. Insert flash drive, press power, hold F12, and select flash drive to boot.

Set system clock:
timedatectl set-ntp true

@mogenson
mogenson / get-speed-limit.py
Created March 8, 2019 19:50
Query speed limit for latitude longitude. Example for I-93: ./get-speed-limit.py 42.589634 -71.163586
#!/usr/bin/env python3
import requests
import sys
import re
# parse command line arguements
if len(sys.argv) != 3:
print("Usage: {} latitude longitude".format(sys.argv[0]))
sys.exit()
unmap("b");
map("b", "S");
map("m", "d");
map(",", "e");
map("H", "E");
map("L", "R");