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 / 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 / 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 / Activity.java
Created November 12, 2014 15:38
Read Call Logs in Android
private void getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Log :");
while (managedCursor.moveToNext()) {
String phNumber = managedCursor.getString(number);
@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
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 / 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 / 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 / justickets.sh
Last active March 22, 2017 17:45
pull db from mobile
adb shell "run-as in.justickets.android.staging chmod 666 /data/data/in.justickets.android.staging/files/justickets.realm"
adb -d shell 'run-as in.justickets.android.staging cp /data/data/in.justickets.android.staging/files/justickets.realm /sdcard/justickets.realm'
adb pull /sdcard/justickets.realm