Skip to content

Instantly share code, notes, and snippets.

View willbur1984's full-sized avatar

William Towe willbur1984

View GitHub Profile
import Stanley
/**
`ReadWriteLock` provides that allow concurrently reading from and synchrously writing to another data structure.
*/
class ReadWriteLock {
/**
Internal queue where read/write operations are dispatched to.
*/
private let queue = DispatchQueue(label: "\(Bundle.main.kst_bundleIdentifier()).read-write-lock", qos: .unspecified, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
/**
`Atomic` is a property wrapper that enforce atomic read/write access to its wrapped value.
*/
@propertyWrapper
struct Atomic<Value> {
var wrappedValue: Value {
get {
return self.queue.sync {
self.value
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:start="6dp">
<shape
android:shape="rectangle"
android:tint="#ffca3f">
<size android:height="175dp" />
<solid android:color="#ffca3f" />
</shape>
</item>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:gravity="center_vertical|fill_horizontal">
<shape
android:shape="rectangle"
android:tint="#ffffff">
<size
android:width="10dp"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:angle="270"
android:startColor="#ffeb92"
android:endColor="#ffca3f"
android:type="linear"/>
</shape>
</item>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
- (void)setupSearchBarAppearance {
[UISearchBar.appearance setBarTintColor:UIColor.TMO_subviewBackgroundColor];
[UISearchBar.appearance setSearchFieldBackgroundImage:({
CGSize size = CGSizeMake(TMOCornerRadius + TMOCornerRadius + 1, 32);
UIGraphicsBeginImageContext(size);
[UIColor.TMO_viewBackgroundColor setFill];
[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, size.width, size.height) cornerRadius:TMOCornerRadius] fill];
UIImage *retval = [UIGraphicsGetImageFromCurrentImageContext() resizableImageWithCapInsets:UIEdgeInsetsMake(0, TMOCornerRadius, 0, TMOCornerRadius) resizingMode:UIImageResizingModeTile];
//
// WorkoutDetailSectionHeaderView.swift
// tribal-ios
//
// Created by William Towe on 11/6/18.
// Copyright © 2018 Kosoku Interactive, LLC. All rights reserved.
//
import UIKit
@willbur1984
willbur1984 / class_cluster.m
Created July 3, 2018 17:44
example of class cluster pattern
#import "iOS11PrivateClass.h"
#import "iOS10PrivateClass.h"
#import <Availability.h>
@implementation MyClass
- (instancetype)init {
if (self.class == MyClass.class) {
#if __IPHONE_11_0
return [[iOS11PrivateClass alloc] init];
@willbur1984
willbur1984 / a.m
Created January 28, 2018 04:16
redirect NSLog to file
- (void)logToFile {
NSURL *directoryURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject;
directoryURL = [directoryURL URLByAppendingPathComponent:@"XfinityDebugLogs" isDirectory:YES];
if (![directoryURL checkResourceIsReachableAndReturnError:NULL]) {
[[NSFileManager defaultManager] createDirectoryAtURL:directoryURL withIntermediateDirectories:YES attributes:nil error:NULL];
[directoryURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:NULL];
}