Tue May 23 01:57:42 WITA 2023
ADD TO THE BOTTOM, NOT HERE!
liver-server
is really really bad when changing CSS UNLESS it is started from a directory rather than .html file.
i.e. ~/something/something/ % live-server something/
-
In order to create a new project on git via CLI git CLI is needed -
gh create repo ${name}
to create the remote via CLI. Then add all and commit push. -
Emmet
on nvim is used with a key combination rather than automatically. i.e.M-y then ,
in my case. -
.tmux.config
will not load if the symlink is broken. Symlink should be created from the destination's folder i.e.~% ln -s something/.dotfiles/.tmux.config .
-
When tmux dies unexpectedly often, it might help to delete the tmux folder form
/temp/
folder. -
A WAY better way to work with the command area of nvim is through
:ctrl f
which will open a nvim-like mini window to work on with the command area.
- in css/html when the meta attribute fails to fill the screen with content in mobile, there is an option to use
min-width: fit-content
attribute. - iterm2 and tmux integratio works really well, if started from iterm2.
- oh-my-zsh is needed for zsh plugins. a super important plugin is
autosuggestions
. - Always remember to add
__dirname
to the relative path forres.sendFile
in express.
- When working with
flex
andCSS
always make sure there are no trailing<br>
s that mess up the spacing. - ALWAYS check for html native tags before some other fancy stuff - e.g.
<input type='date'>
instead of a package. - Better to work with
CDN
rather thannpm
for better preformance (caching). - Put the JS
script
s at the bottom of the HTML to make sure UI loads before the packages. Promises
work differently and cannot be accessed synchoronisly.then
has to be used, for example when calling a fetch API.- TBD Grid VS Flex.
- in iterm2 when
option
key is defined asmeta
thenprefix C-b
which is in many cases a defualt would work out of the box. cd
inFZF
would work only as part ofFZF
in shell (or in my case .zsh) so if it is not installed in .zsh it won't work at all.
- Use a
.zshrc
to add commit push in one line:
function lazygit() {
git add .
git commit -a -m "$*"
git push
}
- Use
nvim -o \
fzf` ` to edit a file found with fzf. - For Emmet shortcuts define ',' as the lead so tapping twice on ',' triggers emmet.
- For commenting, use tcomment plug with
g+motion
or visual block mode with ctrl+v then add # to all lines (takes place only after typing ESC).
Explicit commenting/uncommenting:
g<{motion} :: Uncomment region
g<c :: Uncomment the current line
g<b :: Uncomment the current region as block
g>{motion} :: Comment region
g>c :: Comment the current line
g>b :: Comment the current region as block
In visual mode:
gc :: Toggle comments
g> :: Comment selected text
- In Bash:
main () {
if [ "$1" != "" ]; then
echo "One for $1, one for me."
else
echo "One for you, one for me."
fi
}
# call main with all of the positional arguments
main "$@"
- funcs don't need the argument passed to access it.
- args are accessed: $1 - $N.
- if ends with fi.
- Pipe fzf results to any other bach command - rm for example:
fzf | xargs rm
- In #REACT #JSX - to turn a boolean we can just assign it to the opposite:
chosenTask.isCompleted = !chosenTask.isCompleted;
- Pass
fzf
args tomv
: this will move whatever fzf finds to the example directory:
fzf |
while read fname
do
mv $fname Desktop/example/dir/things.md
done
- Pass
fzf
args tocode
to open in VSCode:
code `fzf`
- When coping a react project, we gotta do the
npm install
to get all the dependencies up and installed, and npm would know where to look for those if there exist apackage.json
file and the install is executed form the project's folder.
- The difference between
class Portfolio extends Component {
andclass Portfolio extends Component() {
is quite big! If there is no need to invoke the function/ component , then don't do it. tabnine adds the paranthesis sometimes!
- Spent at least one hour figuring out how to sign in to GitHub with VSCode - essentially, nothing worked besides deleting the PAT, creating a new one, creating a repo and trying to push --> then instead of password, use the PAT.
- For some time the page wasn't interactive , JS wouldn't work / breaks since it was trying to get DOM elements before the DOM loads.
The solution for this is either to add the defer
attribute to the script tag or to put the script tag at the bottom of the HTML so it renders after the DOM loads.
-
some
npm
packages work withrequire(package)
and some only withimport package from 'package'
.) -
NODE
tip: in order to automatically refresh a node app , install and run thenodemon
package.
- To test an API, install the Thunder Client Extension in VScode and configure parameters, API key, and headers.
-
Start the project from setting up Express, so
npm init -y
and then typescriptyarn add typescript -D
--D
is for devDependencies so it is only available during the build time and locally. -
When using express or other packages with TS, we need to install
yarn add @types/express
or generally:yarn add @types/packageName
to get the type definitions. -
Setting up MongoDB: setting up Mongodb Atlas: get connection string and store it in
.env
file. This is safer than storing it in the code. -
When creating an endpoint, we can use it to test the DB connection with POST. For this we need to create a schema and a model. The schema is the structure of the data and the model is the way we interact with the data. For this we need to use the libraries
mongoose
anddotenv
. doteenv is used to read the.env
file.const dotenv = require('dotenv'); dotenv.config();
- Notice that
require
is outdated and should be replaced withimport
. For eaxample:
import { Router } from 'express';
const router = Router();
-
When interacting with MongoDB, use the VScode extension
MongoDB Explorer
to see the data. -
Remember that tutorials could be outdated, for example,
retult.ops
is not a thing anymore with mongodb, for theinsertOne
method. -
Use this script to automatically update a cell in google sheets with the last edited time:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "2022Q3" ) { //checks that we're on the correct sheet
let targetCell = s.getRange(5,10);
let formattedDate = Utilities.formatDate(new Date(), "GMT+0", 'E MM/dd/yyyy');
targetCell.setValue(formattedDate);
};
};
- Everything I learned today about REACT from Scrimba:
-
React is composable - components can be children of each other. See:
-
React is declarative - we don't tell the browser how to do something, we tell it what to do.
-
React is component based - we can create components and reuse them.
-
JSX turns JS functions into React elements. It is a specific syntax for this purpose.
-
Componenets can be bundled using fragments. Fragments are like empty divs that don't show up in the DOM.
-
Components are named with PascalCase. They are functions that return JSX. We use the following line to render components:
ReactDOM.render(<Component />, document.getElementById('root'));
-
Vite is a bundler that is faster than webpack. It is used to bundle the code and make it ready for production. It comes of the shelf with npm and can be installed with
npm init vite@latest
. It is a zero config bundler. -
To start a project quickly, use vite as follows:
npm init vite@latest my-vite-app -- --template react
or justnpm init vite@latest
and thennpm install
andnpm run dev
.
- Create a global .gitignore and assign it to all projects automatically:
echo .DS_Store >> ~/.gitignore_global #this will add .DS_Store to the global gitignore
git config --global core.excludesfile ~/.gitignore_global #this will store the gitignore_global in the root folder and add it to all future projects
The fast and secure way to find which .vimrc
or init.vim
filr is used is by running:
:echo $MYVIMRC
Details:
https://stackoverflow.com/questions/8977649/how-to-locate-the-vimrc-file-used-by-vim
-
To search across the codebase with amazing preview:
Telescope live_grep
-
Find and replace by pattern:
:%s/<search phrase>/<replace phrase>/options
where the%
symbol applies to all occurrences in the file (can use without for first only).
- Set up copilot on NVChad is a nightmare:
- Has to update in
init.lua
, plugins and custom. BTWinit.lua
is at.config/nvim/init.lua
- Then has to sync NVChad through the NVdashboard.
- Then needs to set lazyload to false for it to work for some reason.
- Has to update in
- The mapping definitions for iterm2 and NVChad get mixed and this is a nightmare for alt specifically, defined as or in mapping settings. The only way to make it work right is to define it in iterm2 settings as the default (which is +esc for option key)..
- Packer is the package manager I'm using and I always forget for #NVIM.
- To jump a full paragraph
}
and{
is very handy. . The very helpful status line I'm using is called Airline.
- #Python - to effectively run jupyter notebook (inside Cursor / VScode or not) the desired follow should be:
- in terminal create an env with venv as follows:
python3 -m venv env_name
and start it withsource env_name/bin/activate
. - Then in that env don't forget to install
ipkernel
andjupyter
so it will be able to be seen as a kernel from the notebook. - Choose that kernel.
- install dependencies with
pip install
inside that env.