Skip to content

Instantly share code, notes, and snippets.

@MaciejGad
MaciejGad / FTPUpload.swift
Created October 10, 2018 09:51 — forked from Nirma/FTPUpload.swift
Upload a file via FTP on iOS or macOS
import Foundation
import CFNetwork
public class FTPUpload {
fileprivate let ftpBaseUrl: String
fileprivate let directoryPath: String
fileprivate let username: String
fileprivate let password: String
import Foundation
func add(_ char:Character, to input:String, pattern:[UInt]) -> String {
guard pattern.reduce(0, +) > 0 else { return input }
var str = input
var index:String.Index? = str.startIndex
var i = 0
while index != nil {
let offset = pattern[i%pattern.count]
i += 1
//
// NibBaseViewController.swift
//
// Created by Maciej Gad on 23/09/2018.
// Copyright © 2018 Maciej Gad. All rights reserved.
//
import Foundation
import UIKit
#!/bin/bash
info="Info.plist"
plistBuddy=/usr/libexec/PlistBuddy
version=`$plistBuddy -c "print CFBundleVersion" "$info"`
echo "Current version: $version"
((version++))
echo "New version: $version"
$plistBuddy -c "set CFBundleVersion $version" "$info"
@MaciejGad
MaciejGad / HideTabBar.swift
Last active June 11, 2018 18:42
Hiding TabBar with animation
extension UITabBarController {
func set(visible: Bool, animated: Bool, completion: ((Bool)->Void)? = nil ) {
guard isVisible() != visible else {
completion?(true)
return
}
let offsetY = tabBar.frame.size.height
@MaciejGad
MaciejGad / NibBaseViewController.swift
Created July 26, 2017 12:14
NibBaseViewController
import Foundation
import UIKit
enum NibBaseError:Error {
case badClassName
case noNibFile
case noStoryboard
}
class NibBaseViewController: UIViewController, IsNibBaseViewController {
@MaciejGad
MaciejGad / NSImageExtensions.swift
Created March 24, 2017 11:49
NSImage extensions for easy resizing, cropping and saving png images. Version updated for Swift 3. Originally by Raphael Hanneken https://gist.github.com/raphaelhanneken/cb924aa280f4b9dbb480
extension NSImage {
/// Returns the height of the current image.
var height: CGFloat {
return self.size.height
}
/// Returns the width of the current image.
var width: CGFloat {
return self.size.width
@MaciejGad
MaciejGad / file.m
Last active April 14, 2016 19:38
Set image with URL
//remember to intall AFNetworking https://github.com/AFNetworking/AFNetworking#installation-with-cocoapods
//and add import :
//#import "UIImageView+AFNetworking.h"
- (void)setImageFromDictionary:(NSDictionary *)dic2 {
NSString *path = dic2[@"safe_value"];
if (![path isKindOfClass:[NSString class]]) {
return;
}
NSURL *imageUrl = [NSURL URLWithString:path];
@MaciejGad
MaciejGad / hanoi.swift
Last active October 6, 2018 23:49
Simple implementation of hanoi algorithm. If you want more information about this algorithm watch this video https://www.youtube.com/watch?v=3YH0SZYAzOQ
enum Tower:String {
case A
case B
case C
}
func hanoi(_ disk: Int, from: Tower, using: Tower,
to: Tower, output: inout [String]) {
if disk == 1 {
output.append("\(from.rawValue)->\(to.rawValue)")
if [ "$CONFIGURATION" = "Ad hoc" ] || [ "$CONFIGURATION" = "Release" ]; then
echo "Bumping build number..."
plist=${PROJECT_DIR}/${INFOPLIST_FILE}
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "No build number in $plist"
exit 2
fi