Skip to content

Instantly share code, notes, and snippets.

View HassanElDesouky's full-sized avatar
:shipit:

Hassan ElDesouky HassanElDesouky

:shipit:
View GitHub Profile
@HassanElDesouky
HassanElDesouky / AppDelegateMethod.swift
Created December 13, 2018 14:23
setting up the window.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//New code starts from here
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let mainVC = ViewController()
window?.rootViewController = mainVC
//
// MainCollectionViewCell.swift
// ShortcutsCollectionView
//
// Created by Hassan El Desouky on 12/13/18.
// Copyright © 2018 Hassan El Desouky. All rights reserved.
//
import UIKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let layout = UICollectionViewFlowLayout()
let mainVC = ViewController(collectionViewLayout: layout)
window?.rootViewController = UINavigationController(rootViewController: mainVC)
return true
import UIKit
class AudioVisualizerView: UIView {
// Bar width
var barWidth: CGFloat = 4.0
// Indicate that waveform should draw active/inactive state
var active = false {
didSet {
if self.active {
@HassanElDesouky
HassanElDesouky / handleView.swift
Created January 18, 2019 15:05
01_medium_article_AppleVoiceMemosClone
//MARK:- Properties
var handleView = UIView()
//MARK:- Setup Methods
fileprivate func setupHandelView() {
handleView.layer.cornerRadius = 2.5
handleView.backgroundColor = UIColor(r: 208, g: 207, b: 205)
view.addSubview(handleView)
handleView.translatesAutoresizingMaskIntoConstraints = false
handleView.widthAnchor.constraint(equalToConstant: 37.5).isActive = true
handleView.heightAnchor.constraint(equalToConstant: 5).isActive = true
@HassanElDesouky
HassanElDesouky / Extensions.swift
Created January 18, 2019 15:06
02_medium_article_AppleVoiceMemosClone
import UIKit
public extension UIColor {
public convenience init(r: CGFloat, g: CGFloat, b: CGFloat) {
self.init(red: r/255, green: g/255, blue: b/255, alpha: 1)
}
}
extension Int {
var degreesToRadians: CGFloat {
return CGFloat(self) * .pi / 180.0
}
@HassanElDesouky
HassanElDesouky / recordButton.swift
Created January 18, 2019 15:09
03_medium_article_AppleVoiceMemosClone
var recordButton = RecordButton()
fileprivate func setupRecordingButton() {
recordButton.isRecording = false
recordButton.addTarget(self, action: #selector(handleRecording(_:)), for: .touchUpInside)
view.addSubview(recordButton)
recordButton.translatesAutoresizingMaskIntoConstraints = false
recordButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -32).isActive = true
recordButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
recordButton.widthAnchor.constraint(equalToConstant: 65).isActive = true
@HassanElDesouky
HassanElDesouky / handleRecording.swift
Created January 18, 2019 15:10
04_medium_article_AppleVoiceMemosClone
@objc func handleRecording(_ sender: RecordButton) {
if recordButton.isRecording {
audioView.isHidden = false
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.handleView.alpha = 1
self.timeLabel.alpha = 1
self.audioView.alpha = 1
self.view.frame = CGRect(x: 0, y: self.view.frame.height, width: self.view.bounds.width, height: -300)
self.view.layoutIfNeeded()
}, completion: nil)
import UIKit
class DSU {
private var parent: [Int] = []
private var sz: [Int] = []
init(length: Int) {
for i in 0..<length {
self.parent.append(i)
@HassanElDesouky
HassanElDesouky / Cpp_DSU.h
Created April 10, 2019 10:32
DSU article
//
// Created by Hassan El Desouky on 2019-04-01.
//
#ifndef PST_DSU_H
#define PST_DSU_H
class DSU {
public: