Skip to content

Instantly share code, notes, and snippets.

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

Somasundaram M msomu

🏠
Working from home
View GitHub Profile
@msomu
msomu / DateVisualTransformation.kt
Created June 30, 2021 17:26
UseVisualTransformation to Create Date TextField in Jetpack Compose
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
class DateVisualTransformation : VisualTransformation {
override fun filter(text: AnnotatedString): TransformedText {
// Make the string DD-MM-YYYY
val trimmed = if (text.text.length >= 8) text.text.substring(0..7) else text.text
var output = ""
@msomu
msomu / apps_install.sh
Last active June 18, 2021 02:51 — forked from brunofbrito/apps_install.sh
Install my macOS apps with homebrew, cask and mas-cli
#!/bin/sh
echo Install all AppStore Apps at first!
read -p "Press any key to continue... " -n1 -s
echo '\n'
echo Installing Homebrew...
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo Installing Brew favorites...
brew tap homebrew/cask-fonts
@msomu
msomu / Hilt.md
Created June 25, 2020 16:05
Learn all about Hilt here

Hilt

  • Jetpack’s recommended library for Dependency Injection.
  • Hilt is a new Android library which simplifies dependency injection in your application.
  • Hilt lets you focus on just the important parts of defining and injecting without worrying about managing all of the DI setup and wiring.

Why DI?

By following the principles of DI, you lay the groundwork for good app architecture.

  • Reusability of code
  • Ease of refactoring
  • Ease of testing
@msomu
msomu / KotlinQuestions.md
Last active May 19, 2020 15:14
Kotlin Job Interview Questions sample 3 Questions

Question 1 (Easy)

How do you make Kotlin variables nullable by default?
A) Use it same like Java
B) Use !! to make variables nullable
C) Use $ to make variables nullable
D) Use ? to make variables nullable

Answer :

D) Use ? to make variables nullable

Explanation :

@msomu
msomu / MainActivity.java
Created April 4, 2018 03:03
Add Image to Firebase Storage
public class MainActivity extends AppCompatActivity {
FirebaseStorage storage = FirebaseStorage.getInstance();
// Fetch the Image file uri and replace it with 'new File("path/to/images/rivers.jpg")'
Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg"));
StorageReference riversRef = storageRef.child("images/"+file.getLastPathSegment());
uploadTask = riversRef.putFile(file);
// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
@msomu
msomu / MainActivity.java
Last active April 5, 2018 15:08
Choose Image from Gallery
public int REQUEST_IMAGE_GET = 104
class MainActivity extends AppCompatActivity {
private void selectImage() {
Intent intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "image/*"
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET)
}
}
@override void onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
@msomu
msomu / Movie.java
Created June 4, 2017 14:01
Introduction to Kotlin
public class Movies {
private String id;
private String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
@msomu
msomu / us_states_cities.json
Created March 3, 2017 06:33
US states cities in JSON form
{
"Alabama": ["Autauga", "Baldwin", "Barbour", "Bibb", "Blount", "Bullock", "Butler", "Calhoun", "Chambers", "Cherokee", "Chilton", "Choctaw", "Clarke", "Clay", "Cleburne", "Coffee", "Colbert", "Conecuh", "Coosa", "Covington", "Crenshaw", "Cullman", "Dale", "Dallas", "DeKalb", "Elmore", "Escambia", "Etowah", "Fayette", "Franklin", "Geneva", "Greene", "Hale", "Henry", "Houston", "Jackson", "Jefferson", "Lamar", "Lauderdale", "Lawrence", "Lee", "Limestone", "Lowndes", "Macon", "Madison", "Marengo", "Marion", "Marshall", "Mobile", "Monroe", "Montgomery", "Morgan", "Perry", "Pickens", "Pike", "Randolph", "Russell", "Shelby", "St. Clair", "Sumter", "Talladega", "Tallapoosa", "Tuscaloosa", "Walker", "Washington", "Wilcox", "Winston"],
"Alaska": ["Anchorage", "Bethel", "Bristol Bay", "Dillingham", "Fairbanks North Star", "Haines", "Juneau", "Kenai Peninsula", "Ketchikan Gateway", "Kodiak Island", "Matanuska-Susitna", "Nome", "North Slope", "Prince of Wales-Outer Ketchikan", "Sitka", "Skagway-Hoonah-Angoon", "Sout
@msomu
msomu / path.sh
Created January 16, 2017 04:02
To set environmental variable on mac for android
nano ~/.bash_profile
export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
source ~/.bash_profile
echo $ANDROID_HOME
@msomu
msomu / Fragment.java
Created December 29, 2016 16:38
A default Fragment
package com.msomu.binaryfreak.ui;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;