Skip to content

Instantly share code, notes, and snippets.

View jfsanchez91's full-sized avatar

Jorge F. Sánchez jfsanchez91

View GitHub Profile
@jfsanchez91
jfsanchez91 / idea
Created August 10, 2023 10:38
Idea cmn line launcher (ToolBox 2.0)
#!/bin/sh
# BIN_PATH=$(ls -d $HOME/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/*/bin | head -n 1)
BIN_PATH=$HOME/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate/bin
("$BIN_PATH/idea.sh" "$@" >/dev/null 2>&1 &)
@jfsanchez91
jfsanchez91 / pycharm
Created August 10, 2023 10:37
Pycharm cmn line launcher (ToolBox 2.0)
#!/bin/sh
# BIN_PATH=$(ls -d $HOME/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/*/bin | head -n 1)
BIN_PATH=$HOME/.local/share/JetBrains/Toolbox/apps/pycharm-professional/bin
("$BIN_PATH/pycharm.sh" "$@" >/dev/null 2>&1 &)
@jfsanchez91
jfsanchez91 / gksu
Created July 13, 2023 16:24
gksu replacement
#!/bin/sh
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY $@
@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
}
@jfsanchez91
jfsanchez91 / to_twitter.sh
Created August 6, 2021 10:39
Bash function to convert videos to be accepted by Twitter format requirements.
#convert videos to be accepted by Twitter
function to_twitter() {
filename=$(basename -- "$1")
ext="${filename##*.}"
filename="${filename%.*}"
echo "Converting $1 to be compatible with the Twitter format."
ffmpeg -i $1 -vcodec libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -pix_fmt yuv420p -strict experimental -r 30 -t 2:20 -acodec aac -vb 1024k -minrate 1024k -maxrate 1024k -bufsize 1024k -ar 44100 -ac 2 $filename.twitter.mp4
}
@jfsanchez91
jfsanchez91 / generate-certificate.sh
Created August 5, 2021 14:18
Bash script for manually generate LetsEncrypt certificates.
#!/bin/bash
echo -n "Enter domain name ( e.g: example.com): "
read domain
echo -n "Enter your email address: "
read email
echo "Generating LetsEncrypt certificate for the domains: $domain and *.$domain"
# JWT decoder
# How to use:
# token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
# 1 - echo $token | jwtd
# 2 - jwtd $token
# # output:
# # {
# # "alg": "HS256",
# # "typ": "JWT",
# # "sub": "1234567890",
@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 / django_admin_autoregister_models.py
Created September 4, 2017 14:30
Django admin automatic model registration method.
""" Django-admin autoregister -- automatic model registration
## sample admin.py ##
from yourproject.autoregister import autoregister
# register all models defined on each app
autoregister('app1', 'app2', 'app3', ...)
"""
from django.apps import apps
from django.contrib import admin