Skip to content

Instantly share code, notes, and snippets.

View jorgenpt's full-sized avatar

Jørgen Tjernø jorgenpt

View GitHub Profile
@jorgenpt
jorgenpt / SaneMinMaxMacros.h
Last active September 1, 2023 09:04
An attempt at some saner min-max-clamp macros for C and Objective-C. Require a modern compiler (C11) with support for statement expressions (Gnu11).
#pragma once
#define _CheckTypes(a,b) _Static_assert(_Generic(a, typeof (b):1, default: 0), "Mismatched types")
#define Min(a,b) \
({ \
const typeof (a) _a = (a); \
const typeof (b) _b = (b); \
_CheckTypes(_a,_b); \
(_a < _b ? _a : _b); \
@jorgenpt
jorgenpt / assert_ndk_version.sh
Last active February 21, 2023 06:05
Shell script to check for Android NDK version.
#!/bin/bash
# Bash script to assert that the current version of the NDK is at least the
# specified version. Prints 'true' to standard out if it's the right version,
# 'false' if it's not.
#
# Typically used like this, in your jni/Android.mk:
#
# ifneq ($(shell $(LOCAL_PATH)/assert_ndk_version.sh "r5c"),true)
# $(error NDK version r5c or greater required)
@jorgenpt
jorgenpt / assert_sdk_version.sh
Created June 5, 2012 23:27
Shell script to check for Android SDK version.
#!/bin/bash
# Bash script to assert that the current version of the SDK is at least the
# specified version. Prints 'true' to standard out if it's the right version,
# 'false' if it's not.
#
# Typically used like this, in your Makefile:
#
# ifneq ($(shell $(LOCAL_PATH)/assert_sdk_version.sh "r16"),true)
# $(error SDK version r16 or greater required)
@jorgenpt
jorgenpt / TextProgressBar.cs
Last active April 2, 2020 03:27
Text based progress bar for C#
using System;
using System.Collections.Generic;
namespace JPT
{
public class TextProgressBar : IDisposable
{
private int _progress;
private int _total;
private int _width;
@jorgenpt
jorgenpt / ksdiff-batch.sh
Last active October 9, 2019 18:24
Batches multiple invocations of ksdiff to open in a single Kaleidoscope window if they happen within a few seconds of eachother. This is useful for Kaleidoscope integration with P4V, since it makes a multi-file diff open in a single window. If it doesn't quite pick up all your files, try setting TIMEOUT to more than 4 seconds.
#!/bin/bash
# Number of seconds we wait after a file is received before we consider the
# batch to be completed.
TIMEOUT=2
# Title of the tab in Kaleidoscope
LABEL="P4V ksdiff-batch"
# FIFO we communicate with the "batch master" for.
fifo="/tmp/ksdiff-batch-$USER"
@jorgenpt
jorgenpt / stream.sh
Created April 21, 2012 06:59
Commands to stream desktop to justin.tv on OS X
#!/bin/sh -xe
API_KEY="YOUR_API_KEY_GOES_HERE"
FPS="10"
VLC_PATH="/Applications/VLC.app/Contents/MacOS/VLC"
# I don't know how this'll behave on multimon, so you might want to hard-code.
# INRES='1440x900'
INRES=$(osascript -e 'tell application "Finder" to get bounds of window of desktop'|sed 's/, /x/g'|cut -f3- -dx)
OUTRES='1280x800'
# You can change this to record microphone or something else, from man soxformat (under coreaudio):
checking for FRIBIDI... configure: error: Package requirements (fribidi >= 0.19.0) were not met:
No package 'fribidi' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables FRIBIDI_CFLAGS
and FRIBIDI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
#!/bin/bash
DIR=$(cd "$(dirname "$0")"; pwd)
MONO=`which mono`
if [ ! -z "$MONO" ]; then
TXT=`${MONO} -V`
VERSION="${TXT#"${TXT%%[[:digit:]]*}"}"
VERSION="${VERSION%%[^[:digit:].]*}"
VERSION="${VERSION//[!0-9\.]/}"
fi
@jorgenpt
jorgenpt / HTTPSCertificateRetriever.h
Last active December 27, 2015 00:59
Utility class to retrieve HTTPS certificates from a server.
#import <Foundation/Foundation.h>
@protocol HTTPSCertificateRetrieverDelegate <NSObject>
/**
* Called when we succeed (or fail) to retrieve the certificate.
*
* @param certificate nil if we fail, otherwise the data of the certificate.
*/
- (void)certificateRetrieved:(NSData*)certificate;
@jorgenpt
jorgenpt / gist:6589639
Created September 17, 2013 03:09
Remove the "Command-T" hotkey in Finder, which normally is "Add to Sidebar"
defaults write com.apple.finder NSUserKeyEquivalents -dict-add "Add to Sidebar" nil