Skip to content

Instantly share code, notes, and snippets.

View mingsai's full-sized avatar
🎯
Focusing

Tommie N. Carter, Jr. mingsai

🎯
Focusing
View GitHub Profile
@bddckr
bddckr / Assertions.h
Last active December 19, 2015 07:59
Assertion macro that works exactly like NSAssert(), with the modification that a code block will be run if the condition is not met. Helps a lot to prevent repetitions when handling the condition a second time for release code (NSAssert will be stripped by default.) Thanks to @ merowing_ for https://gist.github.com/krzysztofzablocki/5921645 !
// See http://stackoverflow.com/a/257424/283482
// Normally a "do {…} while (0)" is used to prevent the problem described in the linked answer,
// but this would prevent us from using "continue" or "break" in the block parameter.
// The problem is fixed thanks to the "if (1) {…}", doing the same as the "do {…} while (0)".
#define AssertTrueOrRunBlock(condition, block, description, ...)\
if (1) {\
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS\
BOOL check = !!(condition);\
NSCAssert(check, (description), ##__VA_ARGS__);\
import Foundation
struct Builder {
typealias Attributes = Dictionary<String, AnyObject>
typealias Block = () -> ()
typealias Visitor = (Node) -> ()
class Node {
var name : String
var parent: Node? { didSet { level = parent!.level + 1} }
@JadenGeller
JadenGeller / Swift Callback.swift
Last active February 12, 2016 13:37
Swift Callback Function Transformation
/*
* Takes in a function that transform T to U and
* a callback that takes arguments of type T and U
* and returns a function that performs f but calls
* the callback before returning
*/
func callback<T,U>(f: T -> U, c: (T, U) -> ()) -> T -> U{
return { x in
let r = f(x)
c(x,r)
@jlindsey
jlindsey / gist:499392
Created July 29, 2010 22:10
Example of GCD
- (void)writeData:(NSData *)data toOutputStream:(NSOutputStream *)stream {
dispatch_async(dispatch_get_current_queue(), ^(void){
BOOL sent = NO;
do {
if (outputStreamReady) {
outputStreamReady = NO;
uint8_t *readBytes = (uint8_t *)[data bytes];
int data_len = [data length];
@shepting
shepting / YMKeyboardLayoutHelperView.m
Last active March 22, 2016 02:50
A great little helper for handling keyboard animations nicely. Just put this view at the bottom vertically of your views and it will move everything else up and down for you.
//
// YMKeyboardLayoutHelperView.m
// ios-chat
//
// Created by Steven Hepting on 7/17/13.
// Copyright (c) 2013 Yammer. All rights reserved.
//
#import "YMKeyboardLayoutHelperView.h"
#import "UIView+LayoutAdditions.h"
@gitbricho
gitbricho / file01_01.swift
Last active May 7, 2016 10:44
swift 2.1 ファイル
import UIKit
//## iOS:ファイルシステム #####
//標準ディレクトリ ( Documents/, Library/, tmp/ ... )
//## OS X:ファイルシステム #####
//ローカルドメイン ( Applications/Utilities, Developer/, Library/ )
//ユーザードメイン ( Users/user1, ... )
//ファイルまたはディレクトリのパス
@frr149
frr149 / transparentModalViewController.m
Created October 20, 2011 18:58
How to create a transparent modal View Controller
#pragma mark - Transparent Modal View
-(void) presentTransparentModalViewController: (UIViewController *) aViewController
animated: (BOOL) isAnimated
withAlpha: (CGFloat) anAlpha{
self.transparentModalViewController = aViewController;
UIView *view = aViewController.view;
view.opaque = NO;
view.alpha = anAlpha;
@galiak11
galiak11 / Query.swift
Last active September 1, 2016 17:23
Swift CoreData Query API
import Foundation
import CoreData
/**
Query: this is a Swift Query API for CodeData.
Usage example:
// fetch multiple rows
let people = Query("Person").whereEqual( "lastName", lastName ).sort( "name" ).fetch()
@venkatperi
venkatperi / gist:209b9fa2946a7151efc0
Created June 4, 2014 15:53
Closure Currying in Swift
struct S0<V> {
typealias F = () -> V
}
struct S1<T1,V>{
typealias F = (T1) -> V
}
//0, 0
func curry<T1, V>(f: S1<T1, V>.F, a1:T1) -> S0<V>.F {
import Firebase from 'firebase';
import Promise from 'bluebird';
import {ValidationError} from './lib/validation';
import {firebaseCursor} from './state';
// if (!process.env.IS_BROWSER) {
// // TODO: Set Firebase for server.
// }
export const TIMESTAMP = Firebase.ServerValue.TIMESTAMP;