Skip to content

Instantly share code, notes, and snippets.

@mhamilt
mhamilt / make-icon-set.sh
Created March 16, 2021 12:08
Generate AppIcon Set with ImageMagick
filename=$(basename $1 .png)
for res in 1024 512 256 128 64 32 16
do
convert $1 -resize "${res}x${res}" "${filename}-${res}.png"
done
@mhamilt
mhamilt / harmonic-series.ipynb
Last active May 17, 2021 15:17
Does gist render Jupyter Notebooks?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mhamilt
mhamilt / write_wave.py
Created March 2, 2021 12:27
Wave file with only Python standard libraries
import struct
import wave
import os
from math import sin, tau
sample_rate = 44100.0
duration = 2.0
frequency = 440.0
num_samples = int(sample_rate * duration)
bit_depth = 16
@mhamilt
mhamilt / wasapi-console.cpp
Last active February 25, 2024 18:27
WASAPI simple console application to play a sine wave
//-----------------------------------------------------------
// Play an audio stream on the default audio rendering
// device. The PlayAudioStream function allocates a shared
// buffer big enough to hold one second of PCM audio data.
// The function uses this buffer to stream data to the
// rendering device. The inner loop runs every 1/2 second.
//-----------------------------------------------------------
#include <iostream>
#include <windows.h>
@mhamilt
mhamilt / sh-exp-modes.md
Created November 17, 2020 11:50
Shell Expansion Modes

Modes

  • Parameter Expansion: ${}
  • Command Substitution: $()
  • Arithmetic Expansion: $(())

Examples

Parameter Expansion

@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)!)