Skip to content

Instantly share code, notes, and snippets.

View sryze's full-sized avatar

Sergey Zolotarev sryze

View GitHub Profile
@sryze
sryze / convert-app-icon-ios.sh
Last active May 4, 2024 22:42
Convert app icon from a single PNG to different sizes for iOS
#!/bin/bash
# Install ImageMagick before using this script: brew install imagemagick (for the convert command)
# This script works in Bash, but not in ZSH.
sizes="
40x40
60x60
58x58
87x87
@sryze
sryze / bashdo.bat
Last active November 11, 2023 09:33
Quickly run a shell command inside Git Bash from command prompt / PowerShell on Windows (without manually opening a new Git Bash instance)
@echo off
REM Usage: bashdo echo 'hello, world!'
REM Caution: it doesn't work well if there are double quotes in your Bash commands (need to figure out how to escape them).
"%ProgramFiles%\Git\bin\bash.exe" -l -c "%*"
@sryze
sryze / build-deps.md
Last active October 26, 2023 04:43
Installing build dependencies of a Debian package that can be easily removed later

This approach allows you to install a *-build-deps package that can be easily apt autoremoved later when you don't need the dependencies anymore.

  1. Install packaging tools: sudo apt install devscripts equivs
  2. Generate a build-deps package (in this case we use nextcloud-desktop as an example):
    mk-build-deps nextcloud-desktop
    
  3. Install it:

sudo apt install ./nextcloud-desktop-build-deps_x.y.z_amd64.deb

@sryze
sryze / prepare_appicon_images.sh
Last active December 24, 2022 18:28
Script for generating iOS app icons of all sizes from a single SVG image via Inkscape
#!/bin/sh
INKSCAPE=/Applications/Inkscape.app/Contents/MacOS/inkscape
mkdir -p converted
for size in $(echo 512 40 60 58 87 80 120 180 20 40 29 58 76 152 167 1024); do
$INKSCAPE --export-type png --export-filename converted/AppIcon_${size}x${size}.png -w $size AppIconUpdated.svg
done
@sryze
sryze / monitor-check.sh
Last active February 16, 2023 14:43
A shell script for LibreELEC to automatically stop Kodi playback when the HDMI monitor is disconnected / turned off
#!/bin/sh
# Usage:
# 1. Save the script to /storage/monitor-check.sh
# 2. Execute: chmod +x /storage/monitor-check.sh
# 3. Execute: crontab -e and put in this line (runs this script once a minute):
# * * * * * /storage/monitor-check.sh
# 4. Execute: systemctl restart cron
# 5. Make sure that the cron job is working by checking the journal (journalctl -xe -u cron)
@sryze
sryze / set-java-version.sh
Created March 19, 2022 16:50
Script for switching between different versions of Java on Windows (needs Git Bash or similar shell)
#!/bin/sh
java_version=$1
java_home=
IFS=$'\n'
for d in $(find "/c/Program Files/Java" -name "jdk*$java_version*" -type d); do
java_home="$d"
done
@sryze
sryze / check-repos.sh
Created November 14, 2020 07:04
Find Git repos and check if they are broken
#!/bin/sh
find $1 -name .git -type d -exec sh -c 'echo $(realpath {}/..); cd {}/..; git status > /dev/null' \;
@sryze
sryze / webivew_crash_fix.kt
Last active July 25, 2020 20:51
Fix WebView crash when running on Android emulator: A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid XXX (RenderThread), pid YYY
val isHardwareAccelerated =
window.attributes.flags and WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED != 0
if (isHardwareAccelerated) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
} else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}
function mergeArraysKeepOrder(a1, a2) {
var a = [];
var i = 0, j = 0;
while (true) {
for (; i < a1.length; i++) {
if (a2.indexOf(a1[i], j) != -1) {
i++;
break;
}
a.push(a1[i]);
@sryze
sryze / capitalize.js
Last active January 7, 2020 13:04
Capitalize every word in a string
export function capitalizeWords(text) {
let result = '';
let wordCharIndex = 0;
for (let i = 0; i < text.length; i++) {
let c = text.charAt(i);
if (/\s/.test(c)) {
wordCharIndex = 0;
} else {
if (wordCharIndex == 0) {
c = c.toUpperCase();