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
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setView(R.layout.round_alert);
AlertDialog dialog = builder.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
public class MockProfileTest extends ActivityInstrumentationTestCase2<FragmentContainer> {
final MockWebServer mMockWebServer = new MockWebServer();
private FragmentContainer fragmentContainer;
final int PORT = 9998;
Instrumentation instrumentation;
int id = 111;
String name = "name";
class Ideone {
static String formatPhone(String s) {
s = s.replaceAll(" ", "").replaceAll("-", "");
char[] array = s.toCharArray();
StringBuilder sb = new StringBuilder();
boolean shouldThree = array.length % 3 == 0;
for (int i = 0, j = 0; i < array.length; i++) {
if (i == array.length - 2 && !shouldThree) {
if (sb.charAt(sb.length() - 1) != '-') {
/* 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
@hardikm9850
hardikm9850 / Android internal system.md
Last active April 11, 2024 11:10
Collecting my learnings under a single node
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 / 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

@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() {}
 
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);
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 ...');