dotfiles

My dotfiles, nothing really interesting to see ...
git clone https://git.onna.be/dotfiles.git
Log | Files | Refs | README

commit 16e73537824b4751e405154a7e92a4b1f9cb622d
parent b6a88631a52774696bfc8832adfc4d7112fdddd3
Author: Paco Esteban <paco@onna.be>
Date:   Sun,  3 Jun 2018 15:24:07 +0200

more bin utils and fixed makefile

Diffstat:
Makefile | 15++++++++-------
bin/b2h | 2++
bin/b2o | 2++
bin/bin | 32++++++++++++++++++++++++++++++++
bin/convertBase.py | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bin/d2b | 2++
bin/d2h | 2++
bin/d2o | 2++
bin/h2b | 2++
bin/h2o | 2++
bin/o2b | 2++
bin/o2h | 2++
12 files changed, 121 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile @@ -9,18 +9,19 @@ endif install: @make $(UNAME) -OSX: zsh nvim tmux git tidy -Linux: zsh nvim tmux git tidy i3 mutt newsboat +OSX: bin zsh nvim tmux git tidy +Linux: bin zsh nvim tmux git tidy i3 clean: @echo "- CLEAN --------------------" - stow -t "$$HOME" -D zsh - stow -t "$$HOME" -D git stow -t "$$HOME/bin" -D bin - stow -t "$$HOME" -D nvim - stow -t "$$HOME" -D tmux + stow -t "$$HOME" -D git stow -t "$$HOME" -D i3 + stow -t "$$HOME" -D nvim stow -t "$$HOME" -D tidy + stow -t "$$HOME" -D tmux + stow -t "$$HOME" -D x11 + stow -t "$$HOME" -D zsh bin: @echo "- BIN ----------------------" @@ -55,4 +56,4 @@ zsh: @echo "- ZSH ----------------------" stow -t "$$HOME" zsh -.PHONY: insta Linux OSX zsh nvim tmux i3 git tidy bin x11 +.PHONY: install Linux OSX zsh nvim tmux i3 git tidy bin x11 diff --git a/bin/b2h b/bin/b2h @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/b2o b/bin/b2o @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin b/bin/bin @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import fileinput +import sys + +line = "" + +# nasty trick to either take stdin or param 1 +if len(sys.argv) < 2: + for l in fileinput.input(): + line += l +else: + line = sys.argv[1] + +chunk_size = 16 + +# split line in chunks of 16 bytes +for i in range(0, len(line), chunk_size): + chunk = line[i:i + chunk_size] + # transform to list, as strings are inmutable in python + chunk_list = list(chunk) + # iterate and substitute any non-printable char + for i, c in enumerate(chunk_list): + if ord(c) < 0x20 or ord(c) > 0x7e: + chunk_list[i] = 'ยค' + # back to string + chunk_filtered = ''.join(chunk_list) + # clever way to transform the original string to hex bytes + chunk_hex = " ".join("{:02x}".format(ord(c)) for c in chunk) + # print it all, similar to hexdump output + print("{:47} {}".format(chunk_hex, chunk_filtered)) diff --git a/bin/convertBase.py b/bin/convertBase.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 + +import sys +from os.path import basename + +if len(sys.argv) != 2: + print("Wrong number of arguments") + sys.exit(1) + +script_name = basename(sys.argv[0]) +res = [] + +if script_name == 'd2b': + base = 10 + bits = 4 + nformat = "{:04b}" +elif script_name == 'd2o': + base = 10 + bits = 7 + nformat = "{:03o}" +elif script_name == 'd2h': + base = 10 + bits = 8 + nformat = "{:02x}" +elif script_name == 'b2h': + base = 2 + bits = 8 + nformat = "{:02x}" +elif script_name == 'b2o': + base = 2 + bits = 7 + nformat = "{:03o}" +elif script_name == 'o2b': + base = 8 + bits = 4 + nformat = "{:04b}" +elif script_name == 'o2h': + base = 8 + bits = 8 + nformat = "{:02x}" +elif script_name == 'h2o': + base = 16 + bits = 7 + nformat = "{:03o}" +elif script_name == 'h2b': + base = 16 + bits = 4 + nformat = "{:04b}" +else: + print("Unrecognized command {}".format(script_name)) + sys.exit(1) + +n = int(sys.argv[1], base) +mask = (1 << bits) - 1 + +while n > 0: + chunk = n & mask + res.insert(0, nformat.format(chunk)) + n = n >> bits + +print(" ".join(res)) diff --git a/bin/d2b b/bin/d2b @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/d2h b/bin/d2h @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/d2o b/bin/d2o @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/h2b b/bin/h2b @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/h2o b/bin/h2o @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/o2b b/bin/o2b @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/o2h b/bin/o2h @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file