Skip to content

Commit

Permalink
discord notes update
Browse files Browse the repository at this point in the history
  • Loading branch information
5urajdas committed Dec 16, 2021
1 parent 735bfc8 commit 654879b
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 5 deletions.
111 changes: 110 additions & 1 deletion JsNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ to learn:
- [ ] api stuff
- [ ] React

- Things to learn before a framework
- Javascript Fundamental
- Module
- Classe
- Arrow function
- Promises / Asynchronus request
- Destructurin
- Concept of components & stat
- Spread operator
- High order array functions

## Intro
- Javascript is a dynamic lang that runs on both browsers(Spidermonkey and v8) and also outside the browser in the node runtime environment
- Standardised by ECMA and standard is called ECMAscript
Expand Down Expand Up @@ -88,6 +99,20 @@ let newText = text.replace("Mcdonalds", "Dominos");
```
- string.toUpperCase() and string.toLowerCase()
- string.trim() => trims off leading and ending whitespaces
- The isNaN() function determines whether a value is NaN or not. The argument is converted to number first so be careful of that
```js
let ex1 = '123';
let ex2 = 'def not a number';

function checkIfNum(x) {if(isNaN(x)) {
console.log('Hey this is not a number');
} else {
console.log('this is number');
}}

checkIfNum(ex1);
checkIfNum(ex2);
```

#### Template Strings
```js
Expand Down Expand Up @@ -381,4 +406,88 @@ listItems.forEach((item) => console.log(item.textContent))
>Note: Use `querySelector` & `querySelectorAll` most of the time
### Doom Manip
-
- Various methods can be called on the selected document elements
- Examples:

```js
const list = document.querySelector('.items'); // selecting a ul list
list.remove(); // removes the whole list
list.firstElementChild.textContent = 'HEHEHEHHEHEHE'; // changes the text of the first element child of the list
list.children[1].textContent = 'Muhauhauhua'; // first gotta get a node list of all the children of the ul list then access any property of that child
list.lastElementChild.innerHTML = '<a href="https://www.example.com">clikity clak</a>'

const btn = document.querySelector('.btn');
btn.style.background = 'blue'; // changing the color of the btn to be blue
```
- You can use `document.createElement('<name of the tag>')` to create elements out of nowhere

### Events
- Events are fired to notify code of "interesting changes" that may affect code execution. These can arise from user interactions such as using a mouse or resizing a window, changes in the state of the underlying environment (e.g. low battery or media events from the operating system), and other causes. (from mdn docs)
- You add an event listener to the element you want to observe and give it to things: the type of event to look out for and a callback function
- The callback function's first parameter will be the event paratmeter often denoted by `e`. `e` is an object that has properties and methods pretaining to the element that is being observed
- there are many diff event types and can be found in the mdn docs
```js
const btn = document.querySelector('.btn');
btn.addEventListener('click', (e) => {
e.preventDefault(); // prevents default form submit behaviour
body = document.querySelector('body')
body.classList.add('bg-dark')
})
```

### Misc stuff
- `setTimeout(<function>, <time>)` - executes given funciton after given time in miliseconds
- I seem to forget about making the variables actually variables by declaring them with let and const, this is likely a habit from using python so much.
- The `onfocus` property can be set to run a function when a specific element is in focus
```js
let input = document.querySelector('input');

input.onblur = inputBlur;
input.onfocus = inputFocus;

function inputBlur() {
input.value = 'Focus has been lost';
}

function inputFocus() {
input.value = 'Focus is here';
}
```


### Examples
1. Simple form
```js
const loginForm = document.querySelector('#my-form');
const nameInput = document.querySelector('#name');
const emailInput = document.querySelector('#email');
const msg = document.querySelector('.msg');
const users = document.querySelector('#users');

loginForm.addEventListener('submit', submitfn);

function submitfn(e) {
e.preventDefault();
if (nameInput.value === '' || emailInput.value === '') {
msg.classList.add('error');
msg.innerHTML = 'Enter your name and email!';

setTimeout(() => msg.remove(), 3000);
} else {
const li = document.createElement('li');
li.appendChild(document.createTextNode(`${nameInput.value} : ${emailInput.value}`));
users.appendChild(li);
}
}
```

2. ReGex can be used in js by simply creating a regex object and then using this objects' methods. A regex object can be created in 2 ways:
- `let re = \vanilla\d\`
- `let re = new RegExp('^[0-9%^*()=+\/.-]*$');`

3. Whitespaces can be blocked in input boxes like so:
```js
// Stopping the use of space and tab keys
var k = event ? event.which : window.event.keyCode;
if (k == 32) return false;
```
24 changes: 20 additions & 4 deletions PythonNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- [Standard library](#standard-library)
- [Zip()](#zip)
- [Packing and Unpacking variables](#packing-and-unpacking-variables)
- [Environment variables](#environment-variables)
- [With env files](#with-env-files)
- [Venv](#venv)
- [Pyinstaller](#pyinstaller)
- [Threading](#threading)
Expand Down Expand Up @@ -38,7 +40,8 @@
- [Genrators in python](#genrators-in-python)

## Tips
- Use [pyp](https://www.pypy.org/) when doing memory intensive tasks (web frameworks, graphics, etc) or need speed (optimisation)
- Use [pyp](https://www.pypy.org/) when doing memory intensive tasks (web frameworks, graphics, etc) or need speed (optimisation)
- Use type hints for clarity of code and speed too maybe
- Error: UnicodeEncodeError: 'charmap' codec can't encode character '\u2640' in position 23: character maps to <undefined>
- Fix: with open("mangas.txt",'w',encoding='utf-8') as f:
- You just change the encoding of the text to utf-8
Expand Down Expand Up @@ -94,7 +97,20 @@ a, *b = 100, 200, 300
# a -> 100, b -> (200, 300)
```
- You can assign the same value to multiple variables by using = consecutively.
`a = b = 1`
`a = b = 1`

### Environment variables
#### With env files
- A .env file is a text file in which the variables are defined, one per line. The format of a .env file is exactly the same under all operating systems, so .env files make working with environment variables uniform across all platforms.
example `.env` file: `BOT_TOKEN="sapdopsoad"`
- The python-dotenv package allows a Python application to import variables defined in a .env file into the environment. You can install python-dotenv in your virtual environment using pip: `pip install python-dotenv`
- the `load_dotenv` function loads all the variables into the python enivronment
```py
>>> from dotenv import load_dotenv
>>> load_dotenv()
```
- then get the env variable using
`os.getenv('BOT_TOKEN')`

## Venv
- Use venv to isolate packages from the main py installation when doing projects
Expand Down Expand Up @@ -452,15 +468,15 @@ con = sqlite3.connect('example.db')
```py
#Create the connection outside of the function, and pass it into the function, or create a shared memory connection:

db = sqlite3.connect("file::memory:?cache=shared")
db = sqlite3.connect("file:cachedb?mode=memory&cache=shared")

#However, the database will be erased when the last connection is deleted from memory; in your case that'll be each time the function ends.
#Rather than explicitly call db.commit(), just use the database connection as a context manager:

try:
with db:
cur = db.cursor()
# massage `args` as needed
# change `args` as needed
cur.execute(*args)
return True
except Exception as why:
Expand Down
1 change: 1 addition & 0 deletions discordbot.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Tutorials :- [lucas](https://www.youtube.com/watch?v=nW8c7vT6Hl4&list=PLW3GfRiBCHOhfVoiDZpSz8SM_HybXRPzZ&index=1)
- Different available Events :- [Event rerence](https://discordpy.readthedocs.io/en/stable/api.html#event-reference)
- Intents :- [intents](https://discordpy.readthedocs.io/en/stable/api.html#intents)
- Use '|| {link_to_file ||' for spoiler tags

## Imports
```py
Expand Down
1 change: 1 addition & 0 deletions fastapinotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
## Basic Structure
- imports `from fastapi import FastAPI`
- Instantiate the app instance `app = FastAPI()`
- Start the app with `uvicorn main:app --reload` in console

### Routing
- Routes in fastapi are done by using decorators with that routes corresponding http method eg. `@app.get('/'), @app.post('/')`
Expand Down
17 changes: 17 additions & 0 deletions regexNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# RegEx Notes

## Tips from u/nickcernis
- Use https://regexr.com/. You can paste an expression at the top, mouse over each highlighted section, and it will explain what that part does. It's a great way to decipher hieroglyphics into something you can start to understand.
- Complete https://regexone.com/. It's a great interactive introduction to regular expressions that should fill any gaps in your knowledge. You have to fill in the regex that satisfies the named matches.
- Complete https://regexcrossword.com/. It's a “reverse regex” crossword web game where you have to type the string that satisfies the expressions in all of the row and column headers. (See https://regexcrossword.com/howtoplay.)
- Look at common regex patterns and try to understand them. Paste some from https://projects.lukehaas.me/regexhub/ into regexr.com and hover over each group in the regex to help figure out anything you're not familiar with. Start with the shortest examples that you don't yet understand.

### An Introduction
- ReGex is a tool to extract information from text (code, log files, documents,..)
- Everything is a character and we write expressions to match a specific pattern of characters (aka a string)
- Characters include both ascii and unicode
- regex returns every string that has common character given by my query, for eg in: abcdefg, abcde, abc | abc matches all three
- When writing regex its best to be as concise in your expression as possible so that no false positives come up. They call it a `tight` expression.

### The 123s
-

0 comments on commit 654879b

Please sign in to comment.