Skip to content

Instantly share code, notes, and snippets.

@thatalextaylor
thatalextaylor / RandomAudioClipPlayer.cs
Last active October 25, 2024 12:24
Play a random Unity AudioClip without playing the same one twice in a row
using UnityEngine;
//Play a random Unity AudioClip without playing the same one twice in a row. Useful for adding variety for otherwise repetitive sounds.
public class RandomAudioClipPlayer
{
private readonly AudioClip[] clips;
private readonly AudioSource audioSource;
private AudioClip lastClip;
//`clips` is the list of sounds to play from
@thatalextaylor
thatalextaylor / CSVMatcher.java
Created February 1, 2017 03:20
CSV Hamcrest Matcher
//package name
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import java.io.IOException;
import java.io.StringReader;
@thatalextaylor
thatalextaylor / 1-python-pretty-time-delta.py
Last active November 5, 2023 22:48
Pretty print a time delta in Python in days, hours, minutes and seconds
def pretty_time_delta(seconds):
sign_string = '-' if seconds < 0 else ''
seconds = abs(int(seconds))
days, seconds = divmod(seconds, 86400)
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
if days > 0:
return '%s%dd%dh%dm%ds' % (sign_string, days, hours, minutes, seconds)
elif hours > 0:
return '%s%dh%dm%ds' % (sign_string, hours, minutes, seconds)