Skip to content

Instantly share code, notes, and snippets.

View hardikm9850's full-sized avatar
🏠
Working from home

Hardik hardikm9850

🏠
Working from home
View GitHub Profile
@hardikm9850
hardikm9850 / kotlin-sealedclass-serialization.kt
Created November 22, 2023 17:03 — forked from krishnabhargav/kotlin-sealedclass-serialization.kt
Using GSON to support serialization and deserialization of Kotlin Sealed Classes.
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import kotlin.jvm.internal.Reflection
import kotlin.reflect.KClass
@hardikm9850
hardikm9850 / Flutter Clean.md
Created April 19, 2023 08:28 — forked from minhcasi/Flutter Clean.md
These are common issues on Flutter and solutions to fix

Quick Clean Cache

  1. Open android studio Tools->Flutter->Clean
  2. Go to File -> Invalidate Caches / Restart
  3. Or open terminal run "flutter clean"
  4. Remove pubspec.lock
  5. Double check the Flutter SDK Path config correcty - https://tppr.me/qn6dP

Or open the terminal and try this script:

flutter clean
import 'dart:math';
void main() async {
var duration = _runCPUBoundTask();
print('The duration for CPU bound task is $duration');
}
Future<Duration> _runCPUBoundTask() async {
var startTime = DateTime.now();
print('Starting ...');
void main() async {
var tweetId = 12345;
// Get tweet details by tweet Id
final networkData = await fetchTweetById(tweetId);
final jsonData = jsonDecode(networkData);
}
Future<Tweet> fetchTweetById(int tweetId) async {
final url = Uri.parse("www.twitter.com" + "/$tweetId");
final response = await http.get(url);
@hardikm9850
hardikm9850 / Singletons.md
Created December 11, 2022 08:06 — forked from Razeeman/Singletons.md
Thread safe singleton implementations in java and kotlin.

Java

Not thread safe.

class SimpleSingleton {
    private static SimpleSingleton sInstance;
  
    private SimpleSingleton() {}
 
@hardikm9850
hardikm9850 / grokking_to_leetcode.md
Created June 1, 2022 06:02 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

fun fetchUsers() {
val call = api.getUsersOverNetwork()
call.addCallback { result ->
when (result) {
is Success<User> -> {
// do something with the result
}
is Error -> {
// handle the error
}
@hardikm9850
hardikm9850 / Android internal system.md
Last active April 11, 2024 11:10
Collecting my learnings under a single node
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class FileCopy
{
public static void main (String[] args) throws java.lang.Exception