Skip to content

Instantly share code, notes, and snippets.

View kshivang's full-sized avatar
🐨
>>> Faith in oneself not reality <<< 🐨

Shivang kshivang

🐨
>>> Faith in oneself not reality <<< 🐨
View GitHub Profile
@kshivang
kshivang / CombineLatestArray.swift
Last active August 2, 2024 12:55
CombineLatest extension for publisher array
// [publisher1, publisher2].combineLatest()
extension Array where Element: Publisher {
func combineLatest() -> AnyPublisher<[Element.Output], Element.Failure> {
Publishers.CombineLatestArray(self)
}
}
// Publishers.CombineLatestArray([publisher1, publisher2])
extension Publishers {
static func CombineLatestArray<P>(_ array: [P]) -> AnyPublisher<[P.Output], P.Failure> where P : Publisher {
@kshivang
kshivang / CombineFirebaseAuth+Publisher.swift
Last active November 18, 2023 19:51
Switch/Refresh publisher on Firebase Auth new login simple one-liner for rever-ai/CombineFirebase
func onLoginRefresher<T>(_ publisherGetter: @escaping () -> AnyPublisher<T, Never> ) -> AnyPublisher<T, Never> {
Auth.auth().stateDidChangePublisher
.filter { $0 != nil } // User LoggedIn
.map { _ in publisherGetter() }
.switchToLatest()
.eraseToAnyPublisher()
}
// e.g.: turn userDataPublisher to onLoginRefresher { userDataPublisher() } and done
//
set surround
let mapleader = ","
inoremap jk <Esc>
cnoremap jk <Esc>
map <leader>r :action RenameElement<CR>
map <Leader>g :action Generate<CR>
map <Leader><Leader> :action Run<CR>
@kshivang
kshivang / AVPlayer+Combine.swift
Last active July 10, 2024 16:47
Combine wrapper over AVPlayer.addPeriodicTimeObserver method. Use AVPlayer.periodicTimePublisher method instead.
import AVFoundation
import Combine
// simply use
// player.periodicTimePublisher()
// .receive(on: RunLoop.main)
// .assign(to: \SomeClass.elapsedTime, on: someInstance)
// .store(in: &cancelBag)
@kshivang
kshivang / BaseActivity.java
Last active October 11, 2020 16:16
Instagram like ViewPager implementation with bottom tab layout, without recreating fragments in fragment manager on tab select or back click. Implementation is prescribed for ViewPager inside fragment(more complex case) similar thing could be achieved for ViewPager in activity as well.
public abstract class BaseActivity extends AppCompatActivity {
public void moveBack() {
super.onBackPressed();
}
public abstract void onBackWhenNoFragment();
@Override
public void onBackPressed() {
@kshivang
kshivang / readingSmsMethodJava.md
Last active May 11, 2020 19:22
Magic souse to read sms from specific date..

Must be implemented through services

private long parseAllSmsFromProvider(long lastRead, ShortSms ignoreSms) {
            Uri uri = Uri.parse("content://sms/inbox");
            String[] columns = new String[]{"_id", "body", "address", "date_sent", "date", "case when date_sent IS NOT 0 then date_sent else date END as dateSent"};
            // If last read is 0 then assume to read from 6 months back sms
            if (lastRead == 0) {
                Calendar cal = Calendar.getInstance();
 cal.setTimeInMillis(System.currentTimeMillis());
@kshivang
kshivang / af
Last active December 12, 2017 11:02
Amazon S3 storage and Firebase Database indexing
#!/bin/bash
# Please pay attention to comment till line 12
# These are your configuration variables
# Configuration
SERVER="Amazon server where S3 is hosted" # "s3.ap-south-1"
BUCKET_NAME="S3 Bucket Name" #Bucket Name
FOLDER_PATH="/default/S3/FOLDER" # Default S3 Folder to upload
@kshivang
kshivang / .vimrc
Last active January 19, 2024 05:02
My vimrc
let g:python_host_prog='/usr/bin/python'
call plug#begin('~/.nvim/plugged')
Plug 'ryanoasis/vim-devicons' " For auto iconify vim
"Plug 'hsanson/vim-android' " For android development
Plug 'scrooloose/nerdcommenter' " Comment fast and professionally
Plug 'scrooloose/nerdtree' , {'on': 'NERDTreeToggle'} " Proper file explorer inside vim
"Plug 'justinmk/vim-dirvish'
Plug 'flazz/vim-colorschemes' " All popular Colorscheme
Plug 'tpope/vim-surround' " Quick Surround with tags or Brackets
Plug 'octol/vim-cpp-enhanced-highlight' " Enhanced syntax highlight for CPP files
@kshivang
kshivang / IITK Fortigate script to login
Last active April 14, 2017 19:24
This is python script can be used to login to iitk fortigate ip configured server.
#!/usr/bin/env python
import requests
import time
import re
import sys
import getpass
from bs4 import BeautifulSoup
def liveSession( html ):