Skip to content

Instantly share code, notes, and snippets.

View fpg1503's full-sized avatar
🐥

Francesco fpg1503

🐥
View GitHub Profile
@fpg1503
fpg1503 / ImageFromUrl.swift
Created January 19, 2015 15:21
UIImageView setImageFromURL - Swift
//
// ImageFromUrl.swift
//
// Created by Francesco Perrotti-Garcia on 1/19/15.
// Copyright (c) 2015 Francesco Perrotti-Garcia. All rights reserved.
//
import Foundation
import UIKit
import ObjectiveC
@fpg1503
fpg1503 / DragView.swift
Last active January 31, 2020 20:10
Drag and Drop View on macOS
protocol DragViewDelegate {
var acceptedFileExtensions: [String] { get }
func dragView(dragView: DragView, didDragFileWith URL: NSURL)
}
class DragView: NSView {
required init?(coder: NSCoder) {
super.init(coder: coder)
registerForDraggedTypes([NSFilenamesPboardType, NSURLPboardType])
@fpg1503
fpg1503 / ViewSpitter.swift
Last active July 11, 2016 21:36
ViewSpitter: Programmatic UIView Boilerplate generator
extension String {
mutating func appendLine(line: String = "") {
self += "\n\(line)"
}
mutating func appendMark(mark: String) {
self.appendLine()
self.appendLine("//MARK - \(mark)")
self.appendLine()
}
@fpg1503
fpg1503 / PixelPerfectConstraint.swift
Created July 28, 2016 18:34
Pixel Perfect Constraint
import UIKit
/// A subclass of NSLayoutConstraint where the constant is in pixels and not points
final class PixelPerfectConstraint: NSLayoutConstraint {
@IBInspectable var constantInPixels: Int = 0 {
didSet {
constant = CGFloat(constantInPixels) / UIScreen.mainScreen().scale
}
}

Keybase proof

I hereby claim:

  • I am fpg1503 on github.
  • I am fpg1503 (https://keybase.io/fpg1503) on keybase.
  • I have a public key ASDU6qes4rGLHgi4QuFxVydgxs2tY8JAR69otLKik8M63go

To claim this, I am signing this object:

@fpg1503
fpg1503 / UIImage+Resize.swift
Created October 31, 2016 17:46
Image Resizer
enum Resize {
case current
case resize(CGSize)
}
extension UIImage {
func resize(_ resize: Resize) -> UIImage? {
guard case let .resize(size) = resize else { return self }
@fpg1503
fpg1503 / Request.md
Created November 4, 2016 01:32
Balance RA DAC - UNICAMP
@fpg1503
fpg1503 / ColorExporter.swift
Created December 28, 2016 18:18
ColorExporter
// ([^#\n]*)\s#([\dA-F]{6})
// (name: "$1", color: UIColor(hex: 0x$2)),
typealias NamedColor = (name: String, color: UIColor)
extension CGFloat {
var prettyString: String {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.roundingMode = .halfUp
formatter.maximumFractionDigits = 10
@fpg1503
fpg1503 / Localized.pl
Created January 9, 2017 04:41
Oops I forgot to localize my entire app
#!/usr/bin/perl -w
# Inspired on:
# settings:
# .swift files may be set as well, just set "swift" if needed
my $sourceFileExtension = "swift";
# if set, the script will only check Localizable.strings files, otherwse all available .strings files
my $stringsFileName = "pt-BR.lproj/Localizable.strings";
@fpg1503
fpg1503 / DateFormat.swift
Created January 9, 2017 06:22
Swifty Date Formats
struct DateFormat: DateFormatConvertible {
let dateFormat: String
init() {
dateFormat = ""
}
init(format: DateFormatConvertible) {
dateFormat = format.dateFormat
}