Kotlin
val url = lastRadioUrl ?: run {
doSomething()
return
}
// use url which is not null
Swift
# Colorful terminal | |
export PATH=/usr/local/bin:$PATH | |
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ " | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
alias ls='ls -GFh' |
for file in $(ls *.png); do convert "$file" -alpha remove -alpha off "$file"; done |
Kotlin
val url = lastRadioUrl ?: run {
doSomething()
return
}
// use url which is not null
Swift
public extension Encodable { | |
public var dictionary: [String: Any]? { | |
guard let data = try? JSONEncoder().encode(self) else { return nil } | |
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] } | |
} | |
} | |
public extension Decodable { | |
public extension Decodable { | |
public static func fromDictionary<T>(_ dict: [String: Any]) throws -> T where T: Decodable { |
/* | |
* Setup project first: https://developers.google.com/identity/smartlock-passwords/android/get-started | |
*/ | |
import android.app.Activity.RESULT_OK | |
import android.content.Intent | |
import androidx.appcompat.app.AppCompatActivity | |
import com.google.android.gms.auth.api.credentials.Credential | |
import com.google.android.gms.auth.api.credentials.CredentialRequest | |
import com.google.android.gms.auth.api.credentials.Credentials |
Remove unavailable simulators:
xcrun simctl delete unavailable
Delete all the unneeded directories from:
cd ~/Library/Developer/Xcode/iOS\ DeviceSupport
import io.reactivex.subjects.BehaviorSubject | |
class Optional<T>(private val value: T? = null) { | |
companion object { | |
fun <T> subject() = BehaviorSubject.createDefault(Optional<T>()) | |
} | |
fun isPresent() = value != null |
import com.google.gson.Gson | |
import com.google.gson.TypeAdapter | |
import com.google.gson.reflect.TypeToken | |
import okhttp3.RequestBody | |
import okhttp3.ResponseBody | |
import retrofit2.Converter | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
import java.lang.reflect.Type |
import com.google.gson.GsonBuilder | |
import com.google.gson.TypeAdapter | |
import com.google.gson.stream.JsonReader | |
import com.google.gson.stream.JsonWriter | |
import org.threeten.bp.* | |
private fun LocalDateTime.toISO8601UTCString() = withNano(0).atOffset(ZoneOffset.UTC).toString() | |
abstract class NullableTypeAdapter<T> : TypeAdapter<T>() { | |
override fun write(writer: JsonWriter?, value: T) { |