Skip to content

Instantly share code, notes, and snippets.

@aminbenarieb
aminbenarieb / main.dart
Created June 22, 2022 08:59
Ignore error in future
void main() async {
print(await foo().catchError((_) => false));
}
Future<bool> foo() async {
throw Error();
// return Future.value(true);
}
@aminbenarieb
aminbenarieb / ABOrderedKeyArray.h
Last active June 2, 2021 05:38
ABOrderedKeyArray
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NSComparisonResult (^ABOrderedKeyArrayComparator)(id _Nonnull obj1,
id _Nonnull obj2);
@interface ABOrderedKeyArray<__covariant KeyType, __covariant ObjectType>
: NSObject <NSFastEnumeration>
class ArchiverContainer<T: Codable>: NSObject, NSCoding {
enum ArchiverContainerError: Error {
case failedDecoding
}
let info: T
init(info: T) {
self.info = info
}
required init?(coder: NSCoder) {
class ProfileAppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
for i in 100...100000000 {
let side = i
let size = CGSize(width: side, height: side)
print("size: \(side)x\(side) => \(ImageStitcher.bytes(for: size))")
}
private func activeArea(pixelBuffer: CVPixelBuffer) -> CGRect {
let width = CVPixelBufferGetWidth(pixelBuffer)
let height = CVPixelBufferGetHeight(pixelBuffer)
let verticalInset = Double(height) * self.activeInsetProcent
let horizontalInset = Double(width) * self.activeInsetProcent
return CGRect(x: horizontalInset,
y: verticalInset,
width: Double(width) - 2*horizontalInset,
height: Double(height) - 2*verticalInset)
}
let framesPerSecond = min(self.nominalFrameRate, self.framesPerSecond)
let processedFrameIdx = Int64(self.nominalFrameRate / framesPerSecond)
guard self.frameCounter.value % processedFrameIdx == 0 else {
sample = self.assetReader?.outputs.first?.copyNextSampleBuffer()
continue
}
usleep(UInt32(1000 * Int(1000.0 * 1.0 / framesPerSecond) * self.framesRate))
still 00:00:00 00:00:10
right 00:00:10 00:00:13
up 00:00:13 00:00:15
still 00:00:15 00:00:19
right 00:00:19 00:00:20
left 00:00:20 00:00:24
right 00:00:24 00:00:26
down 00:00:26 00:00:27
right 00:00:27 00:00:28
right 00:00:28 00:00:30
extension Array where Element: UIImage {
func stitchImages(isVertical: Bool) -> UIImage {
let maxWidth = self.compactMap { $0.size.width }.max()
let maxHeight = self.compactMap { $0.size.height }.max()
let maxSize = CGSize(width: maxWidth ?? 0, height: maxHeight ?? 0)
let totalSize = isVertical ?
CGSize(width: maxSize.width, height: maxSize.height * (CGFloat)(self.count))
: CGSize(width: maxSize.width * (CGFloat)(self.count), height: maxSize.height)
{
varitaion: "words"
}
#!/usr/bin/env python3
import os
match_keyword ="<some stuff here to find>"
import_line = "<some stuff needed to be imported>"
def find_first_line_match_idx(lines, match_str):
lastmatchIdx = None
idx = 0