Skip to content

Instantly share code, notes, and snippets.

View graetzer's full-sized avatar

Simon graetzer

View GitHub Profile
@graetzer
graetzer / client.cpp
Created April 16, 2018 01:36
C++ Simple HTTP Client
/// Copyright 2018 Simon Grätzer
#include "client.h"
#include "defer.h"
#include <http_parser.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
@graetzer
graetzer / aql-geo-test.js
Created June 8, 2017 19:25
Benchmark Arango Geo index
/*jshint globalstrict:false, strict:false, maxlen: 500 */
/*global assertEqual */
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for query language, geo queries
///
/// @file
///
/// DISCLAIMER
///
@graetzer
graetzer / build.sh
Last active November 2, 2023 08:20
PJSIP 2.6 iPhone iOS 9.0 build script
#!/bin/bash
echo "Building pjsip:"
# change this to whatever DEVPATH works
# if you get make errors, maybe redownload pjsip and try again
export DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
MIN_IOS="-miphoneos-version-min=9.0" ARCH="-arch i386" CFLAGS="-O2 -m32 -mios-simulator-version-min=9.0 -fembed-bitcode" LDFLAGS="-O2 -m32 -mios-simulator-version-min=9.0 -fembed-bitcode" ./configure-iphone
@graetzer
graetzer / hdkf.m
Created September 19, 2014 22:25
Provides HKDF with sha256 as hash function
#import <CommonCrypto/CommonCrypto.h>
// ...
NSData * HKDF_SHA256(NSData *seed, NSData *info, NSData *salt, int outputSize) {
char prk[kCCHmacAlgSHA256] = {0};
CCHmac(CC_SHA256_DIGEST_LENGTH, [salt bytes], [salt length], [seed bytes], [seed length], prk);
int iterations = (int)ceil((double)outputSize/(double)CC_SHA256_DIGEST_LENGTH);
NSData *mixin = [NSData data];
NSMutableData *results = [NSMutableData data];
@graetzer
graetzer / key_parts.m
Last active August 29, 2015 14:06
Extract modulus and exponent from public key
// Create the keys with SecKeyGeneratePair
// Look at https://developer.apple.com/library/ios/samplecode/CryptoExercise/Introduction/Intro.html
NSData* keyData = [self _getPublicKeyBits];
NSLog(@"Public Key: %@", [keyData hexadecimalString]);
// http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One#Example_encoded_in_DER
const char *buffer = keyData.bytes;
NSData* modulus;
NSData* exponent;
// Check for correct ASN.1 DER start
@graetzer
graetzer / pbkdf2_hmac_sha256.m
Last active August 29, 2015 14:05
Generate keys from passwords using PBKDF2-HMAC-SHA256
#import <CommonCrypto/CommonCrypto.h>
// ...
// http://www.opensource.apple.com/source/OpenSSL/OpenSSL-12/openssl/crypto/evp/p5_crpt2.c
// This is the method specified by RSA's PKCS #5 standard.
// Compatible to https://github.com/bitwiseshiftleft/sjcl/blob/master/core/pbkdf2.js
NSData * PBKDF2_HMAC_SHA256(NSData *data,NSData *salt, int iter, int keylen) {
unsigned char digtmp[CC_SHA256_DIGEST_LENGTH], *p, *buffer, itmp[4];
NSInteger cplen, j, k, tkeylen;
@graetzer
graetzer / gist:7972341
Created December 15, 2013 12:22
404 - The requested document is no more
var tl=new Array(
"The requested document is no more.",
'No file found.',
"Even tried multi.",
"Nothing helped.",
"I'm really depressed about this.",
"You see, I'm just a web server...",
"-- here I am, brain the size of the universe,",
"trying to serve you a simple web page,",
@graetzer
graetzer / ActionbarTabsPager.java
Created April 19, 2012 21:39
Android FragmentTabsPager with Actionbarsherlock
import java.util.ArrayList;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;