Skip to content

Instantly share code, notes, and snippets.

// this is original
// https://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg
digraph G {
graph [
bgcolor=grey90;
splines=true;
dpi=200;
rankdir=TB;
pad=1;
@sagax
sagax / dot_notation_in_dict.tcl
Created April 6, 2019 22:45
dot notation in dict
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]"
@sagax
sagax / catch_all_unknown_method.tcl
Created April 6, 2019 22:22
catch all unknown method
rename unknown _unknown
proc unknown {args} {
puts stderr "Hey, wrong method: $args"
}
@sagax
sagax / encode_decode_url.tcl
Created April 6, 2019 22:13
encode decode url
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"
@sagax
sagax / list_all_tcl_packages.tcl
Created April 6, 2019 18:16
list all tcl packages
uplevel 0 [package unknown] x
puts "[package names]"
@sagax
sagax / generator.sh
Created January 20, 2019 01:49
generator of file as json with array of words
# 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 January 17, 2019 19:38
fishrc ps1 with git
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 January 17, 2019 12:36
bashrc ps1 with git
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"
@sagax
sagax / mysql_cheat_sheet.sh
Last active November 10, 2018 00:18
mysql cheat sheet
#
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