Skip to content

Instantly share code, notes, and snippets.

View churchofthought's full-sized avatar
🪐
Universe simulations and whatnot.

Church of Thought churchofthought

🪐
Universe simulations and whatnot.
View GitHub Profile
@churchofthought
churchofthought / gist:5202041
Last active October 23, 2017 13:25 — forked from anonymous/gist:5202029
Y Combinator Explained
I just finally had my mind snap into place with understanding of the Y Combinator. Most explanations I read, even the ones using JS, didn't make much sense and were overly long so here follows my own, much simpler explanation. I will be using JS.
We have fibonacci to start with, very simple recursive function.
It's fixed points are 0 and 1, fib(0) = 0, and fib(1) = 1
That's all a fix point means, when the f(x) == x
They are important because they are the only values at which recursion can cease.
Our Fibonacci Function
======================
@churchofthought
churchofthought / YCombinatorCurrySauce.txt
Last active May 20, 2017 14:50
Y Combinator Explained
I just finally had my mind snap into place with understanding of the Y Combinator.
Most explanations I read, even the ones using JS, didn't make much sense and were
overly long so here follows my own, much simpler explanation. I will be using JS.
We have fibonacci to start with, very simple recursive function.
It's fixed points are 0 and 1, fib(0) = 0, and fib(1) = 1
That's all a fix point means, when the f(x) == x
They are important because they are the only values at which recursion can cease.
AsyncBlockOperation is very similar to NSBlockOperation with one caveat; the block you pass to it receives one argument, a reference to the AsyncBlockOperation for the block. When your block is done with its task, it must call [op complete]
Example usage:
NSOperation* asyncOp = [AsyncBlockOperation blockOperationWithBlock:^(AsyncBlockOperation* op) {
NSLog(@"starting op");
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
@churchofthought
churchofthought / FunctionalOR.README.txt
Last active December 16, 2015 19:39
Functional OR for Objective C.
NSLog(@"%@", OR(nil,@"", @{@"foo": @"bar"}, @[]));
// outputs {foo = bar;}
NSLog(@"%@", OR(nil,@"", @{}, @[]));
// outputs []
NSLog(@"%@", OR(nil,@"", @[], @"", @{}));
// outputs {}
NSLog(@"%@", OR(nil,@"", @[], @"", nil));
@churchofthought
churchofthought / gist:5520044
Created May 5, 2013 07:41
Non-coalescing OR macro for variable arguments and variable types including objects/primitives.
#ifndef XIBXOR_OR
//
// XXOr.h
//
// Created by XibXor on 5/5/13.
//
// Non-coalescing OR macro for variable arguments and variable types including objects/primitives.
// Similar to || behavior in ECMAScript
//
// Usage: OR(a,b,...)
@churchofthought
churchofthought / XXOr.h
Last active December 17, 2015 00:19
Non-coalescing OR macro for variable arguments and variable types including objects/primitives.
//
// XXOr.h
//
// Created by XibXor on 5/5/13.
//
// Non-coalescing OR macro for variable arguments and variable types including objects/primitives.
// Similar to || behavior in ECMAScript
//
// Usage: OR(a,b,...)
//
@churchofthought
churchofthought / gist:5520574
Last active December 17, 2015 00:19
improved 8-byte strrev
void strrev(char *strStart, const int len){
char* strEnd = strStart + len;
while (strStart <= (strEnd -= 8)){
__uint64_t buf = *(__uint64_t*)strStart;
*(__uint64_t*)strStart = *(__uint64_t*)strEnd;
__asm__ ("bswap %0" : "=r" (*(__uint64_t*)strStart) : "0" (*(__uint64_t*)strStart));
comment *==========================================
jagHook
Note that:
macros are like win32 api; they may modify all registers but ebx, edi, esi
your .text section needs to be writable if using the non-procedural hooking
if using radasm, add /SECTION:.text|RWE the LINK box under Project -> Project Options]
otherwise, just add /SECTION:.text,RWE to linking arguments
@churchofthought
churchofthought / jagHook.asm
Created June 10, 2013 23:01
x86 Hooking Library written in MASM
comment *==========================================
jagHook by jAgx
Note that:
macros are like win32 api; they may modify all registers but ebx, edi, esi
your .text section needs to be writable if using the non-procedural hooking
if using radasm, add /SECTION:.text|RWE the LINK box under Project -> Project Options]
otherwise, just add /SECTION:.text,RWE to linking arguments
@churchofthought
churchofthought / gist:5753292
Created June 10, 2013 23:17
x86 hooking/detours macros and procedures written in MASM
comment *==========================================
jagHook
Note that:
macros are like win32 api; they may modify all registers but ebx, edi, esi
your .text section needs to be writable if using the non-procedural hooking
if using radasm, add /SECTION:.text|RWE the LINK box under Project -> Project Options]
otherwise, just add /SECTION:.text,RWE to linking arguments