Skip to content

Instantly share code, notes, and snippets.

View Tulakshana's full-sized avatar

Tula Tulakshana

View GitHub Profile
@Tulakshana
Tulakshana / Data+File.swift
Created November 14, 2018 23:38
An extension for Data to get the file extension
extension Data {
private static let mimeTypeSignatures: [UInt8 : String] = [
0xFF : "image/jpeg",
0x89 : "image/png",
0x47 : "image/gif",
0x49 : "image/tiff",
0x4D : "image/tiff",
0x25 : "application/pdf",
0xD0 : "application/vnd",
0x46 : "text/plain",
@Tulakshana
Tulakshana / CustomSlider.swift
Last active June 28, 2023 14:35
A subclass of UISlider which has a tool tip indicating the current value of the slider.
import UIKit
class CustomSlider: UISlider {
private var toolTip: ToolTipPopupView?
override func awakeFromNib() {
super.awakeFromNib()
self.initToolTip()
@Tulakshana
Tulakshana / MyAPI.swift
Last active April 20, 2023 12:31
Handling re-direction with URLSession (Swift)
import UIKit
@objc class MyAPI: NSObject {
static let keyError: String = "Error"
static let keyResult: String = "Result"
static let unknownError: String = "Unknown error"
static let notificationMyAPIDidEnd = Notification.Name(rawValue: "notificationMyAPIDidEnd")
@Tulakshana
Tulakshana / MovieTransitionsVC.swift
Last active January 12, 2023 08:25 — forked from SheffieldKevin/movietransitions.swift
Make a movie with transitions with AVFoundation and swift. Add an UIActivityIndicatorView and an UIButton and connect appropriately. You will also need to attach few videos to the project.
//
// MovieTransitionsVC.swift
// VideoAnimations
//
// Created by Tula on 2018-06-14.
// Copyright © 2018 Tula. All rights reserved.
//
import UIKit
import AVFoundation
@Tulakshana
Tulakshana / CustomButton.swift
Created November 13, 2017 12:55
A custom UIButton which could have different background colours for enabled and disabled states.
class CustomButton: UIButton {
@IBInspectable private var enabledBackgroundColor: UIColor?
@IBInspectable private var disabledBackgroundColor: UIColor?
override var isEnabled: Bool {
set {
if newValue {
self.backgroundColor = enabledBackgroundColor
} else {
self.backgroundColor = disabledBackgroundColor
@Tulakshana
Tulakshana / smartZip.sh
Created April 7, 2022 02:42
Script to create a zip file in macOS without .DS_Store and __MACOSX files. Run this script inside the folder you want to zip.
zip -r smart.zip . -x "*.DS_Store" -x "__MACOSX"
@Tulakshana
Tulakshana / androidDockerFile
Last active March 13, 2022 08:31
Docker steps to install packages using sdkmanager (Android)
ENV ANDROID_HOME_DIR=/opt/tools/android-sdk-linux
ENV SDK_MANAGER=$ANDROID_HOME/cmdline-tools/bin/sdkmanager
ENV TEMP_DIR=<Path to a temporary directory you download files to. e.g. /tmp/install>
ENV ANDROID_TOOLS_VERSION=30.0.3
ENV ANDROID_BUILD_VERSION=32
ADD <path to SDK tools. Refer command line tools in https://developer.android.com/studio#downloads> $TEMP_DIR/
RUN mkdir -p $ANDROID_HOME_DIR && \
cd $ANDROID_HOME_DIR && \
unzip $TEMP_DIR/<zip file name downloaded above> && \
@Tulakshana
Tulakshana / TouchDetectingView.swift
Created November 18, 2021 15:52
A sub class of UIView with delegate methods to detect pan gestures with direction and displacement.
import UIKit
protocol TouchDetectingViewDelegate: NSObjectProtocol {
func touchDetectingViewDidDetectPan(view: TouchDetectingView,
direction: TouchDetectingView.Direction,
displacement: CGFloat,
state: UIGestureRecognizer.State)
func touchDetectingViewPanEnded(view: TouchDetectingView)
}
@Tulakshana
Tulakshana / FYISession.swift
Last active November 25, 2020 09:42
Saving custom objects in NSUserDefaults - Swift
import Foundation
class FYISession {
let savedUserKey = "savedUser"
static let sharedInstance = FYISession()
var user:FYIUser = FYIUser(userId: 0, userMobile: "", userEmail: "", userName: "")
func userLoggedIn() -> Bool{
@Tulakshana
Tulakshana / VideoHelper.swift
Created August 7, 2019 21:33
Use this to save a video to an album in the phone gallery. The method creates the album if it doesn't exists.
import Photos
class VideoHelper {
private static func createAlbum(name: String, completion: @escaping ((_ collection: PHAssetCollection?) -> Void)) {
//Get PHFetch Options
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", name)
let collection : PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions)
//Check return value - If found, then get the first album out