Skip to content

Instantly share code, notes, and snippets.

View gotev's full-sized avatar

Aleksandar 'Alex' Gotev gotev

View GitHub Profile
@gotev
gotev / resize-images
Created October 30, 2019 07:01
Batch resize images
sips -Z 640 *.jpg
@gotev
gotev / static-json-server
Last active September 27, 2019 10:10
Static JSON File Server in Python 3
#!/usr/bin/env python3
from http.server import HTTPServer, BaseHTTPRequestHandler
import os
base_path = os.path.dirname(__file__)
class StaticServer(BaseHTTPRequestHandler):
def execute_request(self):
filename = 'cached-responses' + self.path + '.json'
@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:

@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 / 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 / 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 / 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 / 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 / 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 / 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