Skip to content

Instantly share code, notes, and snippets.

View raghunandankavi2010's full-sized avatar
🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.

Raghunandan Kavi raghunandankavi2010

🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.
View GitHub Profile
@raghunandankavi2010
raghunandankavi2010 / GitGist.md
Created January 21, 2021 06:29
Keep fork updated with origin remote master
  1. Clone your fork:

    git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

  2. Add remote from original repository in your forked repository:

    cd into/cloned/fork-repo git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git git fetch upstream

@raghunandankavi2010
raghunandankavi2010 / ticks.txt
Created January 17, 2021 10:47
Drawing ticks on circle circumference
for (int i = 0; i < TICK_COUNT; i++) {
float startAngle = (float) Math.toRadians(0f);
float angle = (float) ((startAngle + i) * (Math.toRadians(360)/TICK_COUNT));// * (Math.PI / TICK_COUNT));
int x = (int) ((radius* Math.cos(angle))+ cx);
int y = (int) ((radius* Math.sin(angle)) + cy);
int x1 = (int) (((radius+20)* Math.cos(angle))+ cx);
int y1= (int) (((radius+20)* Math.sin(angle)) + cy);
canvas.drawLine(
@raghunandankavi2010
raghunandankavi2010 / Git
Created January 14, 2021 04:50
adding remote repo as upstream
# Add a new remote upstream repository
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
# Sync your fork
git fetch upstream
git checkout master
git merge upstream/master
@raghunandankavi2010
raghunandankavi2010 / Flow.txt
Created January 14, 2021 03:48
rxjava equivalent in kotlin flow
flow<String> {
// suspending call here
emit("Foo")
}
.onStart { // show loading }
.onCompletion { // hide loading }
.catch { // exception handling }
.onEach { // equivalent to rx onNext }
.launchIn(yourScope)
@raghunandankavi2010
raghunandankavi2010 / gist:c7daf3b869b364e92de239fe1fb4dd64
Created October 27, 2020 08:11
Custom Circular Progress view with percentage text in center.
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import bg.dihanov.customviewexamples.R
import bg.dihanov.customviewexamples.px
import kotlin.math.max
import kotlin.math.min
inline fun <refied T: Any> Context.openActivity(noinline init: Intent.()-> Unit = {}){
val intent == newIntent<T>(this)
intent.init()
startActivity(intent)
}
inline <refied T: Any> fun newIntent(context: Context): Int{
Intent(context.T::class.kava)
@raghunandankavi2010
raghunandankavi2010 / Sharedpreferences
Created August 18, 2020 06:35
SharedPreferences edit inline function
// SharedPreferences extension function
// SharedPreferences.Editor.() - lambda with receiver
// call edit for the editor
// perform the action and apply edit.
inline fun SharedPreferences.edit(action: Sharedpreferenes.Editor.()->Unit) {
val edit = edit()
action.edit()
edit.apply()
}
public class InputStreamRequestBody extends RequestBody {
private final MediaType contentType;
private final ContentResolver contentResolver;
private final Uri uri;
public InputStreamRequestBody(MediaType contentType, ContentResolver contentResolver, Uri uri) {
if (uri == null) throw new NullPointerException("uri == null");
this.contentType = contentType;
this.contentResolver = contentResolver;
this.uri = uri;
suspend fun <T> retryIO(
times: Int = Int.MAX_VALUE,
initialDelay: Long = 100, // 0.1 second
maxDelay: Long = 1000, // 1 second
factor: Double = 2.0,
block: suspend () -> T): T
{
var currentDelay = initialDelay
repeat(times - 1) {
try {
@raghunandankavi2010
raghunandankavi2010 / environ.text
Created March 31, 2020 10:01
Adding to environment variable ubuntu
// edit /home/.bashrc and add the following lines
JAVA_HOME='/home/raghu/jdk1.8.0_241'
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
FLUTTER_HOME='/home/raghu/flutter'
export FLUTTER_HOME
export PATH=$PATH:$FLUTTER_HOME/bin
ANDROID_SDK_ROOT='/home/raghu/Android/Sdk'