Skip to content

Instantly share code, notes, and snippets.

View rubeniskov's full-sized avatar
:octocat:
decrypting matrix

Rubén López Gómez rubeniskov

:octocat:
decrypting matrix
View GitHub Profile
@rubeniskov
rubeniskov / make-gist-modules.sh
Last active September 29, 2022 00:39
make-gist-modules.sh
#usage: script gist_user ... <gist_hash|gist_filename> <gist_hash|gist_filename>
#example: wget -q -O - https://goo.gl/jVJuEc |bash -s rubeniskov concat-bash-sources.mk
#example Makefile includes
#INCLUDE_MODULES = concat-bash-sources.mk \
# build_benchmark.mk \
# crawler.mk \
# publish_gist.mk
#
#include $(shell wget -q -O - goo.gl/jVJuEc |bash -s rubeniskov $(INCLUDE_MODULES))
@rubeniskov
rubeniskov / concat-bash-sources.mk
Created May 3, 2018 14:56
Concatenate bash sources once to create standalone file
# $(call concat_bash_sources,<main.sh>[,header,footer])
define concat_bash_sources
echo "$(1)" |\
awk -v header="$(2)" \
-v footer="$(3)" \
-f <(wget -q -O - https://gist.githubusercontent.com/rubeniskov/b039a9a37827421e7eb3981a29d36c01/raw)
endef
@rubeniskov
rubeniskov / concat-bash-sources.awk
Last active September 29, 2022 00:39
Concatenate bash sources once to create standalone file
#!/usr/bin/env awk
# usage
# echo "main.sh" | awk -v header='# HEADER COMMENT' -v footer='# FOOTER COMMENT' -f concat-bash-sources.awk
function read_file_content(file) {
while ((getline line < file) > 0) {
if ( line ~ /^source / ) {
print parse_bash_source(line)
# remove comments and hashbangs
} else if ( line !~ /^#/ ) {
@rubeniskov
rubeniskov / build_benchmark.mk
Last active September 29, 2022 00:39
Makefile build benchmark snippet
# $(call build_benchmark,<source>)
define build_benchmark
timestamp=$$(date +%s) && \
$(1) \
&& printf >&2 "Build took %d seconds\n" $$(($$(date +%s)-timestamp))
endef
@rubeniskov
rubeniskov / crawler.mk
Last active September 29, 2022 00:39
Makefile crawler urls snippet
# $(call crawler,<url>,<depth_levels>)
define crawler
{ echo '$(1)'\
$(foreach DEPTH_LEVEL, $(shell printf '1 %.0s' {1..$(2)}), \
| xargs -n 1 -P $(shell echo $$(($$(nproc 2>/dev/null|| sysctl -n hw.physicalcpu) * 32))) \
wget \
--delete-after \
--level=$(DEPTH_LEVEL) \
--domains="$(shell echo '$(1)'|awk -F/ '{print $$3}')" \
@rubeniskov
rubeniskov / publish_gist.mk
Last active May 14, 2022 17:03
Makefile publish gist snippet
# $(call publish_gist,<access_token>,<filename>,<description>[,gist_hash])
define publish_gist
cat $(2) |\
awk -v description="$(3)" \
-v filename="$(2)" \
'BEGIN {\
ORS = "";\
print("{");\
printf("\"description\": \"%s\",",description);\
@rubeniskov
rubeniskov / ltu
Last active April 29, 2018 14:47
Linaro Toolchain Utils Standalone
#!/usr/bin/env bash
VERSION=""
LTU_VERSION=${VERSION:="TESTING"}
LTU_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LTU_PATH=${LTU_PATH:="$LTU_DIR"}
LTU_DEST_DIR=${LTU_DEST_DIR:="$LTU_PATH/toolchains"}
LTU_CACHE_DIR=${LTU_CACHE_DIR:="$LTU_PATH/cache"}
@rubeniskov
rubeniskov / ltu_release_links
Last active October 2, 2024 09:34
Linaro Toolchain Releases Download URLs
@rubeniskov
rubeniskov / curl-progress.sh
Last active September 29, 2022 00:39
Custom curl progress
curl https://goo.gl/g8PnUL -L -o bbb_sunflower.mp4 --progress-bar 2>&1 |
while IFS= read -d $'\r' -r p; do
p=${p:(-6)}
p=${p%'%'*}
p=${p/,/}
p=$(expr $p / 10 2>/dev/null);
echo -ne "[ $p% ] [ $(eval 'printf =%.0s {1..'${p}'}')> ]\r"
done
# TODO
@rubeniskov
rubeniskov / print_stdin_table.awk
Last active May 14, 2022 17:03
awk -v argv="Column1%20 Column2%3"
#!/bin/awk
function max(a, b){
return (a > b) ? a : b
}
function draw_splitter(column_sizes){
for(i = 1; i <= length(column_sizes); i++) {
str_splitter=sprintf("%"column_sizes[i]"s", "");
gsub(/ /, "-", str_splitter);