Skip to content

Instantly share code, notes, and snippets.

View dot_notation_in_dict.tcl
set some {a {x 1 y 2 z 3} b { x 4 y 5 z 6} c { a {x 7 y 8 z 9}}}
proc d {param} {
set varname [lindex [split $param .] 0]
set params [lrange [split $param .] 1 end]
upvar $varname object
return [dict get $object {*}[join $params { }]]
}
puts "default: [dict get $some a x]"
View catch_all_unknown_method.tcl
rename unknown _unknown
proc unknown {args} {
puts stderr "Hey, wrong method: $args"
}
View encode_decode_url.tcl
package require ncgi
set line "ссылка"
puts "SRC: $line"
set encoded [ncgi::encode [encoding convertto utf-8 $line]]
puts "ENCODED: $encoded"
set decoded [ncgi::decode $encoded]
puts "DECODE $decoded"
View list_all_tcl_packages.tcl
uplevel 0 [package unknown] x
puts "[package names]"
@sagax
sagax / generator.sh
Created Jan 20, 2019
generator of file as json with array of words
View generator.sh
# one command line
export LINE=200000 LWORD=31 FNAME="dict.json" && printf "[" > "$FNAME" && cat /dev/random | tr -dc 'a-zA-Z' | fold -w $LWORD | head -n $LINE | sed 's/^/"/; s/$/",/' >> "$FNAME" && sed -i '$s/",/"]/' "$FNAME"
#
export \
LINE=200000 \
LWORD=31 \
FNAME="dict.json" && \
printf "[" > "$FNAME" && \
cat /dev/random | tr -dc 'a-zA-Z' | fold -w $LWORD | head -n $LINE | sed 's/^/"/; s/$/",/' >> "$FNAME" && \
@sagax
sagax / fishrc_ps1_with_git.fish
Last active Jan 17, 2019
fishrc ps1 with git
View fishrc_ps1_with_git.fish
set -gx TERM "xterm-256color"
set -gx EDITOR "vim"
set c_off "\e[0m"
set c_bold_on "\e[1m"
set c_light_on "\e[2m"
set c_underscore "\e[4m"
set c_blink_on "\e[5m"
set c_reverse "\e[7m"
set c_concealed_on "\e[8m"
@sagax
sagax / bashrc_ps1_with_git.sh
Last active Jan 17, 2019
bashrc ps1 with git
View bashrc_ps1_with_git.sh
export TERM="xterm-256color"
export EDITOR="vim"
# source link:
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
#
# download link:
# https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
PATHTOGITPROMPT="$HOME/git-prompt.sh"
[[ -s "$PATHTOGITPROMPT" ]] && source "$PATHTOGITPROMPT"
View postgresql_cheat_sheet.sh
pg_restore -h 127.0.0.1 -p 5432 -U horse -d horse -v late
#
psql -U username -d basename < command.sql
psql -U username -d basename -t < command.sql
@sagax
sagax / compression_original.sh
Created Oct 28, 2018
compression original image with convert
View compression_original.sh
[[ -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 \