Skip to content

Instantly share code, notes, and snippets.

View jslegendre's full-sized avatar

Jeremy Legendre jslegendre

  • Alpine Machine Company
  • Xcode
View GitHub Profile
@jslegendre
jslegendre / argToCFString.c
Created February 3, 2018 05:18
Create CFString from CLI arguments in C
/***************************
Compile with:
gcc -framework CoreFoundation
****************************/
#include <CoreFoundation/CoreFoundation.h>
int main(int argc, char** argv) {
CFStringRef myCFString = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingMacRoman);
/* Use myCFString */
@jslegendre
jslegendre / class_printMethods.m
Created January 13, 2018 00:27
Print all methods of a class
void class_printMethods(Class cl) {
unsigned int methodCount = 0;
Method *methods = class_copyMethodList(cl, &methodCount);
printf("Methods for %s: \n", class_getName(cl));
for (int i = 0; i < methodCount; i++) {
Method method = methods[i];
printf("%s : %s \n",
sel_getName(method_getName(method)),
method_getTypeEncoding(method));
}
@jslegendre
jslegendre / class_printProperties.m
Created January 13, 2018 00:26
Console log all properties of a class
void class_printProperties(Class cl) {
unsigned int propCount;
objc_property_t *props = class_copyPropertyList(cl, &propCount);
printf("Properties for %s: \n", class_getName(cl));
for (int i = 0; i < propCount; i++) {
objc_property_t prop = props[i];
printf("%s : %s \n",
property_getName(prop),
property_getAttributes(prop));
}
@jslegendre
jslegendre / class_printIvars.m
Created January 13, 2018 00:22
A function to quickly write a list of the instance variables of a class to the console.
void class_printIvars(Class cl) {
unsigned int ivarCount;
Ivar *ivars = class_copyIvarList(cl, &ivarCount);
printf("Ivars for %s: \n", class_getName(cl));
for (int i = 0; i < ivarCount; i++) {
Ivar ivar = ivars[i];
printf("%s : %s \n",
ivar_getName(ivar),
ivar_getTypeEncoding(ivar));
}
@jslegendre
jslegendre / class_getIvarFromString.m
Last active January 13, 2018 00:12
Natively, the objective-c runtime does not have a function to get an instance variable by name so I wrote a function to do so. This works great for inspecting 'concrete' classes.
Ivar class_getIvarFromString(Class cl, NSString *__ivar) {
unsigned int count;
Ivar *ivars = class_copyIvarList(cl, &count);
for (int i = 0; i < count; i++) {
Ivar ivar = ivars[i];
NSString *ivarName = [NSString stringWithUTF8String:ivar_getName(ivar)];
if([ivarName isEqualToString:__ivar]) {
free(ivars);
return ivar;
}
@jslegendre
jslegendre / wavplot.py
Last active November 29, 2017 03:07
WAV to Plot from scratch in Python. I know this can be done using SciPy or various other libraries but I wanted to learn more about wav data so I did this from scratch. Added bonus to doing this myself is that I could specify how accurately I wanted the data to be in order to speed up time on large files. Currently, this only works on 16bit mono…
import os
import sys
import numpy as np
import struct
import warnings
path="sample.wav"
#get the file size in bytes
fileSize=os.path.getsize(path)