Skip to content

Instantly share code, notes, and snippets.

View Fahrni's full-sized avatar

Rob Fahrni Fahrni

View GitHub Profile
fileprivate func displayOptionsViewController() {
guard let optionsViewController = OptionsViewController.create(completionBlock: optionsCompletionHandler) else {
NSLog("Failed to create OptionsViewController, whoops")
return
}
self.show(optionsViewController, sender: nil)
self.optionsViewController = optionsViewController as? OptionsViewController
}
extension OptionsViewController {
class func create(completionBlock: @escaping OptionsCompletionHandler) -> UIViewController? {
let storyboard = UIStoryboard(name: "Options", bundle: nil)
guard let vc =
storyboard.instantiateViewController(withIdentifier:"OptionsViewController") as? OptionsViewController else {
return nil
}
vc.completionBlock = completionBlock
return vc
}
@Fahrni
Fahrni / CCswiftTest.swift
Last active November 20, 2016 19:51
Using Objective-C++ from Swift
func testCreateDeleteMaleCalculate() {
guard let cc = PKMCreatinineClearance(40, height: 75, weight: 70, scr: 1.0, gender: PKMMale) else {
XCTFail("Create Creatinine Clearance Male Instance failed")
return
}
let clcr = cc.calculate()
XCTAssertEqualWithAccuracy(clcr, 97.2, accuracy: 0.2, "Male clcr should be around 97.2, range allowed to be +/- 0.2")
}
@Fahrni
Fahrni / CCbridgeCode.mm
Created November 20, 2016 19:34
Objective-C++ bridge to C++ Creatinine Clearance calculation
#import "PKMCreatinineClearance.h"
#import "PKMConvert.h"
#import "CreatinineClearance.h"
@interface PKMCreatinineClearance ()
@property (nonatomic, assign) PKMath::CreatinineClearance* ccInstance;
@end
@implementation PKMCreatinineClearance
@Fahrni
Fahrni / ACLMessageDispatch.cpp
Last active May 28, 2016 06:09
ACL Library Message Dispatch Mechanism
LRESULT ACLWinBase::DispatchMessage
(
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam
)
{
LRESULT lResult(1);
UINT uSubMsg(WM_NULL); // By default this really isn't looked at.
@Fahrni
Fahrni / BaseClassWindowProc.cpp
Last active May 28, 2016 06:00
Base Class Window Procedure
EXTERNC ACLWINCB(LRESULT) ACLWindowDispatchProc
(
IN HWND hWnd,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam
)
{
UNALIGNED ACLWinBase* pWindow = NULL;
PWINMSGHNDLR pHandler = NULL;
@Fahrni
Fahrni / NewSchoolWindowProc.cpp
Last active May 28, 2016 05:41
Window Proc built in C++ using ACL Window Library
static ACLWinMessageMap stcMsgMap[] =
// message sub msg/ctl id message handler method.
//
{ { WM_CREATE, WM_NULL, (PWINMSGHNDLR)&SampleWindow::OnCreate }
, { WM_DESTROY, WM_NULL, (PWINMSGHNDLR)&SampleWindow::OnDestroy }
, { WM_COMMAND, IDM_ABOUT, (PWINMSGHNDLR)&SampleWindow::OnAbout }
, { WM_COMMAND, IDM_EXIT, (PWINMSGHNDLR)&SampleWindow::OnExit }
, { WM_SIZE, WM_NULL, (PWINMSGHNDLR)&SampleWindow::OnResize }
}; // stcMsgMap
@Fahrni
Fahrni / OldSchoolWindowProc.c
Last active May 28, 2016 05:30
Old school Window Procedure
LRESULT CALLBACK WindowProc
(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
switch (message)
{
static void FizzBuzz()
{
static int kBufferMax = 256;
char outputBuffer[kBufferMax];
for (int x = 1; x <= 100; x++)
{
memset(&outputBuffer, 0, kBufferMax);
if (0 == (x % 3))