Skip to content

Instantly share code, notes, and snippets.

@gabrielfeo
gabrielfeo / merge-gradle-profiler-results.py
Last active November 9, 2024 01:07
Compare separate gradle-profiler (last tested with v0.20.0) benchmark results by merging them into a single HTML
#!/usr/bin/env python3
from collections import namedtuple
import os
import shutil
import re
import json
import argparse
import sys
@gabrielfeo
gabrielfeo / download_gradle_profiler.sh
Created March 22, 2022 19:25
Download latest Gradle Profiler release
#!/usr/bin/env sh
# Downloads the latest prebuilt gradle-profiler release to the specified path
#
# Usage:
# download_gradle_profiler.sh <download-path>
set -eu
output_path="${1:?"Usage: download_gradle_profiler.sh <download-path>"}"
MAVEN_METADATA_URL="https://repo1.maven.org/maven2/org/gradle/profiler/gradle-profiler/maven-metadata.xml"
@gabrielfeo
gabrielfeo / add_mpl_header.py
Last active March 29, 2022 21:20
Add the Mozilla Public License (MPL) v2.0 header to every source file in a directory. Apache's license-eye does this already, but its formatting of comments isn't perfect, e.g. no newline after the header comment.
#!/usr/bin/env python3
from collections import namedtuple
from ctypes import Union
import os
import argparse
from fileinput import FileInput
import textwrap
parser = argparse.ArgumentParser()
@gabrielfeo
gabrielfeo / log-init-scripts.groovy
Last active April 11, 2022 10:46
Log all init script in a Gradle build. Paste in ~/.gradle/init.gradle to inspect IDE-injected init scripts.
import java.time.LocalDateTime
rootProject {
def time = LocalDateTime.now().toString()
def log = new File("${projectDir}/init-scripts-${time}.log")
log.write "${time}\n"
log << gradle.startParameter.currentDir.path
<< '\nInit scripts:\n---------\n\n'
gradle.startParameter.allInitScripts.each { file ->
@gabrielfeo
gabrielfeo / check-inconsistent-versions.init.gradle.kts
Created February 24, 2023 20:19
check-inconsistent-versions.init.gradle.kts
/**
* Checks for inconsistent versions in project dependencies.
* USAGE:
* ./gradlew help --init-script check-inconsistent-versions.init.gradle.kts
*
*
* For example, a project using Okio 3.0.0 in production, but 3.3.0 in tests:
*
* project ':': inconsistencies found
* com.squareup.okio:okio:
@gabrielfeo
gabrielfeo / ggdsl_datetime_errors_javatime.ipynb
Last active April 4, 2023 18:01
Kotlin ggdsl errors with datetime APIs. Don't use java.time. Don't use kotlinx.time LocalDate or LocalDateTime. Do use kotlinx.datetime.Instant.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gabrielfeo
gabrielfeo / craft-asset-fix.py
Created May 1, 2023 02:14
Craft attachment import fix
#!/usr/bin/env python3
import shutil
import argparse
from pathlib import Path
from urllib.parse import quote
def prefix_assets(dir_path):
for assets_dir in dir_path.rglob("*.assets"):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gabrielfeo
gabrielfeo / touch-id-for-sudo.sh
Last active June 2, 2023 18:29
Add touch ID as valid authentication for sudo on macOS
awk '!/^#/ && !p { print "auth sufficient pam_tid.so"; p=1 }1' /etc/pam.d/sudo \
| tee ./temp-pamd \
&& read \
&& sudo mv ./temp-pamd /etc/pam.d/sudo
&& rm ./temp-pamd