Skip to content

Instantly share code, notes, and snippets.

View jesvs's full-sized avatar

Jesús Sánchez jesvs

View GitHub Profile
import kotlin.math.ln
import kotlin.math.pow
fun convertToSuffix(x: Double): String {
if (x < 1_000) return "$x"
val exp = (ln(x) / ln(1_000.0)).toInt()
return String.format("%.1f%c", x / 1_000.0.pow(exp), "kmgtpe".toCharArray()[exp - 1])
}
@jesvs
jesvs / getBitmapFromDrawable.kt
Created October 23, 2019 23:57
Get a Bitmap from a Drawable resource id
fun getBitmapFromDrawable(resId: Int): Bitmap? {
val drawable = AppCompatResources.getDrawable(requireContext(), resId) ?: return null
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
@jesvs
jesvs / mpcsimilar.sh
Last active January 2, 2025 03:54
Shell script that uses last.fm API to add similar artists to MPD.
#!/bin/bash
# depends on jq to parse json
# https://stedolan.github.io/jq/
#
# This script will query the last.fm API for
# similar artists based on the currently playing track.
# It will crop the current playlist, and shuffle the API results.
#
# You can configure 3 parameters:
diff -Naur wine-5.9/dlls/ntdll/esync.c wine-fsync/dlls/ntdll/esync.c
--- wine-5.9/dlls/ntdll/esync.c 2020-08-10 01:37:43.417493835 -0600
+++ wine-fsync/dlls/ntdll/esync.c 2020-08-10 01:39:33.252766633 -0600
@@ -48,6 +48,7 @@
#include "ntdll_misc.h"
#include "esync.h"
+#include "fsync.h"
WINE_DEFAULT_DEBUG_CHANNEL(esync);
@jesvs
jesvs / legendary-0.20.1.ebuild
Created October 2, 2020 13:33
Legendary Epic launcher, Gentoo ebuild.
# Copyright 2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
PYTHON_COMPAT=( python3_8 )
inherit distutils-r1
MY_PN="legendary-gl"
MY_P="${MY_PN}-${PV}"