Skip to content

Instantly share code, notes, and snippets.

View gotev's full-sized avatar

Aleksandar 'Alex' Gotev gotev

View GitHub Profile
@gotev
gotev / .bash_profile
Created November 11, 2017 10:56
Colorful macOS terminal
# 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'
@gotev
gotev / remove-alpha-channel.sh
Created June 28, 2018 16:36
Remove alpha channel from PNGs in a directory
for file in $(ls *.png); do convert "$file" -alpha remove -alpha off "$file"; done
@gotev
gotev / guard-let-kotlin-swift.md
Last active July 12, 2018 13:56
Guard let comparison between Kotlin and Swift

Kotlin

val url = lastRadioUrl ?: run {
    doSomething()
    return
}
// use url which is not null

Swift

@gotev
gotev / Codable+Dictionary.swift
Last active October 9, 2018 10:45
Codable Dictionary
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 {
@gotev
gotev / SmartLoginHelper.kt
Last active October 16, 2018 15:02
Smart Login Helper
/*
* 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
@gotev
gotev / xcode-clean.md
Created January 13, 2019 16:02
Free Up Space taken by Xcode

Remove unavailable simulators:

xcrun simctl delete unavailable

Delete all the unneeded directories from:

cd ~/Library/Developer/Xcode/iOS\ DeviceSupport
@gotev
gotev / Optional.kt
Created May 27, 2019 12:43
Optional Subject
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
@gotev
gotev / ExtendedGsonFactory.kt
Created June 6, 2019 12:44
Extended Gson Factory
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
@gotev
gotev / ISO8601DateTimeAdapters.kt
Created June 6, 2019 12:46
ISO8601 Gson Type Adapters
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) {
@gotev
gotev / GitFlow-SourceTree.md
Last active June 16, 2019 12:11
Enable GitFlow in SourceTree

Clone both master and develop branches and switch on develop:

01

Right click on an empty space on the toolbar:

02

Drag GitFlow on your toolbar and click Done: