Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Cardona Rojas DanielCardonaRojas

View GitHub Profile
@DanielCardonaRojas
DanielCardonaRojas / Resolver.swift
Created Jan 7, 2021
Dependency injection for Swift projects
View Resolver.swift
@propertyWrapper
public struct Inject<Component> {
var component: Component
public init() {
self.component = Resolver.shared.resolve(Component.self)
}
public var wrappedValue: Component {
View TimeInterval+Extensions.swift
extension TimeInterval {
var milliseconds: Int {
return Int((truncatingRemainder(dividingBy: 1)) * 1000)
}
var seconds: Int {
return Int(self) % 60
}
var minutes: Int {
@DanielCardonaRojas
DanielCardonaRojas / circular_progress_border.dart
Created Nov 26, 2020
CircularProgressBorder flutter widget
View circular_progress_border.dart
import 'package:flutter/material.dart';
import 'dart:math';
class CircularProgressBorder extends StatelessWidget {
final Color backgroundColor;
final Color progressColor;
final Color unfilledColor;
final double progress;
final double thickness;
final double offset;
@DanielCardonaRojas
DanielCardonaRojas / dialog_controller.dart
Last active Oct 23, 2020
Flutter DialogController #flutter
View dialog_controller.dart
import 'dart:async';
import 'package:flutter/material.dart' as material;
import 'package:flutter/material.dart' show BuildContext, Widget, Navigator;
class DialogController {
final BuildContext context;
final Widget Function(BuildContext) builder;
Future<dynamic> value;
@DanielCardonaRojas
DanielCardonaRojas / MockURLProtocol.swift
Created Jul 31, 2020
MockURLProtocol useful for mocking URLSession #URLSession #Mock
View MockURLProtocol.swift
//
// MockURLProtocol.swift
// APIClientTests
//
// Created by Daniel Cardona Rojas on 31/07/20.
// Copyright © 2020 Daniel Cardona Rojas. All rights reserved.
//
import Foundation
@DanielCardonaRojas
DanielCardonaRojas / EZAction.swift
Created Jul 28, 2020
Add closure targets to UIControl subclasses.
View EZAction.swift
import UIKit
public typealias Action = (UIControl) -> Void
extension NSObject {
var uniqueId: String {
return String(describing: self)
}
}
@DanielCardonaRojas
DanielCardonaRojas / UIApplication+Extensions.swift
Created Jul 24, 2020
UIApplication extensions. Bundle marketing and build versions
View UIApplication+Extensions.swift
extension UIApplication {
static var appVersion: String? {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}
static var buildVersion: String? {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
}
static var fullVersion: String? {
@DanielCardonaRojas
DanielCardonaRojas / gen_ios_imgs.sh
Created Jul 16, 2020
Generate ios images from svg #svg #ios #png #images
View gen_ios_imgs.sh
# gen_ios_icons.sh
# Params: (filename) (width 1x) (height 1x)
# Get filename without an extension
filename=$1
filename_length=${#1}
name_length=$((filename_length-4))
name=${filename:0:$name_length}
mkdir $name
rsvg-convert -w $2 -h $3 $filename > $name/$name.png
rsvg-convert -w $((2*$2)) -h $((2*$3)) $filename > $name/$name@2x.png
@DanielCardonaRojas
DanielCardonaRojas / UIColor+Extension.swift
Created Jul 14, 2020
UIColor+Extensions #ios #swift #UIColor
View UIColor+Extension.swift
extension UIColor {
public convenience init?(hex: String) {
let r: CGFloat
let g: CGFloat
let b: CGFloat
let a: CGFloat
let start = hex.index(hex.startIndex, offsetBy: hex.hasPrefix("#") ? 1 : 0)
var hexColor = String(hex[start...])
if hexColor.count == 6 { hexColor += "FF" }
@DanielCardonaRojas
DanielCardonaRojas / generate_text_resource_class
Created Jul 9, 2020
Generate type safe class for localized strings #awk #iOS #Localized Strings
View generate_text_resource_class
#! /usr/bin/awk -f
BEGIN {
print "\
// This file is autogenerated do not modify\
\
import Foundation\
";
print "public struct TextResource {"
}