Skip to content

Instantly share code, notes, and snippets.

View AmatsuZero's full-sized avatar
💭
I may be slow to respond.

Daubert Jiang AmatsuZero

💭
I may be slow to respond.
  • Tencent
  • Beijing, China
View GitHub Profile
@AmatsuZero
AmatsuZero / linkmap.js
Created January 15, 2021 08:10 — forked from bang590/linkmap.js
XCode Linkmap Parser
var readline = require('readline'),
fs = require('fs');
var LinkMap = function(filePath) {
this.files = []
this.filePath = filePath
}
LinkMap.prototype = {
start: function(cb) {
import Foundation
enum RandomSource {
static let file = fopen("/dev/urandom", "r")!
static let queue = DispatchQueue(label: "random")
static func get(count: Int) -> [Int8] {
let capacity = count + 1 // fgets adds null termination
var data = UnsafeMutablePointer<Int8>.allocate(capacity: capacity)
defer {
@AmatsuZero
AmatsuZero / RandomWaterfallLayout.swift
Last active April 30, 2020 03:32
iOS不规则瀑布流
import UIKit
public protocol RandomWaterfallLayoutDelegate: class {
/// 列数
func columnCount(_ layout: RandomWaterfallLayout) -> CGFloat
/// 列间距
func columnMargin(_ layout: RandomWaterfallLayout) -> CGFloat
/// 行间距
func rowMargin(_ layout: RandomWaterfallLayout) -> CGFloat
/// CollectionView 边距
@AmatsuZero
AmatsuZero / UICollectionViewLeftAlignedLayout.swift
Created June 18, 2019 09:30
UICollectionView 固定行距列表左排: 来一个自定制 Layout
// based on http://stackoverflow.com/questions/13017257/how-do-you-determine-spacing-between-cells-in-uicollectionview-flowlayout https://github.com/mokagio/UICollectionViewLeftAlignedLayout
import UIKit
extension UICollectionViewLayoutAttributes {
func leftAlignFrame(with sectionInset:UIEdgeInsets){
var tempFrame = frame
tempFrame.origin.x = sectionInset.left
frame = tempFrame
}
}
hdiutil create -o /tmp/HighSierra.cdr -size 5200m -layout SPUD -fs HFS+J
hdiutil create -o /tmp/HighSierra.cdr -size 5200m -layout SPUD -fs HFS+J
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/install_build
mv /tmp/HighSierra.cdr.dmg ~/Desktop/InstallSystem.dmg
hdiutil detach /Volumes/Install\ macOS\ High\ Sierra
hdiutil convert ~/Desktop/InstallSystem.dmg -format UDTO -o ~/Desktop/HighSierra.iso
extension UIImage {
func upFixedImage() -> UIImage? {
// No-op if the orientation is already correct
guard imageOrientation != .up else {
return nil
}
var transform = CGAffineTransform.identity
switch imageOrientation {
case .down, .downMirrored:
extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
@AmatsuZero
AmatsuZero / Bridge.swift
Created January 6, 2019 07:54
Swift self casting
func bridge<T : AnyObject>(obj : T) -> UnsafeRawPointer {
return UnsafeRawPointer(Unmanaged.passUnretained(obj).toOpaque())
}
func bridge<T : AnyObject>(ptr : UnsafeRawPointer) -> T {
return Unmanaged<T>.fromOpaque(ptr).takeUnretainedValue()
}
func bridgeRetained<T : AnyObject>(obj : T) -> UnsafeRawPointer {
return UnsafeRawPointer(Unmanaged.passRetained(obj).toOpaque())
@AmatsuZero
AmatsuZero / DispatchTime+Extensions.swift
Created January 1, 2019 08:23
DispatchTime 便捷方法
extension DispatchTime: ExpressibleByIntegerLiteral {
public init(integerLiteral value: Int) {
self = DispatchTime.now() + .seconds(value)
}
}
extension DispatchTime: ExpressibleByFloatLiteral {
public init(floatLiteral value: Double) {
self = DispatchTime.now() + .milliseconds(Int(value * 1000))
}
@AmatsuZero
AmatsuZero / 字符串转OSType.swift
Created December 24, 2018 05:36
字符串转OSType
extension String {
var fourCharCode: FourCharCode? {
guard self.count == 4 else {
return nil
}
return self.utf16.reduce(0) { $0 << 8 + FourCharCode($1) }
}
}