Skip to content

Instantly share code, notes, and snippets.

View jorgerance's full-sized avatar
💭
I may be slow to respond.

Jorge Rancé Cardet jorgerance

💭
I may be slow to respond.
View GitHub Profile
@jorgerance
jorgerance / killit.sh
Created January 14, 2020 03:29
[killit.sh] Easily killing all processes related to a specific binary #bash #macos #cli #tool #script
#!/bin/bash
source $HOME/.env/old_dot_custom/fx_msgFormatting.sh
_scriptname="$(basename $0)"
_forceKill=$1
_stringtokill="$@"
function pidlist_gen() {
ps -eo pid= -o cputime= -o comm= | grep -v grep | grep -i ${_stringtokill}
@jorgerance
jorgerance / vars_colours.sh
Created January 14, 2020 03:38
[colors.sh] bash helper for using colors #cli #helper #colors #output
#!/usr/bin/env bash
# Define ANSI color escape code
# color <ansi_color_code>
color() { printf "\033[${1}m"; }
# No Color
NO_COLOR=$(color "0")
NC=${NO_COLOR}
@jorgerance
jorgerance / fx_msgFormatting.sh
Created January 14, 2020 03:44
[msgFormatting.sh] output formatting bash helper #bash #helper #script #printf #format #emoji #colors
#!/usr/bin/env bash
## Output formatting helper for bash
source ~/.env/bash_helpers/vars_colours.sh
## Get exit status of process that's piped to another
set -o pipefail
## fx
@jorgerance
jorgerance / jekyll_findAndReplace.sh
Created January 15, 2020 03:22
[findAndReplace.sh] Recursive find files with specific extension within multiple dirs and replace multiple strings. Currently using it on Jekyll builds #jekyll #sed #find #replace #bash #ruby #helper #build
#!/bin/bash
# Source bash output formatting helper
source ${BASH_HELPERS}/msg_format.sh
# Strings to replace before building site "orignal1:::new1" "original2:::new2"
declare -a stringsToReplace=("original1:::new1" "original2:::new2")
for string in "${stringsToReplace[@]}"; do
@jorgerance
jorgerance / figlet_fonts.txt
Last active February 10, 2022 16:22
[Figlet Hamburgefonstiv test] Testing all figlet fonts #fonts #typography #bash #script #Hamburgefonstiv #Hamburgevons
0 ✓ steve@hal9000 ~ $ figlist | \
awk '/fonts/ {f=1;next} /control/ {f=0} f {print}' |\
while read font; do\
printf "\n\n\n>>> Font: $font\n\n"
echo 'Hamburgefonstiv' | \
figlet -w 150 -f $font
done
@jorgerance
jorgerance / index.js
Created January 17, 2020 02:32
[Web scraping with Node.js and PostgreSQL using Puppeteer] #example #node #nodejs #puppeteer #postgresql #postgres #scrpping #crawling
// Puppeteer
const puppeteer = require('puppeteer');
// PostgreSQL
const pg = require('pg');
// Login + PostgreSQL credentials
const CREDS = require('./creds');
// Base URL
const URL = 'https://<WOOCOMMERCE_FQDN>'
const PRODUCT = '<PRODUCT_URL_PATH>'
@jorgerance
jorgerance / bootstrap.sh
Last active February 14, 2024 00:43
[Raspberry Pi Bootstrap script] Setting up raspberry defaults with bash #bash #raspberry #boostrab #custom #image #customize
#!/bin/bash
# Fail on error
set -e
source "$1"
cd "$(dirname "$0")"
if [ $# -ne 1 ]; then
@jorgerance
jorgerance / pie_chart.py
Last active February 4, 2020 01:09
[pandas - cool pie (donut) charts] #pandas #jupyter #plotting #piechart #python
def plot_piechart(data, column_numbers, column_index):
"""
Plots a preformated pie chart
- data: dataframe
- column_values: column name for quantitative values
- column_index: column name for qualitative values
"""
''' colormaps: https://matplotlib.org/examples/color/colormaps_reference.html
https://matplotlib.org/tutorials/colors/colormaps.html#kovesi-colormaps'''
@jorgerance
jorgerance / group_small_values.py
Last active February 4, 2020 01:05
[pandas - group small values] #python #pandas #data #datamanipulation #dataframe #jupyter #notebook
def group_small_values(data, idx, column, percentage):
"""
Groups small dataframe values into a sigle group
- data = source dataframe
- idx = column with qualitative values
- column = column to evaluate
- percentage = group values which value > sum(column)
"""
total_column = data[column].sum()
other_percentage = ((float(total_column) / float(100) * float(percentage)))
@jorgerance
jorgerance / print_imports_version.py
Created February 4, 2020 02:02
[print imports version] #python #imports #version
def imports_version():
"""
Print imported modules and its version
Source: https://stackoverflow.com/a/50396275
"""
import sys
for module in sys.modules:
try:
print(module,sys.modules[module].__version__)