Browse Source

re-wire, let's go go go

main
decentral1se 2 years ago
parent
commit
004f0fcca5
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 23
      README.md
  2. 209
      contrib/init.vim
  3. 15
      exp/README.md
  4. BIN
      exp/files/74ahc138.pdf
  5. BIN
      exp/files/arrestantenhandleiding.pdf
  6. BIN
      exp/files/vanwiehuurik.pdf
  7. 64
      exp/gimmetxt/gimmetxt.go
  8. 25
      exp/ls.go
  9. 34
      exp/readtxt/readtxt.go
  10. BIN
      go-sh-manymanuals
  11. 27
      go-sh-manymanuals.go
  12. 13
      go.mod
  13. 31
      go.sum

23
README.md

@ -1,19 +1,18 @@
# go-sh-manymanuals
> WIP
The idea behind this software came from the [Permacomputing Update
2021](http://viznut.fi/texts-en/permacomputing_update_2021.html), especially
chapter 7. A collapse-tolerant business which is a series of practical
guidelines. One of which reads as follows:
the idea behind this software came from Viznut Permacomputing Update 2021
http://viznut.fi/texts-en/permacomputing_update_2021.html especially chapter 7. Collapse-tolerant business
which is a series of practical guidelines. One of which reads.
> Self-host everything you need for software work on local physical servers.
> This includes all networked applications as well as an extensive library of
> software and documentation (including repair manuals and OS distributions for
> all relevant hardware). Offer hosting services to make use of the surplus.
> Self-host everything you need for software work on local physical servers. This includes all networked applications as well as an extensive library of software and documentation (including repair manuals and OS distributions for all relevant hardware). Offer hosting services to make use of the surplus.
which lead us to think about an application where one can up and download manuals and datasheets for everything in Varia.
Which lead us to think about an application where one can up and download
manuals and datasheets for everything in Varia.
## hacking
Proposal co-learning co-hacking protocol:
- Building blocks & learning programs go in [`exp`](./exp/).
- When we are happy with a thing, we bring it into [`go-sh-manymanuals.go`](./go-sh-manymanuals.go).
`go build . && ./go-sh-manymanuals`

209
contrib/init.vim

@ -1,209 +0,0 @@
scriptencoding utf-8
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source ~/.config/nvim/init.vim
endif
call plug#begin('~/.config/nvim/plugged')
Plug 'Raimondi/delimitMate'
Plug 'Shougo/deoplete.nvim', {'do': ':UpdateRemotePlugins'}
Plug 'Shougo/neosnippet-snippets'
Plug 'Shougo/neosnippet.vim'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'craigemery/vim-autotag'
Plug 'davidhalter/jedi-vim', {'for': 'python'}
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'ervandew/supertab'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries', 'for': 'go'}
Plug 'ggandor/lightspeed.nvim'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'kien/rainbow_parentheses.vim'
Plug 'mhinz/vim-signify'
Plug 'preservim/nerdtree'
Plug 'rhysd/clever-f.vim'
Plug 'sebdah/vim-delve', {'for': 'go'}
Plug 'sheerun/vim-polyglot'
Plug 'morhetz/gruvbox'
Plug 'takac/vim-hardtime'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rsi'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'vim-airline/vim-airline'
Plug 'w0rp/ale'
Plug 'zchee/deoplete-jedi', {'for': 'python'}
call plug#end()
let g:gruvbox_italic=1
let g:gruvbox_termcolors=16
colorscheme gruvbox
set background=dark
hi Normal guibg=NONE ctermbg=NONE
hi Comment ctermfg=grey
let g:hardtime_default_on=1
let g:hardtime_timeout=500
let g:hardtime_maxcout=4
let g:python_host_prog='/usr/bin/python2'
let g:python3_host_prog=$PYENV_ROOT.'/versions/3.9.0/bin/python'
let g:mapleader=';'
let g:airline#extensions#tabline#enabled=1
let g:deoplete#enable_at_startup=1
let g:deoplete#enable_ignore_case=1
let g:SuperTabDefaultCompletionType='<c-n>'
let g:SuperTabLongestHighlight=1
let g:nerdtree_tabs_autoclose=1
let g:nerdtree_tabs_open_on_console_startup=0
let g:nerdtree_tabs_smart_startup_focus=2
let g:nerdtree_tabs_startup_cd=1
let g:nerdree_minimal_ui=1
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeShowHidden=0
let g:jedi#usages_command=''
let g:jedi#popup_select_first=1
let g:jedi#use_tabs_not_buffers=1
let g:jedi#show_call_signatures='2'
let g:jedi#auto_close_doc=1
let g:jedi#completions_enabled=0
let g:ale_linters={
\ 'python': ['flake8', 'mypy'],
\ 'sh': ['shellcheck'],
\ 'bash': ['shellcheck'],
\ }
let g:ale_fix_on_save=1
let g:ale_fixers={
\ '*': ['trim_whitespace', 'remove_trailing_lines'],
\ 'python': ['isort', 'black'],
\ 'go': ['gofmt'],
\ }
let g:ale_lint_delay=500
let g:ale_lint_on_enter=0
let g:ale_lint_on_enter=0
let g:ale_lint_on_filetype_changed=0
let g:ale_lint_on_insert_leave=0
let g:ale_lint_on_save=0
let g:ale_lint_on_save=1
let g:ale_lint_on_text_changed=0
let g:go_fmt_command='goimports'
let g:go_addtags_transform='snakecase'
let g:go_snippet_engine='neosnippet'
let g:go_def_mapping_enabled=0
let g:fzf_tags_command='ctags -R'
let g:delimitMate_nesting_quotes=['"', '`', "'"]
let g:autotagTagsFile='tags'
imap jk <Esc>
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target)
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
ino <C-e> <C-o>a
ino <C-d> <C-o>A
nn <Leader>Z 1z=
nn <C-t> :tabnew<cr>
nn <leader>n :NERDTreeToggle<cr>
nn <leader>f :Files<cr>
nn <leader>r :Rg<cr>
nn <leader>t :Tags<cr>
nn <leader>g :GoDef<cr>
nn <leader>d :GoDoc<cr>
nn <leader>D :GoDocBrowser<cr>
nn <leader>p :Git push<cr>
nn <Leader>ev :split $MYVIMRC<cr>
nn <Leader>sv :source $MYVIMRC<cr>
nn <Leader>pi :PlugInstall<cr>
nn <Leader>pu :PlugUpdate<cr>
nn <Leader>pg :PlugUpgrade<cr>
nn <Leader>pc :PlugClean<cr>
nn <C-j> <C-w>j
nn <C-k> <C-w>k
nn <C-l> <C-w>l
nn <C-h> <C-w>h
syntax on
filetype plugin indent on
set spelllang=en_gb
set nopaste
set nospell
set number
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*.pyc*,*/.venv/*,*/.ve/*
set completeopt=menuone,preview
set wrap
set incsearch
set ignorecase
set textwidth=0
set wrapmargin=0
set nobackup
set nowritebackup
set noswapfile
set history=999
set backspace=indent,eol,start
set ruler
set showmode
set laststatus=2
set scrolloff=10
set cmdheight=2
set hlsearch
set gdefault
set hidden
set whichwrap+=<,>,[,]
set wildmenu
set title
set virtualedit=onemore
set fileencodings=.
set spelllang=en_gb
set foldmethod=indent
set foldlevel=99
set relativenumber
set nohlsearch
set list
set expandtab
set nosmartindent
set shiftwidth=2
set softtabstop=2
set tabstop=2
set splitbelow
set splitright
set inccommand=split
set updatetime=100
set encoding=utf8
set clipboard+=unnamedplus
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
augroup nerdtree
autocmd!
autocmd! FileType nerdtree setlocal relativenumber
augroup END

15
exp/README.md

@ -1,15 +0,0 @@
# exp
> WIP
## `ls.go`
Lists files in [`files`](./files/). Run with `go run ls.go`.
## `gimmetxt.go`
WIP of gosseract pdf OCR. its far from perfect.
* gosseract doesn't OCR pdfs only imagees
* tried using gographics imagick.v2 with imagemagick6
* this only does one page of the PDF, its very slow and it doesn't even do the OCR yet.
* imagemagick6 has a security policy when it comes to pdf. it's not install and go.

BIN
exp/files/74ahc138.pdf

Binary file not shown.

BIN
exp/files/arrestantenhandleiding.pdf

Binary file not shown.

BIN
exp/files/vanwiehuurik.pdf

Binary file not shown.

64
exp/gimmetxt/gimmetxt.go

@ -1,64 +0,0 @@
package main
import (
"log"
"gopkg.in/gographics/imagick.v2/imagick"
)
func main() {
if err := ConvertPdfToJpg("../files/vanwiehuurik.pdf", "out.jpeg"); err != nil {
log.Fatal(err)
}
//client := gosseract.NewClient()
//defer client.Close()
//client.SetImage(file.Name())
//text, _ := client.Text()
//fmt.Println(text)
}
func ConvertPdfToJpg(pdfName string, imageName string) error {
// Setup
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
// Must be *before* ReadImageFile
// Make sure our image is high quality
if err := mw.SetResolution(300, 300); err != nil {
return err
}
// Load the image file into imagick
if err := mw.ReadImage(pdfName); err != nil {
return err
}
// Must be *after* ReadImageFile
// Flatten image and remove alpha channel, to prevent alpha turning black in jpg
if err := mw.SetImageAlphaChannel(imagick.ALPHA_CHANNEL_FLATTEN); err != nil {
return err
}
// Set any compression (100 = max quality)
if err := mw.SetCompressionQuality(95); err != nil {
return err
}
// Select only first page of pdf
mw.SetIteratorIndex(0)
// Convert into JPG
if err := mw.SetFormat("jpg"); err != nil {
return err
}
// Save File
return mw.WriteImage(imageName)
}

25
exp/ls.go

@ -1,25 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"path/filepath"
)
func main() {
fpath, err := filepath.Abs("./files")
if err != nil {
log.Fatalln(err)
}
files, err := ioutil.ReadDir(fpath)
if err != nil {
log.Fatalln(err)
}
for _, file := range files {
fmt.Println(file.Name())
}
}

34
exp/readtxt/readtxt.go

@ -1,34 +0,0 @@
package main
import (
"bytes"
"fmt"
"github.com/ledongthuc/pdf"
)
func main() {
pdf.DebugOn = true
content, err := readPdf("../files/74ahc138.pdf") // Read local pdf file
if err != nil {
panic(err)
}
fmt.Println(content)
return
}
func readPdf(path string) (string, error) {
f, r, err := pdf.Open(path)
// remember close file
defer f.Close()
if err != nil {
return "", err
}
var buf bytes.Buffer
b, err := r.GetPlainText()
if err != nil {
return "", err
}
buf.ReadFrom(b)
return buf.String(), nil
}

BIN
go-sh-manymanuals

Binary file not shown.

27
go-sh-manymanuals.go

@ -1,9 +1,34 @@
package main
import (
"flag"
"fmt"
"os"
)
const help = `go-sh-manymanuals: ???
???
Options:
-h output help
`
var portFlag int
var helpFlag bool
func handleCliFlags() {
flag.BoolVar(&helpFlag, "h", false, "output help")
flag.Parse()
}
func main() {
fmt.Println("Hello, World!")
handleCliFlags()
if helpFlag {
fmt.Printf(help)
os.Exit(0)
}
fmt.Printf("???")
}

13
go.mod

@ -3,7 +3,14 @@ module varia.zone/go-sh-manymanuals
go 1.18
require (
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 // indirect
github.com/otiai10/gosseract/v2 v2.3.1 // indirect
gopkg.in/gographics/imagick.v2 v2.6.0 // indirect
github.com/muesli/coral v1.0.0
github.com/muesli/mango-coral v1.0.1
github.com/muesli/roff v0.1.0
)
require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/muesli/mango v0.1.0 // indirect
github.com/muesli/mango-pflag v0.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)

31
go.sum

@ -1,13 +1,18 @@
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/gosseract/v2 v2.3.1 h1:BFy9Rru7dzqEYX7/tJuEvjVPkkJck0f+b5fYzzr6/RM=
github.com/otiai10/gosseract/v2 v2.3.1/go.mod h1:2ZOGgdTIXQzCS5f+N1HkcXRgDX6K3ZoYe3Yvo++cpp4=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
gopkg.in/gographics/imagick.v2 v2.6.0 h1:ewRsUQk3QkjGumERlndbFn/kTYRjyMaPY5gxwpuAhik=
gopkg.in/gographics/imagick.v2 v2.6.0/go.mod h1:/QVPLV/iKdNttRKthmDkeeGg+vdHurVEPc8zkU0XgBk=
gopkg.in/gographics/imagick.v3 v3.4.0 h1:kSnbsXOWofo81VJEn/Hw8w3qqoOrfTyWwjAQzSdtPlg=
gopkg.in/gographics/imagick.v3 v3.4.0/go.mod h1:+Q9nyA2xRZXrDyTtJ/eko+8V/5E7bWYs08ndkZp8UmA=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/muesli/coral v1.0.0 h1:odyqkoEg4aJAINOzvnjN4tUsdp+Zleccs7tRIAkkYzU=
github.com/muesli/coral v1.0.0/go.mod h1:bf91M/dkp7iHQw73HOoR9PekdTJMTD6ihJgWoDitde8=
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
github.com/muesli/mango-coral v1.0.1 h1:W3nGbUC/q5vLscQ6GPzteHZrJI1Msjw5Hns82o0xRkI=
github.com/muesli/mango-coral v1.0.1/go.mod h1:EPSlYH67AtcxQrxssNw6r/lMFxHTjuDoGfq9Uxxevhg=
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

Loading…
Cancel
Save