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 / 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 / qrencode-overlay.sh
Created December 2, 2011 15:15
Script to generate QR code with data, and then place an overlay image on top of it
#!/bin/bash
if [ "$#" -eq "0" ] ; then
printf "Usage: %s [content] [overlay image] [output image]\n" "$0"
exit 1
fi
content="$1"
overlayImage="$2"
outputImage="$3"
https://extensions.gnome.org/extension/3780/ddterm/
https://extensions.gnome.org/extension/1162/emoji-selector/
https://extensions.gnome.org/extension/1125/github-notifications/
https://extensions.gnome.org/extension/1399/pop-theme-toggle/
https://extensions.gnome.org/extension/120/system-monitor/
@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 / CallSuspendResume.cpp
Last active September 12, 2019 15:26
Code snippits for creating a VST 2.x plugin host
void resumePlugin(AEffect *plugin) {
dispatcher(plugin, effMainsChanged, 0, 1, NULL, 0.0f);
}
void suspendPlugin(AEffect *plugin) {
dispatcher(plugin, effMainsChanged, 0, 0, NULL, 0.0f);
}
@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 / 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:1408399
Created November 30, 2011 08:06
Unix date formatting cheat sheet
Day
---
%a weekday, abbreviated Tue
%A weekday, full Tuesday
%d day of the month (dd), zero padded 22
%e day of the month (dd) 22
%j day of year, zero padded 001-366
%u day of week starting with Monday (1), i.e. mtwtfss 2
%w day of week starting with Sunday (0), i.e. smtwtfs 2
@nikreiman
nikreiman / YourProjectName.cpp
Created December 10, 2010 08:52
Code snippits for a VST plugin written for Windows
#include "YourProjectName.h"
AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {
return new YourProjectName(audioMaster);
}
YourProjectName::YourProjectName(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, 0, NUM_PARAMS) {
}
YourProjectName::~YourProjectName() {
@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");