Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon graetzer

View GitHub Profile
@graetzer
graetzer / client.cpp
Created Apr 16, 2018
C++ Simple HTTP Client
View client.cpp
/// 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 Jun 8, 2017
Benchmark Arango Geo index
View aql-geo-test.js
/*jshint globalstrict:false, strict:false, maxlen: 500 */
/*global assertEqual */
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for query language, geo queries
///
/// @file
///
/// DISCLAIMER
///
@graetzer
graetzer / build.sh
Last active May 6, 2021
PJSIP 2.6 iPhone iOS 9.0 build script
View build.sh
#!/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 Sep 19, 2014
Provides HKDF with sha256 as hash function
View hdkf.m
#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 Aug 29, 2015
Extract modulus and exponent from public key
View key_parts.m
// 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 Aug 29, 2015
Generate keys from passwords using PBKDF2-HMAC-SHA256
View pbkdf2_hmac_sha256.m
#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 Dec 15, 2013
404 - The requested document is no more
View gist:7972341
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 Apr 19, 2012
Android FragmentTabsPager with Actionbarsherlock
View ActionbarTabsPager.java
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;