Skip to content

Instantly share code, notes, and snippets.

View mrvfino's full-sized avatar
🌴
"Work from roam!"

markr mrvfino

🌴
"Work from roam!"
View GitHub Profile
// Requires: Moya
// (source): https://stackoverflow.com/questions/31949118/send-post-parameters-with-multipartformdata-using-alamofire-in-ios-swift
private static func uploadAsMultipart(_ params: Encodable) -> Task {
let multipart = params.asParams().map { (key, value) -> MultipartFormData in
let data = (value as! String).data(using: .utf8, allowLossyConversion: false)!
return MultipartFormData(provider: .data(data), name: key)
}
return .uploadMultipart(multipart)
}
@mrvfino
mrvfino / ShadowWithCornerRadius.swift
Last active September 17, 2020 18:29
Add a SHADOW with CORNER RADIUS to a view.
/**
Usage:
1. Add a dummy UIView behind the main UIView where you want to have a shadow with corner radius effect.
2. Apply your corner radius to the main UIView.
3. Call this function with the dummy UIView as the argument for shadowView.
*/
func initShadow(shadowView: UIView, cornerRadius: CGFloat) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
guard shadowView.layer.shadowPath == nil else { return }
let c = """
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
</head>
<body>
\(content ?? "")
</body>
</html>
"""
//
// URL+naiveUniformType.swift
// MyPocketDoctor
//
// Created by Mark on 26/12/2018.
// Copyright © 2018 Mediaxes. All rights reserved.
//
import Foundation
import MobileCoreServices
@mrvfino
mrvfino / FileUploaderService.swift
Last active September 17, 2020 18:50
WIP: Reusable service that enables rudimentary selection of any files for uploading. | Rename to file selector?
//
// FileUploaderService.swift
// https://gist.github.com/markrufino/c0712635fbd258a192f4bb26c57ce443
//
// Created by Mark on 25/12/2018.
// Copyright © 2018 Mark Rufino. All rights reserved.
//
import AVKit
import Foundation
import os
from shutil import copyfile
i = 0
def mapper(p):
global i
for file_or_dir in os.listdir(p):
d = f"{p}/{file_or_dir}"
if os.path.isfile(d):
/// - Groups an array of `T` objects, that conform to the `DateSortableType` protocol, based on their `sortingDate` property.
struct DateSortablesContainer<T: DateSortableType> {
/// - An array of dates to be used as keys for `DateSortablesContainer.objectsGroupedByDate`. This is sorted in ascending order.
let dates: [Date]
/// - A dictionary of `[T]` arrays.
let objectsGroupedByDate: Dictionary<Date, [T]>
init(_ dateSortables: [T]) {
#!/usr/local/bin/python3
import os
import requests
current_working_directory = os.getcwd()
print(f"Creating a .gitignore for a Swift project @ {current_working_directory}")
swift_gitignore_url = "https://raw.githubusercontent.com/github/gitignore/master/Swift.gitignore"
print(f"Downloading latest gitignore for Swift @ {swift_gitignore_url}")
// A sample closure that handles your pdf data download
{ (response) in
let data = response.data
var writeUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last
writeUrl = writeUrl?.appendingPathComponent("aeon-billing-statement.pdf")
try! data.write(to: writeUrl!)
return writeUrl!
}
@mrvfino
mrvfino / TableViewWithAssortedCells.swift
Last active January 12, 2018 00:33
A clean pattern for dealing with tables that contain assorted cells.
import UIKit
// TODO: Create custom protocol.
class ViewController: UIViewController {
enum TableViewAssortedCellTypes {
case withSwitch(isOn: Bool)
case withImage(imageName: String)