Skip to content

Instantly share code, notes, and snippets.

View ViksaaSkool's full-sized avatar
:octocat:
I've set my status

ViksaaSkool ViksaaSkool

:octocat:
I've set my status
View GitHub Profile
@ViksaaSkool
ViksaaSkool / DrawableMatcher.java
Last active March 25, 2017 16:24
DrawableMatcher for medium article https://is.gd/Ru0XVF
public class DrawableMatcher extends TypeSafeMatcher<View> {
private final int expectedId;
private String resourceName;
private int isAnimatedDrawable = -1;
private int randomFrame = 0;
public DrawableMatcher(int expectedId) {
super(View.class);
@ViksaaSkool
ViksaaSkool / PerfectLoopMediaPlayer.java
Last active November 14, 2021 13:40
PerfectLoopMediaPlayer because it's 2017 and this is still an issue on Android
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.util.Log;
import java.io.IOException;
/**
* Created by viksaaskool on 13-04-2017.
*/
@ViksaaSkool
ViksaaSkool / KotlinBasics.kt
Last active October 7, 2018 21:51
KotlinBasics
/* Declaring variables */
//[val/var] name_of_variable : [type] = value
//no need for ; at the end of the line
val a: Int = 1
var b: String = "NullPointerException is dead"
var c: Double? = 0.4
//val - read only value, constant
@ViksaaSkool
ViksaaSkool / UtilsAndExtensions.kt
Last active December 9, 2018 23:12
UtilsAndExtensions
//A higher-order function is a function that takes functions as parameters, or returns a function. kotlin has the power
//to pass around functions
/* Lambdas */
//by definition, lambda expressions are functions that are not declared, but passed immediately as an expression
//surrounded by curly braces and the body goes after ->
//very basic definition
val sum = { x: Int, y: Int -> x + y }
@ViksaaSkool
ViksaaSkool / KotlinCoroutines.kt
Last active December 9, 2018 21:10
Some Kotlin Coroutines basics
//
@ViksaaSkool
ViksaaSkool / DelegatedProperties.kt
Last active December 9, 2018 21:04
DelegatedProperties
//we have class called Delegate that defines how to get and set values
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return "$thisRef, thank you for delegating '${property.name}' to me!"
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
println("$value has been assigned to '${property.name}' in $thisRef.")
}
}
@ViksaaSkool
ViksaaSkool / HigherOrderFunctions.kt
Last active December 9, 2018 17:05
Higher-order functions
/* With */
//receives an object, and a function that will be executed as an extension function, which means that with can be used
//inside of a function to refere to the object, i.e. do something "with"
inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
//example
fun getPersonFromDeveloper(developer: Developer): Person {
return with(developer) {
Person(developerName, developerAge)
}
@ViksaaSkool
ViksaaSkool / KotlinGenerics.kt
Last active December 9, 2018 18:25
Example for Kotlin Generics - MyKotlinSharedPreference call when storing/retrieving any type of primitive data
//One very powerful example of Generics might in combination with delegates is creation of SharedPreferences support
//taken from Kotlin for Android Developers by Antonio Leiva
class MyKotlinSharedPreference<T>(val context: Context, val name: String, val default: T) {
val prefs by lazy {
context.getSharedPreferences("default", Context.MODE_PRIVATE)
}
//operator overloading
@ViksaaSkool
ViksaaSkool / generate_stand_up_comedians_twitter_accounts_list.ipynb
Created April 1, 2020 22:04
generate_stand_up_comedians_twitter_accounts_list.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ViksaaSkool
ViksaaSkool / get_twitter_data_example.ipynb
Created April 10, 2020 01:37
get_twitter_data_example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.