Skip to content

Instantly share code, notes, and snippets.

@drulabs
drulabs / AppDelegate.Swift
Last active August 15, 2017 15:08
Request notification permission iOS
// displaying only relevant content not all the functions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// other stuff of didFinishLaunchingWithOptions inside app delegate
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
@drulabs
drulabs / AppDelegate_FCM_Data.swift
Last active August 15, 2017 15:52
Receive data from remote notification
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("Dhruw: Dumping notification payload")
if application.applicationState != .active {
let value1: String? = userInfo["key1"] as? String
let value2: String? = userInfo["key2"] as? String
let value3: Bool? = userInfo["key3"] as? Bool
// do something with the received data
}
}
@drulabs
drulabs / FCM_json_sample.json
Created August 15, 2017 16:13
JSON structure of firebase cloud messaging
// HTTP URL : https://fcm.googleapis.com/fcm/send
{
"registration_ids":["XXXXXXXXXXXX:APA91XXXX7ziO-XXXXXXXXXXXXXXXXXXXXXX3B7OzLmNoAfHmZ3ju1M8gk7d-fYwXXXXXXdOHiwNhP6ThXNizSAu-Q0RkywWR8YCEiXf6a4Y803HY1t-XXXXXXXXXXX"],
"notification": {
"title":"Venue change for Avengers secret meet",
"body":"Tap here to open location on your phone"
},
"data": {
"latitude" : "39.204720",
"longitude" : "-96.564909",
@drulabs
drulabs / FCM_message_single_device_curl_command.txt
Last active June 14, 2023 15:27
Curl command for sending FCM message
curl -i -H 'Content-type: application/json' -H 'Authorization: key=<your_server_key>' -XPOST https://fcm.googleapis.com/fcm/send -d '{
"registration_ids":["registration_ids", "of the", "target", "devices as array"],
"notification": {
"title":"Title of your notification",
"body":"content of your notification"
},
"data": {
"key1" : "value1",
"key2" : "value2",
"key3" : 23.56565,
@drulabs
drulabs / introrx.md
Created October 26, 2017 10:35 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@drulabs
drulabs / .vscodestyle.css
Last active June 26, 2018 03:51
my vs code style
.monaco-shell {
font-family: "Operator Mono", "Inconsolata", monospace;
}
/* This makes the dirty tab circle yellow */
.vs-dark
.monaco-workbench
> .part.editor
> .content
> .one-editor-silo
@drulabs
drulabs / CodeHard.xccolortheme
Last active June 26, 2018 05:32
my xcode color scheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0 0 0 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SFMono-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0 0 0 1</string>
Bank bank = .... ;
List<Customer> customers = bank.getCustomers(); // Get all bank customers
List<Transaction> = customer.getTransactions(); // Get all transactions by 1 customer
double amount = transaction.getAmount(); // Get transaction amount
String transactionType = transaction.getType(); // Get type of transaction (deposit or withdraw)
@drulabs
drulabs / MinBalanceCustomer.java
Last active August 7, 2018 13:03
Find customer with minimum balance
// JAVA WAY - Who has minimum balance
Customer minBalanceCustomer = Collections.min(
customers, (o1, o2) -> (int) (o1.getBalance() - o2.getBalance())
);
// THE KOTLIN WAY
// 1. Who did maximum number of transactions
val maxTransactionsBy = customers.maxBy { it.transactions.count() }
// List all transactions irrespective of customers
val transactions = customers.flatMap { it.transactions }
// 2a. Get total amount deposited in the bank (use transactions constant from above)
val totalAmountDeposited = transactions.filter { it.type == "deposit" }.sumByDouble { it.amount }