Skip to content

Instantly share code, notes, and snippets.

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

Mikhail Radaev msfrms

🏠
Working from home
View GitHub Profile
@msfrms
msfrms / Image+Trim.swift
Created December 26, 2023 03:27 — forked from chriszielinski/Image+Trim.swift
[Swift 5] NSImage/UIImage Crop/Trim Transparency
// Image+Trim.swift
//
// Copyright © 2020 Christopher Zielinski.
// https://gist.github.com/chriszielinski/aec9a2f2ba54745dc715dd55f5718177
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@msfrms
msfrms / gist:a14b65cb82e587f382e5c441af1dcaab
Created August 31, 2022 08:20 — forked from b9AobJ/gist:b9b65c1386ec32c9c1d6796e0bec36a4
Convert an AVFrame to CVPixelbuffer
-(void)getPixelBuffer:(CVPixelBufferRef *)pbuf {
@synchronized (self) {
if(!_pFrame || !_pFrame->data[0])
return;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
// [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
// [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
@(_pFrame->linesize[0]), kCVPixelBufferBytesPerRowAlignmentKey,
@msfrms
msfrms / AVPlayerItem+MLWPerformance.m
Created August 13, 2022 15:41 — forked from k06a/AVPlayerItem+MLWPerformance.m
Smooth AVPlayer scrolling in UICollectionView/UITableView
#import <JRSwizzle/JRSwizzle.h>
@implementation AVPlayerItem (MLWPerformance)
+ (void)load {
[AVPlayerItem jr_swizzleMethod:NSSelectorFromString(@"_attachToFigPlayer") withMethod:@selector(mlw_attachToFigPlayer) error:nil];
}
- (void)mlw_attachToFigPlayer {
static dispatch_queue_t queue = nil;
@msfrms
msfrms / MLWAsyncAVPlayer.h
Created August 13, 2022 15:41 — forked from k06a/MLWAsyncAVPlayer.h
Awesome optimized AVPlayer for smooth scrolling AVPlayerLayer inside UICollectionView/UITableView (tested on iOS10+)
#import <AVFoundation/AVFoundation.h>
@interface MLWAsyncAVPlayer : AVPlayer
@end
@msfrms
msfrms / AVPlayer+Scrubbing.swift
Created August 5, 2022 09:42 — forked from shaps80/AVPlayer+Scrubbing.swift
Enables smooth frame-by-frame scrubbing (in both directions) – similar to Apple's applications.
public enum Direction {
case forward
case backward
}
internal var player: AVPlayer?
private var isSeekInProgress = false
private var chaseTime = kCMTimeZero
private var preferredFrameRate: Float = 23.98
@msfrms
msfrms / gist:bb3b24ccc456605d5f0f93a43879805a
Created August 5, 2022 09:16 — forked from ukudala/gist:ac529a1b183e4873ed6f
Smooth AVPlayer scrolling performance fix
> DESCRIPTION OF PROBLEM
> In Photos.app, Videos.app, and iMovie.app, local videos can be rewound using the video scrubber. Scrubbing backwards in a video is extremely smooth and satisfying.
>
> Using AVPlayer in our app, ScoreBreak, we cannot achieve the same smoothness when scrubbing a video backwards. There are reports on stack overflow which indicate that this is due to the codec used by AVPlayer.
>
> We would like to deliver the same beautiful user interaction with videos as offered by your system apps. Can you instruct us on how to achieve this while using AVFoundation?
>
> STEPS TO REPRODUCE
> • Create test application which utilizes AVPlayer for local video file playback
> • Scrub backwards using AVPlayer controller
@msfrms
msfrms / search-address.swift
Last active June 21, 2021 02:56
SearchAddress
enum AddressActions: Action {
case search(String)
case failed(String)
case receiveAdresses([Address])
}
struct Address {
struct Id {}
let id: Id
}
@msfrms
msfrms / user-location.swift
Created June 21, 2021 02:53
UserLocation
enum UserLocationActions: Action {
case startUpdatingLocation
case receive(CLLocationCoordinate2D)
}
struct UserLocation {
let coordinate: CLLocationCoordinate2D
let request: UUID?
func reduce(action: Action) -> UserLocation {
@msfrms
msfrms / Mail.scala
Created March 19, 2021 15:59 — forked from mariussoutier/Mail.scala
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@msfrms
msfrms / idea.vmoptions
Created March 13, 2021 02:49
Better performance vmoptions for 2020.1 intellij
-Xms1024m
-Xmx3072m
-Xss64m
-Dfile.encoding=UTF-8
-Djava.net.preferIPv4Stack=true
-Dsun.io.useCanonCaches=false
-XX:+AggressiveOpts
-XX:+AlwaysPreTouch
-XX:+CMSClassUnloadingEnabled
-XX:+CMSIncrementalMode