Skip to content

Instantly share code, notes, and snippets.

View jfsanchez91's full-sized avatar

Jorge F. Sánchez jfsanchez91

View GitHub Profile
@Morreski
Morreski / timed_cache.py
Last active July 3, 2024 16:29
Python lru_cache with timeout
from datetime import datetime, timedelta
import functools
def timed_cache(**timedelta_kwargs):
def _wrapper(f):
update_delta = timedelta(**timedelta_kwargs)
next_update = datetime.utcnow() + update_delta
# Apply @lru_cache to f with no cache size limit
@jfsanchez91
jfsanchez91 / git_pack.sh
Created September 7, 2017 14:06
Bash function to zip a git project using git clone
#Author: Jorge Fernández Sánchez <jfsanchez.email@gmail.com>
#This function clone a git project and makes (in the working directory) a zip file with the project content.
#project packing from git
function git_pack {
_PWD=$PWD
GIT_PATH=$1
GIT_PROJECT=`/usr/bin/basename $GIT_PATH`
OUTPUT_ZIP="$_PWD/$GIT_PROJECT.zip"
TMP_PATH="/var/tmp/"
@jfsanchez91
jfsanchez91 / FlowExt.kt
Last active June 12, 2023 15:01
Kotlin coroutines ext Flow operators
package util.ext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.count
import kotlinx.coroutines.flow.first
suspend fun <T> Flow<T>.all(predicate: suspend (T) -> Boolean): Boolean {
return this.count { !predicate(it) } == 0
}