Skip to content

Instantly share code, notes, and snippets.

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
nums.sort()
start = 0
end = len(nums) - 1
while(nums[start] + nums[end] != target):
if nums[start] + nums[end] > target:
end -= 1
else:
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(0, len(nums)-1):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
return (i, j)
return (-1, -1)
@faanghutProfile
faanghutProfile / LifeCycleCallbacksApplication.kt
Created August 2, 2022 18:25
LifeCycleCallbacksApplication.kt with observer added.
class LifeCycleCallbacksApplication: Application() {
override fun onCreate() {
// Add this
ProcessLifecycleOwner.get().lifecycle.addObserver( AppLifeCycleListener())
super.onCreate()
}
}
@faanghutProfile
faanghutProfile / AppLifeCycleListener.kt
Created August 2, 2022 18:23
AppLifeCycleListener
class AppLifeCycleListener: DefaultLifecycleObserver {
override fun onCreate(owner: LifecycleOwner) {
Log.i("AppLifeCycleListener", "App Came to Foreground")
// Add custom logic for app open here.
super.onCreate(owner)
}
override fun onStop(owner: LifecycleOwner) {
Log.i("AppLifeCycleListener", "App Went to Background")
@faanghutProfile
faanghutProfile / AndroidManifest.xml
Created August 2, 2022 18:04
AndroidManifest.xml
<application
...
android:name=".LifeCycleCallbacksApplication"
...
</application>
class LifeCycleCallbacksApplication: Application() {
override fun onCreate() {
super.onCreate()
}
}
@faanghutProfile
faanghutProfile / build.gradle
Created August 2, 2022 17:58
App's build.gradle for ProcessLifecycleOwner
implementation "androidx.lifecycle:lifecycle-process:2.5.1"
implementation "androidx.lifecycle:lifecycle-common:2.5.1"
@faanghutProfile
faanghutProfile / AndroidManifest.xml
Last active July 28, 2022 18:09
Android Manifest when you want to add broadcast receiver.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.faanghut.detectsimchange">
<!-- Add this permission in your manifiest -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
@faanghutProfile
faanghutProfile / SimChangeReceiver.kt
Created July 28, 2022 17:59
Broadcast Receiver for SIM Change
class SimChangeReceivers: BroadcastReceiver() {
private val TAG = "SimChangeReceivers"
// This is where you'll be receiving the SIM_STATE_CHANGE intent.
override fun onReceive(p0: Context?, p1: Intent?) {
var state = ""
if (p1 != null) {
state = p1.extras?.getString("ss").toString()
}
Log.i(TAG, "SIM State Change Detected $state")
public class VideoFragment extends Fragment {
private StyledPlayerView playerView;
private ExoPlayer player;
private String mediaURI;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mediaURI = "https://download.samplelib.com/mp4/sample-30s.mp4";
}