Skip to content

Instantly share code, notes, and snippets.

View carolinemusyoka's full-sized avatar
:octocat:
so?.let { it -> be (it) }

Carol carolinemusyoka

:octocat:
so?.let { it -> be (it) }
View GitHub Profile
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
# For a detailed guide to building and testing on Android, read the docs:
# https://circleci.com/docs/2.0/language-android/ for more details.
version: 2.1
# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
android: circleci/android@1.0.3
@carolinemusyoka
carolinemusyoka / convertDate.kt
Last active August 7, 2022 13:48
convert date
fun String.convertDate(context: Context): String? {
return try{
// "2021-11=10T16:24:21.579537Z"
val currentLocale = ConfigurationCompat.getLocales(context.resources.configuration)[0]
val inputFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault())
inputFormat.timeZone = TimeZone.getTimeZone("GMT")
val passedDate: Date = inputFormat.parse(this) as Date
// Form example Mon, Nov *, 2021, 12:10 pm
@carolinemusyoka
carolinemusyoka / UploadImageWithMultiPart.kt
Created April 22, 2022 17:23
Uploading an image using multipart in Kotlin
// 1. The Interface
// --> Two ways to do it,
```
@Multipart
@POST("the_endpoint")
suspend fun postImage(
@Part profile_photo: MultipartBody.Part,
@Part ("profile_photo") requestBody: RequestBody
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val parsedDate = LocalDateTime.parse(item.created_at, DateTimeFormatter.ISO_DATE_TIME)
val formattedDate = parsedDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy | HH:mm"))
textCreatedTime.text = formattedDate
} else {
val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
val formatter = SimpleDateFormat("dd.MM.yyyy | HH:mm")
val formattedDate = formatter.format(parser.parse(item.created_at)!!)
textCreatedTime.text = formattedDate
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="45"
android:startColor="@color/green"
android:centerColor="@color/white"
android:endColor="@color/orange" />
</shape>
val regionId = MutableLiveData<Int>()
fun setRegionId(id: Int){
regionId.value = id
}
val builder = LatLngBounds.Builder()
val locBounds = LatLngBounds(LatLng(53.394655, 10.09989), LatLng(53.694865, 9.75758))
builder.include(locBounds.southwest)
builder.include(locBounds.northeast)
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 100))
class Solution {
fun reverse(x: Int): Int {
var res = 0
var n = x
while (n != 0) {
if (Math.abs(res) > Int.MAX_VALUE/10) return 0
res = res*10 + n % 10
n /= 10
}
class Solution {
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
// Check if num1 is smaller than num2
// If not, then we will swap num1 with num2
if (nums1.size > nums2.size) {
return findMedianSortedArrays(nums2, nums1)
}
// Lengths of two arrays
val m = nums1.size
val n = nums2.size
//Finding the length of the longest substring without repeating characters
//Solution
// Iterate through an array, evaluating if new substring should be the max substring
//Time complexity is O(n)..since we're iterating through an array once
//Space complexity is constant
class Solution {
fun lengthOfLongestSubstring(str: String): Int{
val map: HashMap<Char, Int> = hashMapOf()
var max = 0
// last repeat of any character