Skip to content

Instantly share code, notes, and snippets.

View andrewsafwatsamuel's full-sized avatar

andrewsafwatsamuel

View GitHub Profile
fun invoicePath(
config: ProcessConfiguration,
invoiceMap: InvoiceConfig = invoiceConfiguration,
shippingMap: ShippingConfig = shippingConfiguration,
freightMap: FreightConfig = freightCostConfiguration
) = invoiceMap[config.invoiceChoice]!!
.compose(shippingMap[config.shippingChoice]!!)
.compose(freightMap[config.freightChoice]!!)
fun availabilityPath(
@andrewsafwatsamuel
andrewsafwatsamuel / ConnectivityListener.kt
Last active March 8, 2022 08:40
Android connectivity listener
import android.annotation.TargetApi
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.*
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.lifecycle.LiveData
@andrewsafwatsamuel
andrewsafwatsamuel / HigherOrderFunctionsExample
Created April 10, 2021 19:31
kotlin implementation of Mohamed Hammad's functional programming 4th video (higher order functions example)
private val ordersForProcessing = listOf<Order>(
Order(10,1100.0,20.0,20,Type.FOOD),
Order(12,100.0,5.0,8,Type.RAW_MATERIAL)
)
val getDiscountRules = listOf(
Pair(::isQuantityQualified, ::calculateQuantityDiscount),
Pair(::isPriceQualified, ::calculatePriceDiscount),
Pair(::isWeightQualified, ::calculateWeightDiscount),
Pair(::isTypeFood, ::calculateFoodDiscount),
fun hourglassSum(arr: Array<Array<Int>>): Int {
val values = arrayListOf<Int>()
for (i in 0 until (arr.size - 2)) {
for (j in 0 until (arr[i].size - 2)) {
val current = arr[i]
val currentP1 = arr[i + 1]
val currentP2 = arr[i + 2]
val sum = current[j] + current[j + 1] + current[j + 2] + currentP1[j + 1] + currentP2[j] + currentP2[j + 1] + currentP2[j + 2]
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
class HomeFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.fragment_home, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
class MainActivity : AppCompatActivity() {
val fadeAnimator by lazy {
ObjectAnimator.ofFloat(targetImage,"alpha",1.0f,0.0f)
.apply {duration=1500}
.apply { repeatCount=1 }
.apply { repeatMode=ObjectAnimator.REVERSE }
}
override fun onCreate(savedInstanceState: Bundle?) {