Skip to content

Instantly share code, notes, and snippets.

@saantiaguilera
saantiaguilera / Result.kt
Created January 14, 2021 17:07
Result sealed class for kotlin error handling, allowing us to write safe code either in a functional or imperative format, without the use of exceptions. Since kotlin from 1.3 onwards changed their Result into an inline class, we can no longer use it for return values (which eliminates the bad smell of exceptions as errors, like most modern lang…
package com.saantiaguilera
import com.saantiaguilera.Result.Failure
import com.saantiaguilera.Result.Success
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
/**
* A discriminated union that encapsulates successful outcome with a value of type [S]
{
{
"link": "https://kahoot.it/challenge/07478158?challenge-id=36dfa64c-d15a-4990-948c-0d8600cab278_1594751002787",
"leaderboard": "1. X - 100 puntos\n2. Y - 25 puntos\n3. Z - 5 puntos"
},
{
"link": "https://forms.gle/pS4w5MJ6t3zThH3t5",
"leaderboard": "1. X - 100 puntos\n2. Y - 25 puntos\n3. Z - 5 puntos"
}
}
@saantiaguilera
saantiaguilera / IntegrationTests.kt
Created November 5, 2019 03:41
Tennis BrownBag
package com.mercadolibre.dojo
import org.junit.Assert
import org.junit.Before
import org.junit.Test
class IntegrationTests {
lateinit var player1: Player
lateinit var player2: Player
@saantiaguilera
saantiaguilera / .zshrc
Created October 31, 2019 00:03
Volume manager for abstracting code sources
# Add this in your .zshrc or .bash_profile or wherever you want
mount() {
# Note that I save all my sparse images in ~/Projects/
hdiutil attach ~/Projects/$1.dmg.sparseimage -mountpoint /Volumes/$1
}
unmount() {
hdiutil detach /Volumes/$1
}
// Root header to have dependencies
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradleBuildToolsVersion"
classpath gradleApi()
@saantiaguilera
saantiaguilera / service_call_test.py
Last active February 15, 2018 14:40 — forked from ktnr74/service_call_test.py
*update_transaction_codes.py* parses Android services source code to find out transaction codes and saves them in YAML format for later use. *transaction_codes.yaml* is an example of the resulting file. *service_call_test.py* shows how it can be used
#!/usr/bin/python
import os
import sys
import time
import yaml
import subprocess
import re
import struct
@saantiaguilera
saantiaguilera / .adb-aliases
Created October 20, 2016 15:04
Easy adb aliases for an easier life
func_adbfilter() {
adb logcat | ggrep `adb shell ps | ggrep $1 | cut -c10-15`
}
alias adbfilter=func_adbfilter
func_adbphonedata() {
adb shell cat /proc/cpuinfo
}
@saantiaguilera
saantiaguilera / commit
Created October 1, 2016 03:12
Commit with gpg without having to always remember -S
#!/bin/bash
EXISTS="`git config --global --list | sed -n "/.*signingkey.*/p"`"
if [ -z $EXISTS ]
then
echo "Woops ! It seems you dont have your git signed. Looking for an existing GPG key..."
SIGNING_KEY="`gpg --list-keys | sed -n '3p' | sed "s/.*\///" | sed "s/ .*//"`"
@saantiaguilera
saantiaguilera / Frescaso.md
Created September 9, 2016 22:07
Fresco picasso mode

Juanma tutorial for using Fresco as "Picasso"

La diferencia mas grande entre picasso y fresco es que (por si te preguntan):

Android <4.0 usa como vm Dalvik. De 4.0 a 4.4 esta Dalvik y ART (Beta). >5.0 ART.

Las mayor diferencia entre Dalvik y ART, es que dalvik tiene un solo heap uniforme y que, cada vez que corra el garbage collector, haltea TODOS los procesos para limpiar la memoria. Entonces en los celulares de dalvik, si empezas a usar mucha memoria y tiene que recolectarla, se te "freezea" el celular por unos ms.

Esto se nota demasiado en las listviews/gridviews/recyclerviews, ya que uno levanta muchisima memoria y se recolecta al toque, pero en dalvik esto haltea ;).