Skip to content

Instantly share code, notes, and snippets.

@mhamilt
mhamilt / PrintAUs.swift
Last active February 18, 2019 16:43
Print all Audio Unit Effects in Swift
//==============================================================================
// Print all installed audio unit effects in Swift
// Handy in for debugging in a Swift console app
//==============================================================================
import Foundation
import AVFoundation
//==============================================================================
var availableAudioUnits = [AVAudioUnitComponent]()
//==============================================================================
func updateAudioUnitList()
@mhamilt
mhamilt / get_screen_ids.swift
Created June 20, 2019 12:04
Get a list of screen IDs from swift
import Foundation
import Cocoa
for screen in NSScreen.screens
{
print(screen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")]!);
}
@mhamilt
mhamilt / vlc-multi-macos.md
Last active November 6, 2022 12:43
Playing multiple fullscreen instances of VLC

macOS Multi Display Sync: VLC

This brief script came about from numerous requests to play multiple videos in sync with each other from a single machine. The videos were to have different content but would be of the same duration. Achieving this on macOS has proved to be a little tricky to say the least. It is possible to run multiple instance of VLC so that videos can be played concurrently from the same machine.

Be aware that this method does not enforce any syncing, so it is possible for the videos to fall out of sync, especially if the are not exactly the same frame count and encoding.

Further reading

If precision is required you may want to invest in a ocuple of Rapsberry Pis and check out the following

@mhamilt
mhamilt / FFMPEG_Gif.md
Last active September 10, 2019 14:21
Make gifs with ffmpeg

FFMPEG: Generate Gif

See This SO Article

And Here

# verbose, but customisable
ffmpeg -i VIDEO.EXTENSION  -vf "fps=10,scale=680:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 OUT.gif
# gritty, but portable
@mhamilt
mhamilt / pass_unique_ptr.cpp
Created August 16, 2019 09:05
Passing a unique pointer to a function
#include <iostream>
#include <memory>
void setPtr (int *a)
{
std::cout << *a << '\n';
}
int main(int argc, const char * argv[])
{
@mhamilt
mhamilt / metal_compute.md
Created August 23, 2019 11:00
Metal Compute Shader

Paralell Data Processing with Metal

Build Instructions

Create a Swift Command Line Tool in Xcode. You can then copy and paste the below code into the .swift and .metal files respectively

Source

main.swift

@mhamilt
mhamilt / Notes.md
Last active February 19, 2023 20:17
Metal Compute Shader Example in Swift and Objective C

Notes

Create a command line target in xcode either in Swift or Obj-C. add a metal file to the project and copy and paste the respective code into each file.

@mhamilt
mhamilt / add_column_to_csv.py
Last active September 6, 2019 11:56
add a column to a csv file with some robust handling
import csv, os
def add_csv_column(filename: str, column_name: str, data: list) -> None:
"""
Add a column of data to an existing csv file
pads with empty string if data size does not match target csv
:param filename: path to csv file
@mhamilt
mhamilt / sine-sweep.swift
Last active September 11, 2019 12:33
A CLI sine sweep in Swift
//------------------------------------------------------------------------------
import AVFoundation
//------------------------------------------------------------------------------
var secondsOfAudio:Float = 0.5; // or var secondsOfAudio:Float = Float(CommandLine.arguments[1])!;
//------------------------------------------------------------------------------
var ae:AVAudioEngine? = AVAudioEngine()
var player:AVAudioPlayerNode? = AVAudioPlayerNode()
var mixer:AVAudioMixerNode? = ae?.mainMixerNode;
//------------------------------------------------------------------------------
let sr:Float = Float((mixer?.outputFormat(forBus: 0).sampleRate)!)
@mhamilt
mhamilt / classdoc.md
Last active October 8, 2019 10:02
C++ Class declaration snippet with HeaderDoc tags

Copy and Paste or create a code snippet in xcode

Access snippets in Xcode with L

/*!
 @class <#Class Name#>
 @brief <#Quick Description#>
 @discussion <#Talk about what this does in more detail#>
 @namespace &lt;#What is the Namespace if any#&gt;