Skip to content

Instantly share code, notes, and snippets.

View nikreiman's full-sized avatar

Nik Reiman nikreiman

  • Stockholm, Sweden
View GitHub Profile
@nikreiman
nikreiman / gist:5458386
Last active July 16, 2020 17:50
A quick script to clean up Gerrit branches. I tend to have 1 branch per commit for Gerrit reviews, which means that after some time there are a ton of stale branches sitting around. This script examines all your branches, looking for ones which have a change-id that also exists in the current branch. If it has found such a commit, it prompts you…
function git-branch-current() {
printf "%s\n" $(git branch 2> /dev/null | grep -e ^* | tr -d "\* ")
}
function git-branch-cleanup() {
local currentBranch=$(git-branch-current)
local otherBranch=
for otherBranch in $(git branch | grep -v $currentBranch) ; do
printf "Branch %s:\n" "$otherBranch"
printf " HEAD commit is: %s\n" "$(git log --oneline -n 1 $otherBranch)"
@nikreiman
nikreiman / gist:5009156
Last active August 30, 2018 18:28
Why have a sample rate as a floating point number?
Why have a sample rate as a floating point number?
Many audio API's, such as the VST and CoreAudio SDK's, represent the sampling
rate of the audio hardware as a floating point number. This may seem rather
silly at first, given that it's impossible to have a sample rate of 44100.5.
Thus it would seem that an unsigned integer (ie, uint32_t), would be an ideal
container for sample rate.
However, there is a reason that many audio API's use float (or better yet,
double) for sample rate. The reason is because that most DSP algorithms rely on
@nikreiman
nikreiman / gist:4216723
Created December 5, 2012 15:46
Music Hack Day Stockholm 2013 Idea

My idea for MHD is twofold; first, I would like to take MrsWatson (https://github.com/teragonaudio/MrsWatson), a command-line VST host, and create a dynamic library version from it. Architecturally, I have already been working towards this goal and don't anticipate this part to be terribly difficult. However, I would like to clean up the calling API a bit to make it a bit easier to use.

Then, the big kicker: write a wrappers for MrsWatson so that the dynamic library version could be easily called from other languages. Initially, I feel that Java, Python, and Ruby would be good candidate languages for this. Ruby and Python especially lack good VST support, and this project would be a big step in allowing people to write sequencers or audio services in these languages.

The motivation for this project is to allow other applications to easily process audio (either realtime or offline) with VST plugins. This would also make writing automated audio servers or sequencers significantly easier.

I have limited exper

@nikreiman
nikreiman / gist:2634396
Created May 8, 2012 11:38
Remove finder's dock icon
-- Remove Finder's Icon in the Mac OSX Dock
-- This is useful if you want to keep Finder running alongside Path Finder,
-- but don't want to see it's icon in the Dock or in the list of running
-- applications.
--
-- Taken from Jampe's post on the Cocoatech forums:
-- http://forum.cocoatech.com/archive/index.php/t-1803.html
-- If the dock is hidden, sometimes this doesn't really work
-- So show the dock before removing, and autohide it again afterwards
@nikreiman
nikreiman / initAudioSession.c
Created May 3, 2012 07:55
Recording and processing audio on iOS
// Yeah, global variables suck, but it's kind of a necessary evil here
AudioUnit *audioUnit = NULL;
float *convertedSampleBuffer = NULL;
int initAudioSession() {
audioUnit = (AudioUnit*)malloc(sizeof(AudioUnit));
if(AudioSessionInitialize(NULL, NULL, NULL, NULL) != noErr) {
return 1;
}
@nikreiman
nikreiman / gist:2310318
Created April 5, 2012 11:55
Take a screenshot of your Android app and email it somewhere (no root access required)
public static void sendFeedbackScreenshot(final Activity activity) {
try {
final View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
rootView.setDrawingCacheEnabled(true);
Bitmap bitmap = rootView.getDrawingCache();
// Activity.getCacheDir() won't work here, because the email intent can't
// access your app's internal storage. So you need to find a good temporary
// location in SD card storage.
File outputDir = new File(android.os.Environment.getExternalStorageDirectory(), "tmp");
File outputFile = new File(outputDir, "screenshot.png");
@nikreiman
nikreiman / git-rebase-unpushed.sh
Created February 15, 2012 10:01
Rebase all unpushed commits -- very nice to do before pushing
#!/bin/bash
function git-branch-current() {
printf "%s\n" $(git branch 2> /dev/null | grep -e ^* | tr -d "\* ")
}
function git-log-last-pushed-hash() {
local currentBranch=$(git-branch-current);
git log --format="%h" -n 1 origin/${currentBranch}
}
@nikreiman
nikreiman / gist:1663685
Created January 23, 2012 15:20
Memes galore
#!/bin/bash
memes=( ohyeah.jpg orly.jpg seal.jpg snoopdog.gif testing.jpg haters.gif doh.jpg stop.jpg youcandoit.jpg woohoo.jpg boom.gif tumbleweeds.gif kangaroo.gif jumpcat.gif )
function copyMeme() {
inMeme="$1"
for meme in "${memes[@]}" ; do
printf -v memeName "%s" "$(printf "%s" "$meme" | cut -d '.' -f 1)"
if [ "$memeName" = "$inMeme" ] ; then
printf "http://static.nikreiman.com/meme_${meme}" | pbcopy
@nikreiman
nikreiman / incoming.sh
Created January 20, 2012 10:00
My git merging flow: fetch, incoming, review, merge
# Show incoming commits on the current branch that have yet to be merged.
# This function should be run directly after fetching.
function incoming() {
local branch=$1
if [ -z "$branch" ] ; then
branch=$(git-branch-current)
fi
git --no-pager log origin/$branch ^$branch
}
@nikreiman
nikreiman / gist:1485468
Created December 16, 2011 10:13
Hairy-ish code for getting unique ID from Android device
public String getUniqueId(final Context context) {
String uniqueId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
// Ugh, Motorola's Droid 2.2 devices return this ID, which they copied directly from the Android emulator. If
// we see that device ID, we should instead use the telephony manager's ID instead.
if(uniqueId == null || uniqueId.equals("9774d56d682e549c")) {
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
uniqueId = telephonyManager.getDeviceId();
}
if(uniqueId == null) {
ErrorController.logErrorRemotely("No unique ID found for device!", null);