Skip to content

Instantly share code, notes, and snippets.

View onmyway133's full-sized avatar
😇
What you don't know is what you haven't learned

Khoa onmyway133

😇
What you don't know is what you haven't learned
View GitHub Profile
@onmyway133
onmyway133 / SimpleCache.m
Last active September 26, 2015 19:47
SimpleCache.m
// CacheItem.h
@interface CacheItem : RLMObject
@property NSString *key;
@property NSData *value;
@end
// CacheItem.m
@implementation CacheItem
@mackuba
mackuba / wwdc15.md
Last active August 6, 2022 17:28
New stuff from WWDC 2015

Here's my own list of the interesting stuff announced during this year's WWDC, collected from the keynotes, various Apple docs, blog posts and tweets.

If you're planning to watch the videos, I really recommend this Mac app that helps you download and watch them: https://github.com/insidegui/WWDC.

OS X El Capitan

http://www.apple.com/osx/elcapitan-preview/

  • split view - two apps side by side on full screen
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

@onmyway133
onmyway133 / TextViewHighlighter.m
Last active February 3, 2019 22:52
TextViewHighlighter
// SO [UITextView - Highlight text with NSBackgroundColor - exclude line breaks](http://stackoverflow.com/questions/26558396/uitextview-text-highlighting-when-the-text-is-centered)
// Source
// TextViewHighlighter.h
#import <Foundation/Foundation.h>
@import UIKit;
@interface TextViewHighlighter : NSObject
@ColinEberhardt
ColinEberhardt / gist:b4bf4e4566ffa88afcda
Created March 20, 2015 08:14
Pipe forward operator and curried free functions = fluent interface
// meet Stringy - a simple string type with a fluent interface
struct Stringy {
let content: String
init(_ content: String) {
self.content = content
}
func append(appendage: Stringy) -> Stringy {
@JadenGeller
JadenGeller / Swift Unless_When.swift
Last active May 21, 2019 16:11
Swift Unless/When
// Basically, these are if and else statements respectively
// without the opposite clause
func when(test: @autoclosure () -> Bool, action: () -> ()) {
if test() { action() }
}
func unless(test: @autoclosure () -> Bool, action: () -> ()) {
if !test() { action() }
}
@n-b
n-b / fp-obj-c.m
Created February 9, 2015 09:28
fp-obj-c
//#!/usr/bin/env objc-run
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
///
/// Typedefs
typedef id (^TargetMethod)(id arg);
@prestonparris
prestonparris / reactjs-conf-2015-notes.md
Last active April 6, 2017 21:32
Notes from the 2015 React.js Conference

Reactjs conf 2015 Notes

  • react native announced

    • Allows you to use react style javascript to target native ios and android, native views, live reloading
    • intro pt1
    • intro pt2
    • facebook groups app uses react native with graphql and relay
  • realtime page tweaking

    • rethink best practices and workflows
  • inmutability is a good idea

@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@steipete
steipete / gist:8df39fea0d39680a7a6b
Last active September 17, 2020 23:24
Hunting down a regression in interface rotation on iOS 8 with multiple windows. (rdar://19592583)
This is the code path that changed the status bar orientation on iOS 7:
* thread #1: tid = 0x698dbf, 0x00085830 WindowRotationIssue`-[AppDelegate application:willChangeStatusBarOrientation:duration:](self=0x7a041f90, _cmd=0x0137a18d, application=0x79e39cc0, newStatusBarOrientation=UIInterfaceOrientationPortraitUpsideDown, duration=0.80000000000000004) + 96 at AppDelegate.m:23, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
* frame #0: 0x00085830 WindowRotationIssue`-[AppDelegate application:willChangeStatusBarOrientation:duration:](self=0x7a041f90, _cmd=0x0137a18d, application=0x79e39cc0, newStatusBarOrientation=UIInterfaceOrientationPortraitUpsideDown, duration=0.80000000000000004) + 96 at AppDelegate.m:23
frame #1: 0x00bb6ab5 UIKit`-[UIApplication setStatusBarOrientation:animationParameters:notifySpringBoardAndFence:] + 242
frame #2: 0x00bfa8e4 UIKit`-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4761
frame #3: 0x00bf9646 UIKit`-[UIWi