Skip to content

Instantly share code, notes, and snippets.

View karosLi's full-sized avatar
🎯
Focusing

Karosli karosLi

🎯
Focusing
View GitHub Profile
@karosLi
karosLi / git-ssh-error-fix.sh
Created February 9, 2025 04:46 — forked from Tamal/git-ssh-error-fix.sh
Solution for 'ssh: connect to host github.com port 22: Connection timed out' error
$ git clone [email protected]:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
$ # This should also timeout
$ ssh -T [email protected]
ssh: connect to host github.com port 22: Connection timed out
$ # but this might work
@karosLi
karosLi / GradientLabel.swift
Created December 5, 2024 11:40 — forked from SergLam/GradientLabel.swift
Gradient Label for iOS in Swift
import UIKit
final class GradientLabel: UILabel {
private var colors: [UIColor] = [.supAzure, .supAppleFive]
private var startPoint: CGPoint = CGPoint(x: 0.0, y: 0.5)
private var endPoint: CGPoint = CGPoint(x: 1.0, y: 0.5)
@karosLi
karosLi / GCDAsyncSocket-Apportable.m
Created December 2, 2024 03:00 — forked from paulb777/GCDAsyncSocket-Apportable.m
Apportable version of GCDAsync.m that works around an issue with spurious EOF's.
//Apportable version of GCDAsync.m that works around an issue with spurious EOF's.
// Also make this change to GCDAsyncSocket.h :
//--- a/GCDAsyncSocket/GCDAsyncSocket.h
//+++ b/GCDAsyncSocket/GCDAsyncSocket.h
//@@ -21,7 +21,7 @@
//- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // iOS 5.0 supported
//+ #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 50000) && !defined(APPORTABLE) // iOS 5.0 supported
@karosLi
karosLi / CV.m
Created November 13, 2024 02:53 — forked from zadr/CV.m
UIImage from CMSampleBuffer
#import <CoreMedia/CoreMedia.h>
#import <CoreVideo/CoreVideo.h>
#import <UIKit/UIKit.h>
// https://developer.apple.com/library/content/qa/qa1702/_index.html
+ (UIImage * _Nullable)imageWithSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer {
UIImage *returnValue = nil;
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer, 0); {
// Create a UIImage from sample buffer data
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer
{
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
@karosLi
karosLi / gist:85dd2f783c0a5c3dfa52488cc27d7d26
Created November 12, 2024 13:52 — forked from moralez/gist:5544955
Getting a Screenshot for a AVPlayer
- (UIImage *)screenshotFromPlayer:(AVPlayer *)player atTime:(CMTime)time {
CMTime actualTime;
NSError *error;
int attemptNumber = 0;
BOOL success = NO;
UIImage *image;
while (attemptNumber < 5 && !success) {
@karosLi
karosLi / StringEncode.m
Created October 24, 2024 03:32 — forked from MadeBugs/StringEncode.m
特殊字符转码
//特殊字符转码
- (NSString *)encodeWithString:(NSString *)string {
NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";
NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
}
//URL中包含中文的连接转码
NSString *escapedPath = [@"http://www.baidu.com?中文" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
@karosLi
karosLi / command.txt
Created November 2, 2023 06:24 — forked from nrk/command.txt
Using ffprobe to get info from a file in a nice JSON format
ffprobe -v quiet -print_format json -show_format -show_streams "lolwut.mp4" > "lolwut.mp4.json"
@karosLi
karosLi / UIImage_ImageHelper.h
Created February 2, 2023 10:17 — forked from JoeOsborn/UIImage_ImageHelper.h
A UIImage to BGRA8 conversion category
/*
* The MIT License
*
* Copyright (c) 2011 Paul Solt, [email protected]
* Modifications Copyright (c) 2011 Joe Osborn, [email protected]
*
* 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
@karosLi
karosLi / Notes.md
Created September 28, 2022 03:53 — forked from mhamilt/Notes.md
Metal Compute Shader Example in Swift and Objective C

Notes

Create a command line target in xcode either in Swift or Obj-C. add a metal file to the project and copy and paste the respective code into each file.