Skip to content

Instantly share code, notes, and snippets.

View pvn's full-sized avatar

Praveen Kumar pvn

View GitHub Profile
@pvn
pvn / tvosbuttonpresses.swift
Created January 1, 2023 14:45
tvOS: Detecting Button Presses
override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
guard let buttonPress = presses.first?.type else { return }
switch(buttonPress) {
case .menu:
print("Menu")
case .playPause:
print("Play/Pause")
case .select:
print("select")
//
// Uiview.swift
// Created by praveen shrivastav on 26/08/2021.
//
import UIKit
extension UIView{
func makeGradientView(_ colorOne:UIColor,colorTwo:UIColor ){
@pvn
pvn / PKDataManager.swift
Created September 26, 2018 21:01
Helper methods for storing data in UserDefaults using PKDataManager class
class PKDataManager {
static let defaults = UserDefaults.standard
// check if 'key' is present in user defaults
static func isKeyPresentInUserDefaults(key: String) -> Bool {
return defaults.object(forKey: key) != nil
}
// store the SETs as string for given 'key' in user defaults
@pvn
pvn / ColorExtension.swift
Created September 16, 2018 17:50
Color extension using swift
import Foundation
import UIKit
extension UIColor {
convenience init(hexString: String, alpha: CGFloat = 1.0) {
let hexString: String = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
let scanner = Scanner(string: hexString)
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
@pvn
pvn / StringExtension.swift
Last active September 27, 2018 18:28
String extension using swift
extension String
{
var length: Int {
get {
return self.count
}
}
var startToEndRange: Range<String.Index> {
get {
let start = self.index(self.startIndex, offsetBy: 0)
@pvn
pvn / ArrayExtension.swift
Last active September 15, 2018 00:34
Swift: Array Extension
/* Compare two array has the same value */
// firstArray = ['A', 'B', 'C', 'A']
// secondArray = ['A', 'B', 'C', 'A']
// firstArray.isDuplicateOf(secondArray)
extension Array where Element: Comparable {
func isDuplicateOf(as other: [Element]) -> Bool {
return self.count == other.count && self.sorted() == other.sorted()
}
@pvn
pvn / linked_list.py
Last active August 30, 2020 14:07
Linked list implementation with add, search, delete, output operation
class Node:
def __init__(self, data):
self.data = data
self.next = None
return
def has_value(self, value):