Skip to content

Instantly share code, notes, and snippets.

View sergioro9's full-sized avatar

Sergio sergioro9

View GitHub Profile
@sergioro9
sergioro9 / generic.js
Last active July 23, 2020 10:02
generic
/*
* Dowload all images in a site. I use it to download the first images for legendario.com
* source: so/19830088/
* example: downlaod free images from pixabar.com
* output: directory in ~/Downloads
*/
function getAllImages() {
images = document.querySelectorAll("img");
for (i of images) {
var a = document.createElement('a');
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
base_url = 'https://en.wikipedia.org'
site = ARGV.empty? ? 'Film_adaptation' : ARGV.shift
url = base_url + "/wiki/#{site}"
Signal.trap('INT') { exit }
@sergioro9
sergioro9 / autoload.sh
Last active January 17, 2023 10:03
Bash autoload
# autoload bash scripts. Much faster than `source script.sh`
# usage: autoload script.sh
autoload() {
[ -f "$1" ] || { echo "Usage ${FUNCNAME[0]} <filename>"; return 1;}
filename="$1"
loadname="$(sed 's:\..*::' <<< $(basename $filename))"
if [ -z "$(eval echo \${${loadname}_loaded})" ]; then
functions=$(command grep -o "^[a-zA-Z0-9_:]* *()" $filename | sed 's/()//')
for f in $functions; do
eval "
@sergioro9
sergioro9 / linguistic.sh
Last active February 7, 2019 22:35
Command line tool to detect language distribution in a codebase, ignore binary or vendored files.
linguistic() {
IFS_ORIGINAL=$IFS
IFS="?"
FILES=($(find -type f -name "*" -not -path "./.git/*" \
-exec sh -c 'printf "%s " "$(du -b {})"' \; \
-exec file -b {} \; ))
SUM=($(sed 's|\./[^ ]*| |g' <<< ${FILES[@]} \
| sort -k2 \
| awk '{v=$1;$1="";s[$0]+=v}END{for(i in s)print s[i] i "?"}' \