Skip to content

Instantly share code, notes, and snippets.

View damirstuhec's full-sized avatar
💭
👨‍💻

Damir Stuhec damirstuhec

💭
👨‍💻
View GitHub Profile
struct FlowLayout: Layout {
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let sizes = subviews.map { $0.sizeThatFits(.unspecified) }
var totalHeight: CGFloat = 0
var totalWidth: CGFloat = 0
var lineWidth: CGFloat = 0
var lineHeight: CGFloat = 0
@damirstuhec
damirstuhec / systemcolors.swift
Created January 13, 2022 15:48
iOS System Colors
import SwiftUI
struct ContentView: View {
struct ColorGroup: Hashable {
let colors: [ColorInfo]
let name: String
let description: String
}
struct ColorInfo: Hashable {
@damirstuhec
damirstuhec / swiftui-ios15-button-design-system.swift
Last active June 9, 2022 23:39
SwiftUI iOS 15 button design system
//
// ContentView.swift
// SwiftUIDemo
//
// Created by Damir Stuhec on 07/10/2021.
//
import SwiftUI
// MARK: - CustomButtonStyle
@damirstuhec
damirstuhec / SwiftUI-NavigationLink-14.2-RegressionBug.swift
Created November 23, 2020 14:20
SwiftUI NavigationLink regression bug
@damirstuhec
damirstuhec / SwiftUIAlertWithPublisher.swift
Last active February 28, 2020 18:20
SwiftUI Alert with Publisher
import SwiftUI
import Combine
struct AlertWithPublisher<P>: ViewModifier where P: Publisher, P.Failure == Never {
let publisher: P
let alertContent: (P.Output?) -> Alert
@State private var isShowingAlert = false
@State private var publisherOutput: P.Output? = nil
@damirstuhec
damirstuhec / NSString+HashWithModulo
Created June 4, 2014 13:12
NSString category for computing hash with modulo operation
- (NSInteger)hashWithModulo:(NSInteger)modulo
{
int i, sum = 0;
for (i = 0; i < self.length; i++)
{
sum += [self characterAtIndex:i];
}
return (sum % modulo);
}
@damirstuhec
damirstuhec / NSDate-TimeAgo.h
Created June 3, 2014 12:09
NSDate category method for generating "time ago" string
- (NSString *)timeAgo
{
NSDate *now = [NSDate date];
double deltaSeconds = fabs([self timeIntervalSinceDate:now]);
double deltaMinutes = deltaSeconds / 60.0f;
int minutes;
if(deltaSeconds < 5)
{
#import "NSString+Abbreviation.h"
@implementation NSString (Abbreviation)
- (NSString *)abbreviatedWithMiddles:(BOOL)middles
{
NSArray *nameParts = [self componentsSeparatedByString:@" "];
if (nameParts && nameParts.count > 0)
{
@damirstuhec
damirstuhec / gist:9227519
Created February 26, 2014 10:56
Find the highest repeated character
int array[255] = {0};
NSString *test = @"Test string.";
int i = 0;
for(i = 0; i < test.length; i++)
{
++array[[test characterAtIndex:i]];
}
int max = array[0];
NSDate *fireDate = nil;
NSDate *startDate = [card getLatestDateOfActivities:@[ACTIVITY_CARD_CREATED, ACTIVITY_TIME_SET, ACTIVITY_TIME_CHANGED]];
NSDate *endDate = card.time.date;
NSTimeInterval deltaHours = (abs([startDate timeIntervalSinceReferenceDate] - [endDate timeIntervalSinceReferenceDate]) / 3600);
NSString *invitesNamesSentence = [card getInvitesNamesSentenceWithYourFriendsOption:YES];
NSMutableString *alertBody = [[NSMutableString alloc] initWithFormat:@"%@ wants to meet you ", invitesNamesSentence];