Skip to content

Instantly share code, notes, and snippets.

View niltsiar's full-sized avatar

Borja Quevedo niltsiar

View GitHub Profile
@raulraja
raulraja / Services.kt
Last active December 28, 2021 21:37
Services as composable suspended functions
package arrow.meta.continuations
import arrow.core.Either
import arrow.core.computations.either
import arrow.core.flatMap
/**
* Models errors as values
*/
sealed interface Failure
@n0m0r3pa1n
n0m0r3pa1n / BottomSheetExtensions.kt
Last active October 2, 2023 01:53
Bottom sheet dialog with expanding and fullscreen display
fun Fragment.showBottomSheetDialog(
@LayoutRes layout: Int,
@IdRes textViewToSet: Int? = null,
textToSet: String? = null,
fullScreen: Boolean = true,
expand: Boolean = true
) {
val dialog = BottomSheetDialog(context!!)
dialog.setOnShowListener {
val bottomSheet: FrameLayout = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet) ?: return@setOnShowListener
@progrium
progrium / README.md
Last active July 3, 2024 07:19
Setting up M1 Macs for x86 development with Homebrew

Key Points

  • In general, binaries built just for x86 architecture will automatically be run in x86 mode
  • You can force apps in Rosetta 2 / x86 mode by right-clicking app, click Get Info, check "Open using Rosetta"
  • You can force command-line apps by prefixing with arch -x86_64, for example arch -x86_64 go
  • Running a shell in this mode means you don't have to prefix commands: arch -x86_64 zsh then go or whatever
  • Don't just immediately install Homebrew as usual. It should most likely be installed in x86 mode.

Homebrew

Not all toolchains and libraries properly support M1 arm64 chips just yet. Although

@objcode
objcode / ConcurrencyHelpers.kt
Last active July 7, 2024 09:57
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ZacSweers
ZacSweers / GuardTest.kt
Last active September 14, 2018 23:05
Demo of how the Nothing type in Kotlin can allow a Swift-style guard function
import com.google.common.truth.Truth.assertThat
import org.junit.Test
inline fun <T> guard(receiver: T?, block: () -> Nothing): T {
if (receiver == null) {
block()
}
return receiver
}
@nickbutcher
nickbutcher / rainbow.xml
Last active January 25, 2023 17:09
Demonstrating using VectorDrawable gradients to create a rainbow effect. See https://twitter.com/crafty/status/1011922414983352320
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing permissions and limitations under
the License.
@tomaszpolanski
tomaszpolanski / logging.kt
Last active February 7, 2021 15:24
RxLogging
@file:Suppress("NOTHING_TO_INLINE")
import android.util.Log
import io.reactivex.*
inline fun <reified T> printEvent(tag: String, success: T?, error: Throwable?) =
when {
success == null && error == null -> Log.d(tag, "Complete") /* Only with Maybe */
success != null -> Log.d(tag, "Success $success")
error != null -> Log.d(tag, "Error $error")
@parmentf
parmentf / GitCommitEmoji.md
Last active July 24, 2024 23:03
Git Commit message Emoji
@sukharevd
sukharevd / wildfly-install.sh
Last active July 2, 2024 07:55
Script to install JBoss Wildfly 10.x as service in Linux
#!/bin/bash
#title :wildfly-install.sh
#description :The script to install Wildfly 10.x
#more :http://sukharevd.net/wildfly-8-installation.html
#author :Dmitriy Sukharev
#date :2016-06-18T02:45-0700
#usage :/bin/bash wildfly-install.sh
#tested-version1 :10.0.0.CR3
#tested-distros1 :Ubuntu 15.10; Debian 7,8; CentOS 7; Fedora 22
#tested-version2 :10.0.0.Final
@devunwired
devunwired / background_dialog.xml
Created November 14, 2012 20:09
XML Shape Drawable for Dialog Backgrounds. Applies a fixed outer margin to keep background from fully stretching to screen edge, and allows for additional internal padding to apply to the dialog content.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Apply the margin value on the "item" element -->
<!-- This example creates a 15dp visible margin around the dialog -->
<item
android:top="15dp"
android:bottom="15dp"
android:left="15dp"
android:right="15dp">
<shape