Skip to content

Instantly share code, notes, and snippets.

View draganglumac's full-sized avatar

Dragan Glumac draganglumac

  • Glued IT Consulting Limited
  • London, UK
View GitHub Profile
@draganglumac
draganglumac / run_tests
Created May 15, 2015 13:31
Ideas for conditional flag when running jnxlibc tests
#!/bin/bash
OS=`uname`
if [ "$OS" == "Darwin" ]; then
echo "Building with Clang"
COMPILER=clang
else
echo "Building with GCC"
COMPILER=gcc
fi
function echo_red()
@draganglumac
draganglumac / pthread_conditionals.c
Created February 16, 2015 21:08
Example of blocking and signaling via pthread conditionals.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define NUM_THREADS 3
#define TCOUNT 10
#define COUNT_LIMIT 12
int count = 0;
/*
* =====================================================================================
*
* Filename: jnxguid.c
*
* Description:
*
* Version: 1.0
* Created: 26/01/2015 21:16:23
* Revision: none
@draganglumac
draganglumac / gist:4dfeb8c0f57c5fa08d73
Created January 27, 2015 09:18
GUID to string (decimal and hex)
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
uint8_t guid[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
size_t size = sizeof guid;
char dbuffy[49] = {};
for (int j = 0; j < size; j++) {
// If you have two functions that traverse the list in slightly
// different manner
//
// First function:
void traverse_1(list *A) {
list *head = A->head;
while (A->head != NULL)
A->head = A->head->next;
A->head = head;
}
@draganglumac
draganglumac / gist:6af4f5890c3511d71b14
Last active August 29, 2015 14:02
Shifty solution
uint8_t* jnx_encoder_b64_encode(jnx_encoder *e,uint8_t *data, size_t input_length, size_t *output_length) {
JNXCHECK(data);
JNXCHECK(input_length);
*output_length = 4 * ((input_length + 2) / 3);
uint8_t *encoded_data = malloc(((*output_length) +1) * sizeof (char));
if (encoded_data == NULL) return NULL;
int i,j;
for ( i = 0, j = 0; i < input_length; i += 3) {