Skip to content

Instantly share code, notes, and snippets.

View Ilesh's full-sized avatar
:octocat:
Learn | Build | Test | 🚀

Ile$h Ilesh

:octocat:
Learn | Build | Test | 🚀
View GitHub Profile
@Ilesh
Ilesh / getRequest.swift
Created September 6, 2020 16:48 — forked from gkye/getRequest.swift
NSURLSession: GET Request with parameters swift 2.0
//Encode params to be web friendly and return a string. Reference ->http://stackoverflow.com/a/27724627/6091482
extension String {
/// Percent escapes values to be added to a URL query as specified in RFC 3986
///
/// This percent-escapes all characters besides the alphanumeric character set and "-", ".", "_", and "~".
///
/// http://www.ietf.org/rfc/rfc3986.txt
///
@Ilesh
Ilesh / ArrayDeepCopy.swift
Created September 2, 2019 10:48 — forked from sohayb/ArrayDeepCopy.swift
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@Ilesh
Ilesh / compareimages.swift
Created July 26, 2019 12:41 — forked from SheffieldKevin/compareimages.swift
A couple of swift functions for comparing two CGImage using CIImage in OS X
/**
@brief Returns true if images have same meta. Width, Height, bit depth.
@discussion Assumes images are non null.
*/
func doImagesHaveSameMeta(#image1:CGImage, #image2:CGImage) -> Bool {
if CGImageGetWidth(image1) != CGImageGetWidth(image2) {
return false
}
if CGImageGetHeight(image1) != CGImageGetHeight(image2) {
@Ilesh
Ilesh / MIDISamplerSetup
Created May 24, 2019 11:38 — forked from genedelisa/MIDISamplerSetup
Swift MIDI Sampler setup
class MIDISampler : NSObject {
var engine:AVAudioEngine!
var playerNode:AVAudioPlayerNode!
var mixer:AVAudioMixerNode!
var sampler:AVAudioUnitSampler!
override init() {
super.init()
initAudioEngine()
}
@Ilesh
Ilesh / testflight.sh
Created February 13, 2019 06:17 — forked from keith/testflight.sh
Upload an ipa to testflight using altool
#!/bin/bash
set -e
set -u
altool="$(dirname "$(xcode-select -p)")/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Support/altool"
ipa="path/to/foo.ipa"
echo "Validating app..."
time "$altool" --validate-app --type ios --file "$ipa" --username "$ITC_USER" --password "$ITC_PASSWORD"
@Ilesh
Ilesh / README-Template.md
Created January 24, 2019 06:00 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

// MARK: - KVO
var observedPaths: [String] = []
// Usage - observeKVO(keyPath: #keyPath(camera.inputCamera.whiteBalanceMode))
func observeKVO(keyPath: String) -> Bool {
if shouldObserveKVO {
if self.classForCoder.automaticallyNotifiesObservers(forKey: keyPath) {
observedPaths.append(keyPath)
addObserver(self, forKeyPath: keyPath, options: [.old, .new], context: nil)
class SpinView: UIView {
private var animating: Bool = false
private func spin(with options: UIViewAnimationOptions) {
// this spin completes 360 degrees every 2 seconds
UIView.animate(withDuration: 0.5, delay: 0, options: options, animations: {() -> Void in
self.transform = self.transform.rotated(by: .pi / 2)
}, completion: {(_ finished: Bool) -> Void in
if finished {
if self.animating {
@Ilesh
Ilesh / NormalizingOrientation.swift
Created January 23, 2019 12:56 — forked from NikhilManapure/NormalizingOrientation.swift
Code for making image's orientation as .up
func imageByNormalizingOrientation() -> UIImage {
if imageOrientation == .up {
return self
}
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(in: CGRect(origin: CGPoint.zero, size: size))
let normalizedImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return normalizedImage!
}