Skip to content

Instantly share code, notes, and snippets.

@deltheil
deltheil / align.c
Last active March 24, 2018 07:51
ARM: unaligned memory access (EXC_ARM_DA_ALIGN)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define DEREFENCE_MODE 1
#define IS_ALIGNED(P_tr) \
(((uintptr_t) (P_tr) & 3) == 0 ? "YES" : "NO")
@deltheil
deltheil / c-ares.sh
Created December 12, 2012 22:32
Android NDK: build c-ares w/ the Standalone Toolchain
export NDK=/tmp/android-ndk-r8b
# Create the standalone toolchain
$NDK/build/tools/make-standalone-toolchain.sh \
--platform=android-9 \
--install-dir=/tmp/my-android-toolchain
export PATH=/tmp/my-android-toolchain/bin:$PATH
export SYSROOT=/tmp/my-android-toolchain/sysroot
export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT"
@deltheil
deltheil / gist:4344175
Created December 20, 2012 09:37
Apple platform types
# Taken from https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m
iFPGA -> ??
iPhone1,1 -> iPhone 1G, M68
iPhone1,2 -> iPhone 3G, N82
iPhone2,1 -> iPhone 3GS, N88
iPhone3,1 -> iPhone 4/AT&T, N89
iPhone3,2 -> iPhone 4/Other Carrier?, ??
iPhone3,3 -> iPhone 4/Verizon, TBD
@deltheil
deltheil / bsearch.c
Last active February 7, 2022 00:59
qsort and bsearch over an array of pointers
#include <stdio.h>
#include <stdlib.h>
struct foo {
int count;
const char *misc;
};
typedef struct foo * pfoo;
@deltheil
deltheil / snprintf.c
Created March 7, 2013 09:41
Format C string with length pre-computation.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
static char *mysprintf(const char *format, ...);
int main(void) {
char *str = mysprintf("%s fmt with various values: PI ~= %.2f", "Test", 3.14);
printf("%s (len = %zd)\n", str, strlen(str));
@deltheil
deltheil / msgpack.c
Last active June 7, 2022 21:03
Pack / unpack some structs with C msgpack - see http://stackoverflow.com/a/15405794/1688185
#include <stdio.h>
#include <assert.h>
#include <msgpack.h>
typedef struct some_struct {
uint32_t a;
uint32_t b;
float c;
} some_struct;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
const char *g_progname;
const char *g_name;
struct seq {
int *vals;
int size;
@deltheil
deltheil / astr.c
Created March 25, 2013 09:48
Append character strings with asprintf(3)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static int append(char **str, const char *buf, int size);
int main(void) {
char *str = NULL;
append(&str, "this", 4);
append(&str, " is", 3);
@deltheil
deltheil / gist:5661675
Last active December 17, 2015 19:39
Split in two parts, chop and join a transparent button image with ImageMagick.
#!/bin/sh
function split { # file, target_size
_w=$(identify -format "%w" $1)
_dx=$(( ($_w - $2) / 2 ))
convert $1 -crop 50%x100% +repage parts.png
convert parts-0.png -gravity East -chop ${_dx}x0 left.png
convert parts-1.png -gravity West -chop ${_dx}x0 right.png
montage -background none left.png right.png -mode Concatenate -tile x1 out.png
rm parts*.png left.png right.png
}
@deltheil
deltheil / gist:6037656
Created July 19, 2013 08:38
VLC for iOS: upload via WiFi
curl -# -F file=@"foo.mov" http://192.168.0.38:8888/upload.json >/dev/null