Skip to content

Instantly share code, notes, and snippets.

Amin Benarieb aminbenarieb

  • Moscow
View GitHub Profile
View gist:e16cee36347b6a5e6941a52936cabc9b
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))")
}
View activeArea
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)
}
View video_sim_fps.swift
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))
View cuts.txt
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
View Swift stitchImages
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)
View gist:baf1d35c3a98e1800fd912a2333c5301
#!/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
View two max number multiplication
import random
MIN_ARRAY_LENGTH = 1
MAX_ARRAY_LENGTH = 50
MIN_NUM = 0
MAX_NUM = 100
# Uses python3
def max_mult(a,n):
if n < 1:
View gist:31da4d5e80f8e2c1c6a21e1fb4ad5c01
#include <LPC23xx.H>
#include <string.h>
#include <stdlib.H>
int interrupts_count = -2;
int i = 0;
static unsigned const kStrSize = 15;
char star_group = 'u';
View UIAlertController Snippet
UIAlertController* <#alert#> = [UIAlertController alertControllerWithTitle:<#name#>
message:<#message#>
preferredStyle:<#UIAlertControllerStyleAlert#>];
void (^<#handler#>)(UIAlertAction * action) = ^(UIAlertAction * action){
};
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:<#@"OK"#> style:<#UIAlertActionStyleDefault#>
handler:<#handler#>];
You can’t perform that action at this time.