Skip to content

Instantly share code, notes, and snippets.

@tjhv
tjhv / viewControllerLoader.m
Created February 17, 2018 05:20
View controller loader
//convenient method when working with nibs..
//should be used within a view controller subclass
//name your nib the same as your view controller class name
//this will load it given it's in the main bundle, and
//it will append a child to the view in context (inView:)
//if view is nil, obviously it will not add a subview
//but the view controller will still be added as a child.
//did not bother to implement as a UIViewController category,
//minor error testing but worked without issue for my intended use.
@tjhv
tjhv / list.c
Created February 17, 2018 05:19
Rough implementation of the linked list data structure with functions to help visualize the memory layout and check integrity of linkage.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#undef DEBUG_VERBOSE
void debug_print(char *fmt, ...)
@tjhv
tjhv / senddgram.c
Created February 17, 2018 05:16
Old snippet from back in the day.
//Jan 4 2009
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int send_datagram(char* dstaddr, int dstport, char* buffer) {
@tjhv
tjhv / select.c
Last active February 17, 2018 05:15
Select() with callbacks per event
#include <sys/select.h>
#include <stdio.h>
#include <stdlib.h>
void fd_set_v2(unsigned int fd,
fd_set *fds,
unsigned int *max_fd)
{
if(!(fds && max_fd)) return;
@tjhv
tjhv / simplesort.c
Last active February 17, 2018 05:10
Example of sorting by ASCII char code
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define ASIZE 50
char arr[(ASIZE + 1)];
bool k_cmp_chr(char c1, char c2)
{
@tjhv
tjhv / inheritance.c
Created February 17, 2018 05:08
Mock inheritance in C
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
typedef void * (* class_ctor_t)(void *);
typedef struct Class Class_t;
typedef struct ClassImpl
@tjhv
tjhv / serial.js
Last active February 17, 2018 05:05
Stream wrapper for vanilla node.js tty/serial coms
'use strict';
const stream = require('stream');
const fs = require('fs');
const tty = require('tty');
const util = require('util');
//use node.js' child process to spawn and set baudrates