This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readline = require('readline'), | |
fs = require('fs'); | |
var LinkMap = function(filePath) { | |
this.files = [] | |
this.filePath = filePath | |
} | |
LinkMap.prototype = { | |
start: function(cb) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public protocol RandomWaterfallLayoutDelegate: class { | |
/// 列数 | |
func columnCount(_ layout: RandomWaterfallLayout) -> CGFloat | |
/// 列间距 | |
func columnMargin(_ layout: RandomWaterfallLayout) -> CGFloat | |
/// 行间距 | |
func rowMargin(_ layout: RandomWaterfallLayout) -> CGFloat | |
/// CollectionView 边距 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
var fourCharCode: FourCharCode? { | |
guard self.count == 4 else { | |
return nil | |
} | |
return self.utf16.reduce(0) { $0 << 8 + FourCharCode($1) } | |
} | |
} |
NewerOlder