Skip to content

Instantly share code, notes, and snippets.

@akisute
akisute / MainActivity.java
Last active August 29, 2015 14:15
Hello, Android Wear!
public class MainActivity extends Activity {
@InjectView(R.id.text)
TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Object activity = this;
@akisute
akisute / gist:ee17463f862a334731c4
Created February 3, 2015 05:55
TaskToken to cancel running tasks with BFTask
- (BFTask *)loadSomeDataWithToken:(TaskToken *)token
{
BFTask *getSomeDataTask;
BFTask *getOtherDataTask;
getSomeDataTask = [[APIClient sharedClient] withToken:token executeAPI:^BFTask *(APIClient *client) {
return [[client getSomeDataWithParameters:@{}] continueWithSuccessBlock:^id(BFTask *task) {
// TODO: do something
return task;
}];
}];
@akisute
akisute / SomeWebViewController.m
Last active July 27, 2018 04:27
Dismissing fullscreen movie player from <video> tag in UIWebView with animation and completion handler
/*
WARNING: PRIVATE API CALLS
WARNING: FORCEFUL MEMORY MANAGEMENT
highly recommend to avoid using this code
*/
- (void)exitFullScreenVideo:(BOOL)animated completion:(void (^)(void))completion
{
/*
iOS 6~7の場合
本ViewControllerの上にMPInlineVideoFullscreenViewControllerがfullscreen modalで表示されるような挙動になるので
@akisute
akisute / SomeWebViewController.m
Last active July 30, 2018 01:56
Dismissing fullscreen movie player from <video> tag in UIWebView
- (void)exitFullScreenVideo
{
// Works in iOS, not sure in OS X
[self.webView stringByEvaluatingJavaScriptFromString:@"Array.prototype.forEach.call(document.getElementsByTagName('video'),function(v){v.webkitExitFullscreen();});"];
// Didn't work in iOS, works in OS X
[self.webView stringByEvaluatingJavaScriptFromString:@"if(document.webkitFullscreenElement){document.webkitExitFullscreen();}"];
}
@akisute
akisute / Sample.m
Created January 15, 2015 10:54
How to use RACObserve in Swift
// Objective-C
@interface Document: NSObject
@property (nonatomic, copy) NSArray *notes;
@property (nonatomic, readonly) RACSignal *notesUpdatedSignal;
@end
@implementation Document
- (RACSignal *)notesUpdatedSignal
{
// In Objective-C, just simply use RACObserve
import Foundation
public class JSON {
private let _value:AnyObject
public init(_ obj:AnyObject) { self._value = obj }
public init(_ json:JSON){ self._value = json._value }
}
import Foundation
public class JSONObject {
public struct Error {
public enum Element: Equatable {
case Index(Int)
case Key(String)
}
// Created by Ullrich Schäfer on 16/08/14.
// Updated by Masashi Ono (akisute) on 26/12/14.
//
// Tested on CocoaLumberjack 2.0.0 rc
//
// CocoaLumberjack now officially supports Swift (https://github.com/CocoaLumberjack/CocoaLumberjack/blob/2.0.0-rc/Classes/CocoaLumberjack.swift),
// but both the current CocoaPods (0.35) with 2.2.0 rc doesn't support Swift yet.
// We got to workaround this by installing CocoaLumberjack.swift manually.
// I recommend you to use the official CocoaLumberjack.swift instead of this hack.
- (void)removeViewController:(BOOL)animated
{
CGRect destInitialFrame = self.destinationFrame;
CGRect destFinalFrame = CGRectMake(CGRectGetMaxX(destInitialFrame),
CGRectGetMinY(destInitialFrame),
CGRectGetWidth(destInitialFrame),
CGRectGetHeight(destInitialFrame));
UIViewController *srcViewController = self.sourceViewController;
UIViewController *destViewController = self.destinationViewController;
- (void)addViewController:(BOOL)animated
{
CGRect destFinalFrame = self.destinationFrame;
CGRect destInitialFrame = CGRectMake(CGRectGetMaxX(destFinalFrame),
CGRectGetMinY(destFinalFrame),
CGRectGetWidth(destFinalFrame),
CGRectGetHeight(destFinalFrame));
UIViewController *srcViewController = self.sourceViewController;
UIViewController *destViewController = self.destinationViewController;