Skip to content

Instantly share code, notes, and snippets.

@mhamilt
mhamilt / .bash_profile
Last active May 29, 2020 10:51
Random changing emoji prompt in bash
# declares an array with the emojis we want to support
EMOJIS=("🐑" "🦔" "🐈" "🦆" "🐓")
# function that selects and return a random element from the EMOJIS set
RANDOM_EMOJI() {
SELECTED_EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]}]};
echo $SELECTED_EMOJI;
}
# declare the terminal prompt format
@mhamilt
mhamilt / get_mouse_position_macos.cpp
Last active June 19, 2022 18:31
Get the mouse position in macOS with C++
#include <ApplicationServices/ApplicationServices.h>
#include <iostream>
#include <string>
///print out location in a nice way to std cout
void fancyPrintLocation(CGPoint location);
/// This callback will be invoked every time the mouse moves.
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type,
CGEventRef event, void *refcon)
@mhamilt
mhamilt / autocorrolate.matlab
Created November 11, 2019 11:01
Pitch Detection
function out = autocorrolate(signal)
% AUTOCORROLATE Multiply a signal by itself over a moving delay window.
% Max delay will be equal to the length of the signal
% Y = AUTOCORROLATE(x) returns auto correlation of x
%
N = length(signal);
out = zeros(size(signal));
for l = 1:N - 1
for n = l+1:(N)
out(l) = out(l) + (signal(n)*signal(n-l));
@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;
@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 / 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 / Notes.md
Last active December 13, 2024 03:46
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 / 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 / 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 / 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