Skip to content

Instantly share code, notes, and snippets.

View ravitripathi's full-sized avatar
🎯
Focusing

Ravi Tripathi ravitripathi

🎯
Focusing
View GitHub Profile
@ravitripathi
ravitripathi / split.txt
Created March 18, 2021 07:31
Split file based on text
gcsplit logcopy.txt '/FLUTTEREXP: START/' '{*}' --prefix "run"
@ravitripathi
ravitripathi / Data+PrettyPrint.swift
Created January 19, 2020 12:50 — forked from cprovatas/Data+PrettyPrint.swift
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@ravitripathi
ravitripathi / firebasedb.swift
Last active October 4, 2018 12:18
Wrapper for Firebase db callbacks
func listenForAllChildEvents(atPath path: String, completion: @escaping(_ snapshot: DataSnapshot?, _ error: Error?, _ eventType: DataEventType?) -> ()) {
var ref: DatabaseReference!
ref = Database.database().reference()
let itemRef = ref.root.child(path)
itemRef.observe(.childAdded, with: { (snapshot) in
completion(snapshot,nil,DataEventType.childAdded)
}) { (error) in
completion(nil,error,nil)
}
itemRef.observe(.childMoved, with: { (snapshot) in
var formatter = DateFormatter ()
formatter.timeStyle = "hh mm"
//Instead use this:
var formatter = DateFormatter ()
formatter.timeStyle = .shortStyle
English photo
Bahasa foto
French photo
Russian Фото
English picture
Bahasa gambar
French image
Russian картина