Skip to content

Instantly share code, notes, and snippets.

import UIKit
extension CAGradientLayer {
enum Point {
case topLeft
case centerLeft
case bottomLeft
case topCenter
guard var components = URLComponents(string: urlString) else {return}
components.queryItems = [ URLQueryItem(name: "jid", value: jid), URLQueryItem(name: "key", value: encrypted)]
components.percentEncodedQuery = components.percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B")
let url = components.url
@Denismih
Denismih / TextSize.swift
Created March 11, 2019 12:41 — forked from gnou/TextSize.swift
Calculate height of some text when width is fixed
public struct TextSize {
fileprivate struct CacheEntry: Hashable {
let text: String
let font: UIFont
let width: CGFloat
let insets: UIEdgeInsets
fileprivate var hashValue: Int {
return text.hashValue ^ Int(width) ^ Int(insets.top) ^ Int(insets.left) ^ Int(insets.bottom) ^ Int(insets.right)
@Denismih
Denismih / CoreDataController.swift
Created March 7, 2019 06:22 — forked from kharrison/CoreDataController.swift
Swift wrapper for NSPersistentContainer - Easy Core Data Setup with iOS 10
//
// CoreDataController.swift
//
// Created by Keith Harrison http://useyourloaf.com
// Copyright (c) 2017 Keith Harrison. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright
@Denismih
Denismih / AGAudioRecorder
Created January 31, 2019 14:59 — forked from AshvinGudaliya/AGAudioRecorder.swift
Simple Audio recorder and player in swift 4
//
// AGAudioRecorder.swift
// BaseProject
//
// Created by AshvinGudaliya on 17/09/18.
// Copyright © 2018 AshvinGudaliya. All rights reserved.
//
import UIKit
import AVFoundation
@Denismih
Denismih / AudioRecorder.swift
Created January 31, 2019 14:58 — forked from sssbohdan/AudioRecorder.swift
Audio recorder with simple interface, Swift 4
import Foundation
import AVFoundation
protocol AudioRecorder {
func checkPermission(completion: ((Bool) -> Void)?)
/// if url is nil audio will be stored to default url
func record(to url: URL?)
func stopRecording()
import MobileCoreServices
func mimeTypeForPath(path: String) -> String {
let url = NSURL(fileURLWithPath: path)
let pathExtension = url.pathExtension
if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension! as NSString, nil)?.takeRetainedValue() {
if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
return mimetype as String
}
@Denismih
Denismih / AttachmentHandler.swift
Created January 29, 2019 13:42 — forked from deepakraj27/AttachmentHandler.swift
Access Camera, Photo Library, Video and File from User device using Swift 4
//
// AttachmentHandler.swift
// AttachmentHandler
//
// Created by Deepak on 25/01/18.
// Copyright © 2018 Deepak. All rights reserved.
//
import Foundation
import UIKit
func convertVideo(phAsset : PHAsset){
PHImageManager.default().requestAVAsset(forVideo: phAsset, options: PHVideoRequestOptions(), resultHandler: { (asset, audioMix, info) -> Void in
if let asset = asset as? AVURLAsset {
do {
let videoData = try Data.init(contentsOf: asset.url)
print(asset.url)
self.orginalVideo = asset.url
print("File size before compression: \(Double(videoData.count / 1048576)) mb")
let compressedURL = NSURL.fileURL(withPath: NSTemporaryDirectory() + NSUUID().uuidString + ".MP4")
@Denismih
Denismih / ImageMessage.swift
Created January 24, 2019 14:43 — forked from rinat-enikeev/ImageMessage.swift
Chatto ImageMessage
// MARK: - ImageMessageModel
import Chatto
import ChattoAdditions
protocol ImageMessageModelProtocol: PhotoMessageModelProtocol {
var url: URL? { get set }
}
public class ImageMessageModel: PhotoMessageModel<MessageModel>, ImageMessageModelProtocol {