Skip to content

Instantly share code, notes, and snippets.

View Daemon-Devarshi's full-sized avatar

Devarshi Kulshreshtha Daemon-Devarshi

View GitHub Profile
@Daemon-Devarshi
Daemon-Devarshi / unused_assets.py
Last active May 9, 2024 05:44
Python script to identify unused images in the Xcode - Swift project
# Usage e.g.: python3 unused_assets.py '/Users/DevK/MyProject' '/Users/DevK/MyProject/MyProject/Assets/Assets.xcassets'
# It is important to pass project folder path as first argument, assets folder path as second argument
# It is assumed that all the images are maintained within Assets.xcassets folder and are used either within swift files or within storyboards
"""
@author = "Devarshi Kulshreshtha"
@copyright = "Copyright 2020, Devarshi Kulshreshtha"
@license = "GPL"
@version = "1.0.2"
@contact = "kulshreshtha.devarshi@gmail.com"
@Daemon-Devarshi
Daemon-Devarshi / PasteboardWatcher.swift
Last active October 6, 2023 14:15
A class which performs polling to determine the newly copied url of desired kind in an external app
//
// PasteboardWatcher.swift
// PasteboardWatcher
//
// Created by Devarshi Kulshreshtha on 6/19/15.PasteboardWatcher
// Copyright © 2015 Devarshi Kulshreshtha. All rights reserved.
//
import Cocoa
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.runtime.*;
import java.io.FileInputStream;
import java.io.InputStream;
import org.antlr.v4.runtime.CharStreams;
export CLASSPATH=".:/usr/local/lib/antlr-4.11.1-complete.jar:$CLASSPATH"
alias antlr4='java -jar /usr/local/lib/antlr-4.11.1-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'
// Generates listeners
antlr4 ArrayInit.g4
// Compiles java listeners
javac -cp /usr/local/lib/antlr-4.7.1-complete.jar ArrayInit*.java
@Daemon-Devarshi
Daemon-Devarshi / CodableDate
Created October 22, 2020 14:45
Property wrappers to serialise date
extension Date {
static let decodeFormats: [String] = ["yyyy-MM-dd'T'HH:mm:ss.SSSZ"]
func encodedDateString() -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
return formatter.string(from: self)
}
}
@Daemon-Devarshi
Daemon-Devarshi / merge_sort.py
Last active April 25, 2020 06:58
Sorting algorithms in Python
# divide and conquer approach
def mergeSort(array):
# divides the array into sub-parts
length = len(array)
if length == 1 or length == 0:
# returns leaf node
return array
# obtain mid index
mid = length // 2
# obtain left array
@Daemon-Devarshi
Daemon-Devarshi / PlistDecoder.swift
Created October 26, 2019 05:30
A protocol and its extension supporting serialization of Plist to respective data model
import Foundation
/// Protocol supporting decoding of a plist to associated data model
protocol PlistDecoder {
associatedtype PlistModel: Decodable
func decodedValue() -> PlistModel?
}
/// Implementation of PlistDecoder with decoding capability
@Daemon-Devarshi
Daemon-Devarshi / ExtendedArrayController.swift
Created June 20, 2015 20:02
Extended NSArrayController in swift
extension NSArrayController {
/// Method which can be binded in storyboard to remove all objects from array controller
@IBAction func removeAllObjects(sender: AnyObject) {
let range = NSMakeRange(0, self.arrangedObjects.count)
self.removeObjectsAtArrangedObjectIndexes(NSIndexSet(indexesInRange: range))
}
}
@Daemon-Devarshi
Daemon-Devarshi / Pop.swift
Created October 27, 2016 08:44
Push animation using custom segue
protocol Pop {
func moveBackToParentViewController(currentViewController: UIViewController)
}
extension Pop {
func moveBackToParentViewController(currentViewController: UIViewController) {
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionMoveIn