Skip to content

Instantly share code, notes, and snippets.

View Audhil's full-sized avatar
🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
View GitHub Profile
@Audhil
Audhil / build.gradle
Created August 23, 2020 16:44
instrumention tests dependencies - app/build.gradle
dependencies {
...
// For instrumented tests.
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha'
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.28-alpha'
androidTestImplementation "io.mockk:mockk-android:1.9.3"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:4.6.0"
...
}
@Audhil
Audhil / balParenthesis.java
Created August 23, 2020 11:16
check is it given string is balanced parenthesis?!
public static void main(String[] args) {
HashMap<Character, Character> map = new HashMap<>();
map.put('(', ')');
map.put('{', '}');
map.put('[', ']');
String ipString = "{[}]";
System.out.println(isBalancedParenthesis(map, ipString));
}
@Audhil
Audhil / bxUbx.java
Created August 20, 2020 19:11
wrapper classes - (auto)boxing & (auto)unboxing
public static void main(String[] args) {
int i = 10;
Integer ii = new Integer(i); // boxing - putting primitive type in wrapper classes
Integer iii = i; // auto-boxing - putting primitive type in wrapper classes
int j = ii.intValue(); // unboxing - getting primitive type from wrapper classes
int jj = iii; // auto-unboxing - gettingg primitive types from wrapper classes
System.out.println(i);
System.out.println(ii);
@Audhil
Audhil / operatorOverLoading.kt
Last active August 18, 2020 19:53
kotlin operator overloading - ref: https://kotlinlang.org/docs/reference/operator-overloading.html to find allowed operators to overload
fun main() {
val bluePen = Pen(inkColor = "Blue")
bluePen.showInkColor()
val blackPen = Pen(inkColor = "Black")
blackPen.showInkColor()
val blueBlackPen = bluePen + blackPen
blueBlackPen.showInkColor()
}
@Audhil
Audhil / dataClassDemo.kt
Last active August 17, 2020 15:55
data class in kotlin demo - auto implemented equals(), hashcode(), and toString() methods. special function copy() make new reference or new object when data modified
fun main() {
val emp1 = Employee(name = "audhil", id = 33)
val emp2 = Employee(name = "audhil", id = 33)
if (emp1 == emp2) {
println("equal")
} else
println("not equal")
println(emp1.hashCode())
@Audhil
Audhil / DummyActivity.kt
Created August 14, 2020 16:46
app to display - current time in different timezones - keeping this for reference
// based on http://www.theappguruz.com/blog/android-time-zone-demo
class DummyActivity : Activity() {
private var spinnerAvailableID: Spinner? = null
private var current: Calendar? = null
private var textTimeZone: TextView? = null
private var txtCurrentTime: TextView? = null
private var txtTimeZoneTime: TextView? = null
private var miliSeconds: Long = 0
private var idAdapter: ArrayAdapter<String>? = null
@Audhil
Audhil / DummyActivity.kt
Created August 14, 2020 16:46
app to display - current time in different timezones - keeping this for reference
// based on http://www.theappguruz.com/blog/android-time-zone-demo
class DummyActivity : Activity() {
private var spinnerAvailableID: Spinner? = null
private var current: Calendar? = null
private var textTimeZone: TextView? = null
private var txtCurrentTime: TextView? = null
private var txtTimeZoneTime: TextView? = null
private var miliSeconds: Long = 0
private var idAdapter: ArrayAdapter<String>? = null
@Audhil
Audhil / WaitNotifyDemo.java
Created August 1, 2020 19:56
wait() & notify() of Object class - for ref: https://www.youtube.com/watch?v=A1tnVMpWHh8
public class WaitNotifyDemo {
public static void main(String[] args) {
Q q = new Q();
new Producer(q);
new Consumer(q);
}
static class Q {
private int num;
@Audhil
Audhil / DeepCloneDemo.java
Created July 30, 2020 19:28
Deep Copy / clone in java - that supports changing member class data as well
public class DeepCloneDemo {
public static void main(String[] args) throws CloneNotSupportedException {
Employee employee = new Employee("audhil", 31, new Address(11, 782382));
System.out.println("employee:" + employee);
Employee employee2 = (Employee) employee.clone();
System.out.println("employee2:" + employee2);
employee2.setAddress(new Address(33, 4342));
System.out.println("employee:" + employee);
System.out.println("employee2:" + employee2);
@Audhil
Audhil / ShallowCloneDemo.java
Last active July 30, 2020 19:29
Shallow Copy in Java - it doesn't support member classes, suitable for classes with only primitive types
public class ShallowCloneDemo {
public static void main(String[] args) throws CloneNotSupportedException {
Employee employee = new Employee("audhil", 31);
System.out.println(employee);
Employee employee2 = (Employee) employee.clone();
System.out.println(employee2);
employee2.setAge(33);
employee2.setName("yup");
System.out.println(employee2);
}