Skip to content

Instantly share code, notes, and snippets.

View sergiocasero's full-sized avatar
😄

Sergio Casero Hernández sergiocasero

😄
View GitHub Profile
@sergiocasero
sergiocasero / MaybeSave.kt
Last active October 24, 2018 15:42
Maybe extension function to save data and return the same value (wihout blocking the stream)
fun <T> Maybe<T>.save(saveFunction: (T) -> Unit): Maybe<T> {
return MaybeSave(this, saveFunction)
}
private class MaybeSave<T>(val source: MaybeSource<T>, val saveFunction: (T) -> Unit) : Maybe<T>() {
override fun subscribeActual(observer: MaybeObserver<in T>) {
source.subscribe(MaybeSaveObserver<T>(observer, saveFunction))
}
import android.os.Build;
import android.os.HandlerThread;
import android.os.Process;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Completable;
import io.reactivex.Flowable;
#!/bin/bash
grep -rnw '.' -e 'android.support'
@sergiocasero
sergiocasero / functions.js
Created January 12, 2019 19:25
Switch Google Assistant
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.database();
const ref = db.ref("/switch");
@sergiocasero
sergiocasero / DaoGenerator.kt
Created April 25, 2019 09:39
DaoGenerator code template for IntelliJ/AS
package ${PACKAGE_NAME}
#parse("File Header.java")
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Update
import androidx.room.Query
@Dao
@sergiocasero
sergiocasero / Explanation.md
Last active December 13, 2023 10:16
Firebase wrapper for iOS and Android with kotlin multiplatform

Hello guys, I've raised into that problem for a days, but i think I've found one solution, maybe this isn't the better way to do that, but... I will share it. (This is inspired in the Firebase multiplatform repo -> https://github.com/RubyLichtenstein/Kotlin-Multiplatform-Firebase, I'm just summarizing that)

If you want to call some code from a DataSource or Repository from your common code, and the libraries you're using use callbacks, you need to wrap them and there are some problems:

Let me explain it with an example:

expect class RemoteDataSource() {
@sergiocasero
sergiocasero / main.dart
Created July 31, 2020 11:36
Custom Sliver with Toolbar Ellipsis behind
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@sergiocasero
sergiocasero / ssl_pinning_android_ktor.kt
Last active September 22, 2020 16:09
Simple snippet that demonstrates how to make https request with SSL pinning by using ktor on Android
class AndroidRemote(private val context: Context) : Remote {
companion object {
private const val SSL_PROTOCOL = "TLSv1.2"
private const val KEYSTORE_PROTOCOL = "BKS"
private const val KEY_MANAGER_ALG = "X509"
private const val KEYSTORE_PATH = "YOUR_ASSET_NAME.bks"
private val KEYSTORE_PASSWORD = "YOUR_PASS".toCharArray() // Find better place to store this please hahaha
private const val API_ENDPOINT = "API_ENDPOINT"
package com.sergiocasero.backend.push
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.sergiocasero.jvm.network.createService
import com.sergiocasero.model.PushTopic
import com.sergiocasero.properties.Property
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import retrofit2.http.Body
@sergiocasero
sergiocasero / pico_micropython.sh
Created February 1, 2021 20:26
This is a simple and small script to automatize the raspberry pi pico micropython SDK compilation
mkdir pico_micropython_install
cd pico_micropython_install
git clone -b pico https://github.com/raspberrypi/micropython.git
cd micropython
git submodule update --init -- lib/pico-sdk
cd lib/pico-sdk
git submodule update --init
cd ../..
make -C mpy-cross
cd ports/rp2