Skip to content

Instantly share code, notes, and snippets.

View glennposadas's full-sized avatar
🏠
Working from home

Glenn Posadas glennposadas

🏠
Working from home
View GitHub Profile
@myell0w
myell0w / externalKeyboard.m
Last active October 31, 2023 11:21
Detect if there's an external keyboard attached (iOS)
// direct check for external keyboard
+ (BOOL)_isExternalKeyboardAttached
{
BOOL externalKeyboardAttached = NO;
@try {
NSString *keyboardClassName = [@[@"UI", @"Key", @"boa", @"rd", @"Im", @"pl"] componentsJoinedByString:@""];
Class c = NSClassFromString(keyboardClassName);
SEL sharedInstanceSEL = NSSelectorFromString(@"sharedInstance");
if (c == Nil || ![c respondsToSelector:sharedInstanceSEL]) {
@phucnm
phucnm / gist:59599cf4bae05bed284b
Created February 29, 2016 05:06
Record video from camera with AVAssetWriter
Sometimes, for some reason, you have to use AVAssetWriter to record videos from camera instead of using movile file output.
I had experienced some issue by that recording method due to lacking of tutorial and SO questions :))
Noted for everyone who met the issue: black first frame
if (CMSampleBufferDataIsReady(sampleBuffer)) {
if (videoWriter.status != AVAssetWriterStatusWriting) {
CMTime startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:startTime];
extension Sequence {
/**
Returns a filtered "view" of `self` where only one for all elements that return the same value for `taggingHandler` is kept. In other words: every element in the returned array was the first to return its value from `taggingHandler` when traversing the sequence in order.
```swift
[1, 1, 1, 2, 3, 3, 4, 5, 5, 5].unique { $0 }
// = [1, 2, 3, 4, 5]
[0, 1, -1, -2, 2, -3, -3].unique { abs($0) }
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@pffan91
pffan91 / NetworkLayerWithMoya_fullExample.swift
Last active February 7, 2019 12:46
NetworkLayerWithMoya_fullExample
#1 Moya Target
import Foundation
import Moya
enum MyAPI {
// MARK: - User
case createUser(model: User)
case changePassword(currentPassword: String, newPassword: String)
@agrcrobles
agrcrobles / android_instructions_29.md
Last active June 2, 2024 05:54 — forked from patrickhammond/android_instructions.md
Setup Android SDK on OSX with and without the android studio

Hi, I am a fork from https://gist.github.com/patrickhammond/4ddbe49a67e5eb1b9c03.

A high level overview for what I need to do to get most of an Android environment setup and maintained on OSX higher Catalina and Big Sur with and without Android Studio been installed.

Considering the SDK is installed under /Users/<your_user>/Library/Android/sdk folder which is the Android Studio preferred SDK location, but it works fine under /usr/local/share/android-sdk as well, which is a location pretty much used on CI mostly.

Prerequisites:

https://github.com/shyiko/jabba instead ?

@simme
simme / UITabBarController+ToggleTabBar.swift
Created January 25, 2018 15:36
Extension on UITabBarController for hiding/showing the tab bar.
extension UITabBarController {
/**
Show or hide the tab bar.
- Parameter hidden: `true` if the bar should be hidden.
- Parameter animated: `true` if the action should be animated.
- Parameter transitionCoordinator: An optional `UIViewControllerTransitionCoordinator` to perform the animation
along side with. For example during a push on a `UINavigationController`.
*/
@dubemike
dubemike / Genrics+CellReuse.swift
Created June 21, 2018 10:12
An easier way to dequeue cells in iOS
import Foundation
import UIKit
public protocol ReusableView: class {
static var defaultReuseIdentifier: String { get }
}
extension ReusableView where Self: UIView {
public static var defaultReuseIdentifier: String {
return String(describing: self)
}
@zntfdr
zntfdr / firebase-iOS-breakdown.swift
Last active July 4, 2024 09:35
Firebase iOS Version breakdown
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
@SergLam
SergLam / CustomNavigationController.swift
Last active February 6, 2024 09:23
Custom screen transition with pan gesture from the center of screen
import UIKit
// Fade animation: https://medium.com/@ludvigeriksson/custom-interactive-uinavigationcontroller-transition-animations-in-swift-4-a4b5e0cefb1e
// Slide animation: https://medium.com/swift2go/simple-custom-uinavigationcontroller-transitions-fdb56a217dd8
class CustomNavigationController: UINavigationController {
private var interactionController: UIPercentDrivenInteractiveTransition?
private var edgeSwipeGestureRecognizer: UIScreenEdgePanGestureRecognizer?
private var panGesturerecognizer: PanDirectionGestureRecognizer?