Skip to content

Instantly share code, notes, and snippets.

View hsleedevelop's full-sized avatar
🔥

HS Lee hsleedevelop

🔥
View GitHub Profile
let sdevices = devices.flatMap({ (device: Device) -> String in
return "\(device.brand)-\(device.hostname)-\(device.ipAddress)-\(device.macAddress)\n"
}).flatMap({$0}).joined()
DispatchQueue.main.async {
JDAlert(title: "Found \(devices.count) Device(s).", message: sdevices, preferredStyle: .alert)
.addAction(title: "OK", style: .default) { _ in }
.show()
}
//http://stackoverflow.com/questions/41940994/closure-cannot-implicitly-capture-a-mutating-self-paramter/41941810#41941810
private func capture(with block: @escaping () -> ()) { block() }
@hsleedevelop
hsleedevelop / getIPAddressFromHotspot.swift
Created May 11, 2017 13:50
get IPAddress From Hotspot
//#include <ifaddrs.h> in bridging-header first.
fileprivate func getIPAddress() -> String? {
var address : [String]? = []
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ifaddr) == 0 else { return nil}
guard let firstAddr = ifaddr else { return nil}
@hsleedevelop
hsleedevelop / safeAreaInsets.swift
Last active January 14, 2018 07:49
safeAreaInsets get
if #available(iOS 11.0, *) {
let bottomPadding = view.safeAreaInsets.bottom
}
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
ALWAYS_SEARCH_USER_PATHS = NO
ALWAYS_USE_SEPARATE_HEADERMAPS = YES
APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer
APPLE_INTERNAL_DIR = /AppleInternal
APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation
// create results array
__block NSMutableArray* results = [NSMutableArray new];
// create serial queue
dispatch_queue_t queue = dispatch_queue_create("myQueue", 0);
for(NSInteger i = 0; i < 10; i++) {
// enqueue operation in queue
dispatch_async(queue, ^{
// create semaphore
enum DateError: String, Error {
case invalidDate
}
struct Spaceship : Codable {
var name: String
var createdAt: Date
}
let decoder = JSONDecoder()
@hsleedevelop
hsleedevelop / gist:d1612838eadcbe38429866e1e91b50d9
Last active November 16, 2018 05:37
a sample for using UICollectionViewFlowLayout
class AlignTopCollectionViewFlowLayout: UICollectionViewFlowLayout {
var sectionLayout: HomeSectionLayout?
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attrs = super.layoutAttributesForElements(in: rect)
var attrsCopy = [UICollectionViewLayoutAttributes]()
let layout = sectionLayout ?? .PERSONAL
for element in attrs! {
@hsleedevelop
hsleedevelop / gist:73c509014cd622985eb8f4189319547e
Last active November 22, 2018 07:48
check the cell is visible cell in tableView
//validate tpo cell in visible cells,
guard let tableView = self.superview as? UITableView, let ip = self.indexPath, tableView.indexPathsForVisibleRows?.contains(ip) == true else {
return
}
@hsleedevelop
hsleedevelop / scrollViewWillEndDragging.swift
Created November 29, 2018 04:06
scrollViewWillEndDragging
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
guard self.topSectionViewTopConstraint.constant > 0 else { return }
let tableViewOffset = tableViewTopEdgeInset + scrollView.contentOffset.y
let topSectionViewTop = tableViewTopEdgeInset - listHeaderView.dimViewHeight
//-160 ~ 0
var offset = (topSectionViewTop - tableViewOffset)
offset = offset > topSectionViewTop / 2.c ? -tableViewTopEdgeInset : -listHeaderView.dimViewHeight.c
targetContentOffset.pointee.y = offset