Skip to content

Instantly share code, notes, and snippets.

View derekli66's full-sized avatar
🤓
Being.a.nerd()

Chien-Ming (Derek) Lee derekli66

🤓
Being.a.nerd()
View GitHub Profile
@bre7
bre7 / FileMiddlewareWithCache.swift
Created April 6, 2018 03:12
Vapor 3 Middleware to serve files from the public folder and respect Cache-Control headers
import Vapor
/// Services files from the public folder.
public final class FileMiddlewareWithCache: Middleware, Service {
/// The public directory.
/// note: does _not_ end with a slash
let publicDirectory: String
public var webTypes = [MediaType]()
@patricklynch
patricklynch / gist:689525d466c4ada42b8e
Last active October 30, 2021 05:23
The 6 ways to unwrap optionals in Swift 2.0
// The 6 ways to uwnrap optionals in Swift 2.0
//
// Created by Patrick Lynch on 6/28/15.
// Copyright © 2015 Patrick Lynch. All rights reserved.
import Foundation
// 1. Force Unwrapping
// 2. Optional Binding
// 3. Optional Chaining
@rianhunter
rianhunter / call_overhead.c
Last active December 21, 2023 23:25
Indirect vs Direct Function Call Overhead in C/C++
/*
This benchmark shows how indirect function calls have nearly
the same overhead costs as direct function calls.
This is comparing apples to apples, factoring out the savings
due to inlining optimizations that direct calls usually afford.
From this, it seems that inlining and other generic interprocedual
optimizations are the main drivers of direct function call optimization,
not the direct call itself.
@mbigatti
mbigatti / UIView+FirstResponder.swift
Created July 10, 2014 15:40
A classical first responder finder using Swift.
import UIKit
extension UIView {
func currentFirstResponder() -> UIResponder? {
if self.isFirstResponder() {
return self
}
for view in self.subviews {
if let responder = view.currentFirstResponder() {
@stuart11n
stuart11n / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@imoldman
imoldman / NSThread+RunBlock.h
Created February 10, 2014 06:45
handy category for run some block on a NSThread
#import <Foundation/Foundation.h>
@interface NSThread (RunBlock)
- (void)performBlock:(void(^)())block;
- (void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)delay;
@end
ACTION
AD_HOC_CODE_SIGNING_ALLOWED
ALTERNATE_GROUP
ALTERNATE_MODE
ALTERNATE_OWNER
ALWAYS_SEARCH_USER_PATHS
ALWAYS_USE_SEPARATE_HEADERMAPS
APPLE_INTERNAL_DEVELOPER_DIR
APPLE_INTERNAL_DIR
APPLE_INTERNAL_DOCUMENTATION_DIR
@johngraham262
johngraham262 / openx_bash_for_ios
Last active December 9, 2022 02:34
A simple bash script that will open a `.xcworkspace` if it exists in the current directory, otherwise a `.xcodeproj` if it exists, otherwise nothing. It will print the name of the file that is being opened. When using Cocoapods with iOS apps, a second file is created with the `MyProject.xcworkspace` name, alongside the `MyProject.xcproject` file…
# Add the following lines of code to your `~/.bash_profile`,
# and then run `source ~/.bash_profile` to be able to execute
# this from the command line.
openx() {
fileToOpen='';
for file in `find . -maxdepth 1 -name *.xcworkspace`; do
fileToOpen=$file
done
@tkemp
tkemp / PrintASBD.m
Created December 6, 2012 17:08
Print an AudioStreamBasicDescription for a given AUGraph node
-(void) printASBDforNode:(AUNode) node scope:(int) scope bus:(int) bus {
AudioStreamBasicDescription testASBD;
UInt32 asbdSize = sizeof (AudioStreamBasicDescription);
AudioUnit nodeUnit;
AUGraphNodeInfo(_graph, node, NULL, &nodeUnit);
AudioUnitGetProperty(nodeUnit,
kAudioUnitProperty_StreamFormat,
scope,
bus, // bus
@snikch
snikch / gist:3661188
Created September 6, 2012 23:16
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}