Skip to content

Instantly share code, notes, and snippets.

View johnny77221's full-sized avatar

John Hsu johnny77221

  • Shekinah Bread of Life Christian Church
  • Taipei, Taiwan
  • X @johnny77221
View GitHub Profile
NSArray *food = @[
@{
@"name" : @"滄州燒臘",
@"score" : @"50"
},
@{
@"name" : @"Subway",
@"score" : @"80"
},
@{
@johnny77221
johnny77221 / rotation.m
Created November 9, 2015 06:22
rotate code
-(IBAction)startRotation:(id)sender
{
if (rotateTimer) {
[rotateTimer invalidate];
}
rotateTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(rotate) userInfo:nil repeats:YES];
}
-(IBAction)stopRotation:(id)sender
{
@johnny77221
johnny77221 / JHFacebookLogin.h
Created February 19, 2016 07:46
Facebook Login Helper
//
// JHFacebookLogin.h
//
// Created by John Hsu on 2016/2/19.
//
#import <Foundation/Foundation.h>
#import <Accounts/Accounts.h>
#import <Social/Social.h>
@johnny77221
johnny77221 / JHFacebookLogin.m
Created February 19, 2016 07:47
Facebook Login Helper
//
// JHFacebookLogin.m
//
// Created by John Hsu on 2016/2/19.
//
#import "JHFacebookLogin.h"
@implementation JHFacebookLogin
@synthesize accountStore, facebookAccount, handler;
@johnny77221
johnny77221 / openBLESetting
Created October 24, 2016 07:07
opening iOS BLE setting from app
NSURL *bluetoothURLOS8 = [NSURL URLWithString:@"prefs:root=General&path=Bluetooth"];
NSURL *bluetoothURLOS9 = [NSURL URLWithString:@"prefs:root=Bluetooth"];
NSURL *bluetoothURLOS10 = [NSURL URLWithString:@"Prefs:root=Bluetooth"];
if ([[[UIDevice currentDevice] systemVersion] intValue] >= 10) {
Class<NSObject> workSpaceClass = NSClassFromString(@"LSApplicationWorkspace");
if (workSpaceClass) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
id workSpaceInstance = [workSpaceClass performSelector:NSSelectorFromString(@"defaultWorkspace")];
SEL selector = NSSelectorFromString(@"openSensitiveURL:withOptions:");
@johnny77221
johnny77221 / Storage.swift
Last active June 15, 2018 00:31 — forked from saoudrizwan/Storage.swift
Helper class to easily store and retrieve Codable structs from/to disk. https://medium.com/@sdrzn/swift-4-codable-lets-make-things-even-easier-c793b6cf29e1
import Foundation
public class Storage {
fileprivate init() { }
enum Directory {
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud.
case documents
@johnny77221
johnny77221 / stop-video.js
Last active July 20, 2020 02:21 — forked from cferdinandi/stop-video.js
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
element.querySelectorAll('iframe').forEach(function(iframe) {
if ( iframe.contentWindow ) { /* send stop to content */
stopVideo(iframe.contentWindow.document);
}
else { /* Cross Domain, resetting src is all we can do, and the iframe might fail loading same url */
import UIKit
class SwiftUser: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
TestLib().myFunc()
}
}
@johnny77221
johnny77221 / extractSubchunks.swift
Created December 31, 2020 02:28
Swift 5 version syntax correction for https://stackoverflow.com/a/63682544
func extractSubchunks(data:Data) -> RiffFile? {
var data = data
var chunks = [SubChunk]()
let position = data.subdata(in: 8..<12)
let filelengthBytes = data.subdata(in: 4..<8).map { UInt32($0) }
let filelength: UInt32 = filelengthBytes[0] << 24 + filelengthBytes[1] << 16 + filelengthBytes[2] << 8 + filelengthBytes[3]
let wave = String(bytes: position, encoding: .utf8) ?? "NoName"
guard wave == "WAVE" else {
print("File is \(wave) not WAVE")
return nil
@johnny77221
johnny77221 / gist:2a8e369e0bdfa98f89ef04b361613547
Created December 24, 2021 16:56
Xcode 13 Navigation Bar not full height with Safe Area problem
let splashVC = SplashViewController()
let nav = UINavigationController(rootViewController: splashVC)
nav.navigationBar.barStyle = .blackOpaque
nav.navigationBar.isTranslucent = false
// nav.isNavigationBarHidden = true
nav.navigationBar.tintColor = .white
let navBar = nav.navigationBar
if #available(iOS 13.0, *) {
let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithOpaqueBackground()