Skip to content

Instantly share code, notes, and snippets.

View aballano's full-sized avatar
🏠
Working from home

Alberto Ballano aballano

🏠
Working from home
View GitHub Profile
@sergiocasero
sergiocasero / crontab
Last active September 29, 2022 11:15
A simple, lightweight but powerfull telegram bot that sends your public IP through telegram in case it changes, really useful if you have dynamic IPs but also have a private cloud
# Every minute, perfect for IP_INFO free tier
* * * * * /usr/bin/python3 /PATH_TO_THE_SCRIPT/ipbot.py
@alexjlockwood
alexjlockwood / CircleSquare.kt
Last active September 26, 2020 17:52
A circle square animation implemented using Jetpack Compose. Inspired by @beesandbombs (twitter.com/beesandbombs).
package com.alexjlockwood.circlesquare
import androidx.compose.animation.animatedFloat
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.repeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.runtime.Composable
@raulraja
raulraja / IO.kt
Created April 17, 2020 20:06
Kinds without uncheched casts
/** Bifunctor IO */
class IO<out E, out A> :
`*`<IO<*, *>>,
`*-*`<IO<*, *>, A>,
`*-*-*`<IO<*, *>, E, A> {
fun <B> fmap(f: (A) -> B): IO<Nothing, B> = TODO()
fun <B> flatMap(f: (A) -> `*-*`<IO<*, *>, B>): IO<Nothing, B> = TODO()
fun <C, D> bimap(fl: (E) -> C, fr: (A) -> D): IO<C, D> = TODO()
companion object {
@nomisRev
nomisRev / Example.kt
Created November 28, 2019 09:11
Stacksafe Mono Reactor
import reactor.core.publisher.Mono
import java.util.concurrent.Executor
fun noTrampolining(): Mono<Int> {
var initial = Mono.just(0)
(0..5000).forEach { i ->
initial = initial.map { i }
}
return initial
@rallat
rallat / gist:131491722a4b677e8a24353476850812
Created June 24, 2019 08:08
This script compares the similarity between
#!/bin/bash
# This command expects two params.
# First param is the directory of the png.
# Second param is the directory of the webp.
# It will traverse the first directory and compare that file with the same webp in the second directory
# This script requires to download similar script from http://www.fmwconcepts.com/imagemagick/similar/index.php
# and leave it the same directory as this script. This script will be the one leveraging imagemagick
pngDir=$1
webpDir=$2
find $1 -name "*.png" | cut -sd / -f 11- | sed 's/\.png$//1'|while read fname; do
@pedrovgs
pedrovgs / android_start_bitrise_emulator.sh
Last active August 15, 2021 10:04
A ready to work emulator for Bitrise.io
#!/usr/bin/env bash
set -e
build_dir=$(pwd)
echo "Curren build dir:"
echo $build_dir
cd $ANDROID_HOME/emulator
echo "Creating sdcard image"
@minas1
minas1 / gist:f920c037e511f71a1d06c9261f3307be
Created November 9, 2018 16:26
Exclude your own Activity from Activity.startActivity(Intent) chooser
/**
* Attempts to start an activity to handle the given intent, excluding activities of this app.
* <ul>
* <li>If the user has set a default activity (which does not belong in this app's package), it is opened without prompt.</li>
* <li>Otherwise, an intent chooser is displayed that excludes activities of this app's package.</li>
* </ul>
*
* @param context context
* @param intent intent to open
* @param chooserTitle the title that will be displayed for the intent chooser in case one needs to be displayed.
@Cotel
Cotel / RefinedTypes.kt
Last active November 25, 2018 10:35
How to make refined types in Kotlin with Arrow (https://arrow-kt.io/)
import arrow.core.Option
class NonZeroInt private constructor(val value: Int) {
companion object {
operator fun invoke(x: Int): Option<NonZeroInt> =
if (x == 0) Option.empty() else Option.just(NonZeroInt(x))
fun get(x: NonZeroInt): Int = x.value
}
}
when (info) {
null -> {
return unauthorized()
}
else -> {
val validInfo = validator.validateInfo(info)
when (validInfo) {
is Either.Right -> {
if (!validInfo.b.authorised) {
@vlio20
vlio20 / StatusCode.kt
Last active June 19, 2023 23:56
Kotlin Http Status Codes enum
package oogaday.commons.enums
enum class StatusCode(val code: Int) {
Continue(100),
SwitchingProtocols(101),
Processing(102),
OK(200),
Created(201),
Accepted(202),