Skip to content

Instantly share code, notes, and snippets.

@deltheil
deltheil / gist:2888680
Created June 7, 2012 12:57
moreutils (errno): auto-generated errno-s header file via the preprocessor
# Taken from http://joeyh.name/code/moreutils/ Makefile
# See http://blog.liw.fi/posts/errno/ for all the details about `errno` CLI tool
errno.o: errnos.h
errnos.h:
echo '#include <errno.h>' > dump.c
$(CC) -E -dD dump.c | awk '/^#define E/ { printf "{\"%s\",%d},\n", $$2, $$3 }' > errnos.h
rm -f dump.c
# On errno.c side this auto-generated header is used as follow
# --
@deltheil
deltheil / gist:2916633
Created June 12, 2012 09:54
JPEG images: EXIF orientation
# 1/ Read EXIF orientation flag
identify -format "%[EXIF:orientation]" myimage.jpg
# NOTE: jhead can be used too
# see http://www.sentex.net/~mwandel/jhead/
jhead -exifmap myimage.jpg | grep Ori
# 2/ Remove EXIF orientation
# i.e. rotate the image accordingly and reset the orientation
# flag to 1 (default, i.e. origin = TopLeft)
@deltheil
deltheil / gist:2960752
Created June 20, 2012 16:19
Xcode xcrun command-line tools examples
# Find the right Clang path for iOS cross-compilation
xcrun -sdk iphoneos -find clang
# Pick the right tool and run the command (here list #define-s)
xcrun -sdk iphoneos clang -E -dM - < /dev/null
@deltheil
deltheil / b64.c
Created July 28, 2012 14:26
base64url without padding decoding (with TC)
/**
* How to use it
* --
* brew install tokyo-cabinet
* clang -o b64 b64.c -Wall -Werror -I/usr/local/include -L/usr/local/lib -ltokyocabinet
* ./b64
* ./b64 Zm9v
*/
#include <stdio.h>
@deltheil
deltheil / gist:3788263
Created September 26, 2012 14:07
clang -arch armv7 vs. armv7s
--- armv7.txt 2012-09-26 16:03:39.000000000 +0200
+++ armv7s.txt 2012-09-26 16:03:45.000000000 +0200
@@ -3,8 +3,9 @@
#define __APPLE_CC__ 5621
#define __APPLE__ 1
#define __ARMEL__ 1
-#define __ARM_ARCH_7A__ 1
+#define __ARM_ARCH_7S__ 1
#define __ARM_NEON__ 1
+#define __ARM_VFPV4__ 1
@deltheil
deltheil / jparse.c
Created September 27, 2012 12:51
Checking parsing error with json-parser (https://github.com/udp/json-parser/)
#include <stdio.h>
#include <string.h>
#include <json-parser/json.h>
int main(int argc, char *argv[]) {
char *str[] = { "{\"foo\": \"bar\"}" /* ok */, "{\"foo\": \"bar}" /* ko */ };
for (int i = 0; i < 2; i++) {
json_settings settings;
memset(&settings, 0, sizeof(json_settings));
@deltheil
deltheil / jsmn.sh
Created October 4, 2012 20:25
Android NDK basic example: build jsmn C parser w/ the Standalone Toolchain
# 1. Use the tools from the Standalone Toolchain
export PATH=/tmp/my-android-toolchain/bin:$PATH
export SYSROOT=/tmp/my-android-toolchain/sysroot
export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT"
export AR=arm-linux-androideabi-ar
# 2. Clone the Github mirror
git clone git://github.com/noct/jsmn.git; cd jsmn
# 3. Build for the ARMv7 ABI
@deltheil
deltheil / argcheck.lua
Created November 12, 2015 16:56
Playing with torch/argcheck
require 'torch'
local argcheck = require 'argcheck'
local env = require 'argcheck.env'
function env.istype(obj, typename)
if typename == 'torch.Tensor' then
-- could also check the storage type!
return torch.isTensor(obj)
else
@deltheil
deltheil / info.c
Created November 25, 2015 13:07
Check if libcurl was built with async DNS support
#include <stdio.h>
#include <curl/curl.h>
int
main(void)
{
curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
printf("async DNS: %d\n", !!(info->features & CURL_VERSION_ASYNCHDNS));
return 0;
}
@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