Skip to content

Instantly share code, notes, and snippets.

@sagax
sagax / compression_original.sh
Created October 28, 2018 07:47
compression original image with convert
[[ -f "$1" ]] && \
NAME="$1" && \
sname=$(awk -F_original '{print $1}' <<< $NAME) && \
extname=$(cut -d"." -f2 <<< $NAME) && \
convert $NAME \
-sampling-factor 4:2:0 \
-strip \
-quality 85 \
-interlace JPEG \
-colorspace sRGB \
@sagax
sagax / docker.md
Last active October 14, 2018 08:37
docker cheatsheet

example to create docker image in tar file

tar \
    --numeric-owner \
    --exclude=/boot \
    --exclude=/dev \
    --exclude=/pack \
    --exclude=/proc \
    --exclude=/sys \
@sagax
sagax / generator_svg_with_rect_and_text.awk
Created October 5, 2018 21:33
awk script to generation svg document with text inside rect
# GNU Awk 4.2.1, API: 2.0
#
# before run - set variable values, after
# awk -f generator_svg_with_rect_and_text.awk > document.svg
#
# after you can convert svg to png with inkscape
# inkscape --export-png=document.png document.svg
function print_start( page_width, page_height, unit_size) {
printf "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
@sagax
sagax / screen_record.sh
Last active October 10, 2018 10:03
record screen with ffmpeg
#!/bin/bash
# how to use
#
# |----------------------- $1 - filename; can be _
# | |------------------ $2 - window coordinate x
# | | |---------------- $3 - window coordinate y
# | | | |------------ $4 - width
# | | | | |------- $5 - height
# | | | | | |--- $6 - display number
@sagax
sagax / ldd.short.sh
Created September 26, 2018 17:36
get ldd list in short format
ldd "$1" | awk '/=>/{sub(/\.so\.[0-9]{0,}$/, "", $1); print $1}'
@sagax
sagax / get_font_params.sh
Last active August 4, 2018 14:22
Get true font name from font file in json format
fc-scan --format "{\"family\":\"%{family}\",\"fontformat\":\"%{fontformat}\",\"postscriptname\":\"%{postscriptname}\"}"
# fc-scan --format "{\"family\": \"%{family}\" , \"postscriptname\": \"%{postscriptname}\"}" ~/.fonts/7288.ttf | jq .
#
# {
# "family": "Lazurski",
# "postscriptname": "LazurskiBoldCyrillic"
# }
@sagax
sagax / update_package.json.sh
Created August 4, 2018 08:09
Get last version to all dependencies and devDependencies in package.json
# jq - jq-1.5
# awk - GNU Awk 4.2.1, API: 2.0
jq .dependencies,.devDependencies package.json | awk '/^\s/{gsub(/("|:)/, "", $0); command="npm info " $1 " version"; command | getline version; close(command); print " \"" $1 "\": \"" version "\","}'
@sagax
sagax / bash.sh
Created July 21, 2018 15:03
bash cheatsheet
date -d "$(date +%Y/%m/%d)-10 day" +%Y/%m/%d # => 2018/07/11
date -d "$(date +%Y/%m/%d)-0 day" +%Y/%m/%d # => 2018/07/21
fs = require 'fs'
random = (min, max) ->
rand = Math.floor( min + Math.random() * ( max + 1 - min ))
rand
arrDataSize = parseInt process.env['ITEM']
arrData = []
[0...arrDataSize].forEach (item) ->
arrData.push attr: random(1, 20)
@sagax
sagax / youtubeplaylistdownload.sh
Created May 5, 2018 01:52
youtube playlist downloader with youtube-dl
#!/bin/bash
# how to use
# youtubeplaylistdownload.sh link_to_playlist format_to_download
# example
# youtubeplaylistdownload.sh PL5zohYERz9XAYqBu0HQJ_tudt2R6gbPtb 171
#
for url in $(curl -s -X GET https://www.youtube.com/playlist?list="$1" | awk '/data-video-id=/{match($0, /data-video-id="([^"]*)/, arr); print("https://www.youtube.com/watch?v="arr[1]);}'); do
youtube-dl -f "$2" $url
done