Skip to content

Instantly share code, notes, and snippets.

View Daemon-Devarshi's full-sized avatar

Devarshi Kulshreshtha Daemon-Devarshi

View GitHub Profile
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 / 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 / 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 / Stack
Created September 3, 2017 15:28
Implementation of a stack in swift which performs push, pop and peek operations with O(1) complexity
class Stack {
var lastNode: Node? = nil
class Node {
var data: Int!
var prev: Node?
init(data: Int, prev: Node?) {
self.data = data
self.prev = prev
}
protocol StoryboardIdentifiable {
static var storyboardIdentifier: String { get }
}
extension StoryboardIdentifiable where Self: UIViewController {
static var storyboardIdentifier: String {
return String(describing: self)
}
}
@Daemon-Devarshi
Daemon-Devarshi / Reusable.swift
Last active August 2, 2017 14:05
A protocol to be used to avoid hardcoding of reuse identifier
protocol Reusable: class {
static var reuseIdentifier: String { get }
}
extension Reusable {
static var reuseIdentifier: String {
// I like to use the class's name as an identifier
// so this makes a decent default value.
return String(describing: self)
}