Skip to content

Instantly share code, notes, and snippets.

View dipendra-sharma's full-sized avatar

Dipendra Sharma dipendra-sharma

View GitHub Profile
@emil2k
emil2k / Connectivity.java
Last active December 22, 2023 06:03
Android utility class for checking device's network connectivity and speed.
/*
* Copyright (c) 2017 Emil Davtyan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@koesie10
koesie10 / ApiModule.java
Created October 3, 2015 07:40
Retrofit 1 error handling behaviour in Retrofit 2
// Dagger 1 example
@Module(
complete = false,
library = true
)
public final class ApiModule {
@Provides
@Singleton
Retrofit provideRetrofit(Gson gson, Application app) {
return new Retrofit.Builder()
@pwlin
pwlin / gist:8a0d01e6428b7a96e2eb
Last active July 20, 2024 17:34
Android : add cert to system store
https://code.google.com/p/android/issues/detail?id=32696#c5
If you have a certificate that is not
trusted by Android, when you add it, it goes in the personal cert store.
When you add a cert in this personal cert store, the system requires a
higher security level to unlock the device. But if you manage to add your
cert to the system store then you don't have this requirement. Obviously,
root is required to add a certificate to the system store, but it is quiet
easy.
@vzsg
vzsg / RxAlamofire+Multipart.swift
Created July 26, 2017 09:28
Alamofire+RX multipart encoding
import Foundation
import Alamofire
import RxSwift
extension Reactive where Base: SessionManager {
func encodeMultipartUpload(to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders = [:], data: @escaping (MultipartFormData) -> Void) -> Observable<UploadRequest> {
return Observable.create { observer in
self.base.upload(multipartFormData: data,
to: url,
method: method,
@florina-muntenescu
florina-muntenescu / BaseDao.kt
Last active July 8, 2024 12:48
Use Dao inheritance to reduce the amount of boilerplate code - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@dentechy
dentechy / WSL-ssh-server.md
Last active July 14, 2024 03:54
A step by step tutorial on how to automatically start ssh server on boot on the Windows Subsystem for Linux

How to automatically start ssh server on boot on Windows Subsystem for Linux

Microsoft partnered with Canonical to create Bash on Ubuntu on Windows, running through a technology called the Windows Subsystem for Linux. Below are instructions on how to set up the ssh server to run automatically at boot.

  1. Edit the /etc/ssh/sshd_config file by running the command sudo vi /etc/ssh/sshd_config and do the following
    1. Change Port to 2222 (or any other port above 1000)
    2. Change PasswordAuthentication to yes. This can be changed back to no if ssh keys are setup.
  2. Restart the ssh server:
    • sudo service ssh --full-restart
  3. With this setup, the ssh server must be turned on every time you run Bash on Ubuntu on Windows, as by default it is off. Use this command to turn it on:
@bleeding182
bleeding182 / App.kt
Created March 30, 2018 17:52
Dagger 2 `@PerScreen` scope surviving configuration change
class App : Application() {
@Inject
lateinit var applicationInjector: ApplicationInjector
override fun onCreate() {
super.onCreate()
DaggerAppComponent.create().inject(this)
registerActivityLifecycleCallbacks(applicationInjector)
@darrarski
darrarski / RxSwift_Observable_RetryCountWhen.swift
Last active February 19, 2020 11:43
RxSwift Observable Retry When with Count
extension ObservableType {
func retry(_ maxAttemptCount: Int = 1, when: @escaping (Error) -> Observable<Void>) -> Observable<E> {
return retryWhen { errorObservable -> Observable<Void> in
var retries = maxAttemptCount
return errorObservable.flatMap { error -> Observable<Void> in
guard retries > 0 else { return Observable.error(error) }
retries -= 1
return when(error)
}
}
@chinmaygarde
chinmaygarde / Dockerfile
Created July 2, 2018 18:09
Flutter Android on Docker
# Flutter (https://flutter.io) Developement Environment for Linux
# ===============================================================
#
# This environment passes all Linux Flutter Doctor checks and is sufficient
# for building Android applications and running Flutter tests.
#
# To build iOS applications, a Mac development environment is necessary.
#
FROM debian:stretch