Skip to content

Instantly share code, notes, and snippets.

View karosLi's full-sized avatar
🎯
Focusing

Karosli karosLi

🎯
Focusing
View GitHub Profile
@karosLi
karosLi / Makefile
Created September 28, 2022 03:52 — forked from wakita/Makefile
Metal compute shader example
SDK = xcrun -sdk macosx
all: compute.metallib compute
compute.metallib: Compute.metal
# Metal intermediate representation (.air)
$(SDK) metal -c -Wall -Wextra -std=osx-metal2.0 -o /tmp/Compute.air $^
# Metal library (.metallib)
$(SDK) metallib -o $@ /tmp/Compute.air

Understanding UIViewController Rotation

Problem

To enable the rotation of a single view controller used to display the preview of Images/Videos. It is intuitive to allow user to rotate there device and screen changes accordingly, so it feels pleasant. But to achieve this, we need to enable the (almost) all Supported Device orientations.

Ex: `Portrait`, `LandscapeLeft`, `LandscapeRight`.
@karosLi
karosLi / delete_git_submodule.md
Created May 7, 2022 16:13 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@karosLi
karosLi / build_framework.sh
Created March 11, 2022 10:25
build_framework
# Merge Script
# 1
# Set bash script to exit immediately if any commands fail.
set -e
# 2
# Setup some constants for use later on.
PROJECT=WPFixDemo.xcodeproj
FRAMEWORK_NAME=WPFix
@karosLi
karosLi / build_static_library.sh
Last active March 11, 2022 10:26
build_static_library
#!/bin/sh
LIB_NAME=ffi
TARGET_NAME=libffi-iOS
PROJECT=libffi.xcodeproj
CONFIGURATION=Release
DEVICE=iphoneos
SIMULATOR=iphonesimulator
FAT=universal
@karosLi
karosLi / frameworks_blogpost_merge_script.sh
Created March 11, 2022 10:14 — forked from kientux/frameworks_blogpost_merge_script.sh
Merge simulator and device dynamic frameworks into one
# Merge Script
# 1
# Set bash script to exit immediately if any commands fail.
set -e
# 2
# Setup some constants for use later on.
FRAMEWORK_NAME="${PROJECT_NAME}"
@karosLi
karosLi / GLKMathUtils
Created December 20, 2021 11:44 — forked from AyadiMehdi/GLKMathUtils
GLKMathProject and GLKMathUnproject
GLKVector3 GLKMathProject(GLKVector3 object, GLKMatrix4 model, GLKMatrix4 projection, int *viewport) {
assert(viewport);
GLKVector4 v4 = GLKVector4MakeWithVector3(object, 1.0);
GLKVector4 v = GLKMatrix4MultiplyVector4(model, v4);
v = GLKMatrix4MultiplyVector4(projection, v);
v.v[3] = 1.0/v.v[3];
v.v[0] *= v.v[3];
v.v[1] *= v.v[3];
@karosLi
karosLi / SheetModalPresentationController.swift
Created January 16, 2021 09:57 — forked from vinczebalazs/SheetModalPresentationController.swift
A presentation controller to use for presenting a view controller modally, which can be dismissed by a pull down gesture. The presented view controller's height is also adjustable.
import UIKit
extension UIView {
var allSubviews: [UIView] {
subviews + subviews.flatMap { $0.allSubviews }
}
func firstSubview<T: UIView>(of type: T.Type) -> T? {
allSubviews.first { $0 is T } as? T
@karosLi
karosLi / index.html
Created October 23, 2019 08:56
iphone-inline-video demo with playsinline // source https://jsbin.com/batetip/1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>iphone-inline-video demo with playsinline</title>
</head>
<body>
<video loop playsinline autoplay="autoplay" id="video1" muted="muted" poster="http://image.baby-kingdom.com/images2/2016/b/html5/wyeth_20161122_320x280/poster.jpg" type="video/mp4" width="100%" src="http://image.baby-kingdom.com/images2/2016/b/html5/wyeth_20161122_320x280/video.mp4">
</video>
@karosLi
karosLi / 判断代码是否在扩展里执行
Last active May 5, 2018 02:59
判断代码是否在扩展里执行
+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && !defined(AF_APP_EXTENSIONS)
- (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler; - (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler;
#endif #endif