Skip to content

Commit 58486e7

Browse files
authored
Merge branch 'master' into master
2 parents 6c055fe + 1907f7b commit 58486e7

19 files changed

+590
-15
lines changed

Diff for: C/C-CheatSheet.pdf

1.51 MB
Binary file not shown.

Diff for: C/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# C
2+
3+
## Cheatsheets:
4+
5+
- [C++ Basics & advance](./C-Cheatsheet.pdf)

Diff for: HTML/readme.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
### HTML
2-
3-
---
4-
5-
#### Cheatsheet:
6-
- [Basic HTML](./Basic%20HTML.pdf)
1+
# HTML
2+
3+
## Cheatsheets:
4+
5+
- [HTML Cheatsheet](./html-cheatsheet.pdf)

Diff for: JavaScript/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
- [Codecademy JavaScript Cheatsheet](./codecademy-js.pdf)
99
- [JavaScript Cheatsheet](./Javascript_cheatsheet.pdf)
1010
- [Javascript Dom Cheatsheet](./JavaScript_DOM_Cheatsheet.pdf)
11-
- [Javascript ES6 Cheatsheet](./es6_chatesheet.pdf)
11+
- [Javascript ES6 Cheatsheet](./es6_cheatsheet.pdf)
1212
- [Javascript Array Reduce Cheatsheet](./javascript-array-reduce.png)
1313
- [Javascript Cheatsheet from overAPI](https://overapi.com/javascript)

Diff for: Neural Networks/brainjs-cheatsheet.md

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# BrainJS
2+
BrainJS is a neural network library for browser JS & NodeJS, for generic code examples see here, for actual explanations see the official documentation.
3+
4+
## Setup
5+
<details>
6+
<summary>Setup</summary>
7+
8+
NodeJS: npm install brainjs
9+
```javascript
10+
const brain = require("brain");
11+
```
12+
browser:
13+
```html
14+
<script src="//unpkg.com/brain.js"></script>
15+
```
16+
</details>
17+
18+
## Minimal Example
19+
<details>
20+
<summary>code</summary>
21+
22+
```javascript
23+
const net = new brain.NeuralNetwork();
24+
const training = net.train([
25+
{ input: [0, 1], output: [1] },
26+
{ input: [0, 0], output: [0] },
27+
{ input: [1, 1], output: [0] },
28+
{ input: [1, 0], output: [1] }]);
29+
net.run([1, 1]); // expect 0
30+
```
31+
</details>
32+
33+
## [Neural Network Types](https://github.com/BrainJS/brain.js#neural-network-types)
34+
<details>
35+
<summary>code</summary>
36+
37+
```javascript
38+
const net = new brain.NeuralNetwork();
39+
// const net = new brain.recurrent.LSTMTimeStep();
40+
// const net = new brain.recurrent.LSTMTimeStep({ inputSize: 2, hiddenLayers: [10], outputSize: 2,});
41+
// const net = new brain.recurrent.LSTM();
42+
// const net = new brain.recurrent.LSTM();
43+
// const net = new brain.recurrent.RNN();
44+
// const net = new brain.NeuralNetworkGPU();
45+
// const net = new brain.NeuralNetworkGRU();
46+
```
47+
</details>
48+
49+
## [Training](https://github.com/BrainJS/brain.js#training)
50+
<details>
51+
<summary>code</summary>
52+
53+
```javascript
54+
net.train([
55+
{ input: [0, 1], output: [1] },
56+
{ input: [0, 0], output: [0] },
57+
{ input: [1, 1], output: [0] },
58+
{ input: [1, 0], output: [1] },
59+
{ input: [0, 1], output: [1] },
60+
{ input: [0, 0], output: [0] },
61+
{ input: [1, 1], output: [0] },
62+
{ input: [1, 0], output: [1] }]);
63+
64+
net.train([
65+
{ input: 'I feel great about the world!', output: 'happy' },
66+
{ input: 'The world is a terrible place!', output: 'sad' },
67+
]);
68+
```
69+
</details>
70+
71+
72+
### [Training Options](https://github.com/BrainJS/brain.js#training-options)
73+
<details>
74+
<summary>code</summary>
75+
76+
```javascript
77+
net.train(data, {
78+
// Defaults values --> expected validation
79+
iterations: 20000, // the maximum times to iterate the training data --> number greater than 0
80+
errorThresh: 0.005, // the acceptable error percentage from training data --> number between 0 and 1
81+
log: false, // true to use console.log, when a function is supplied it is used --> Either true or a function
82+
logPeriod: 10, // iterations between logging out --> number greater than 0
83+
learningRate: 0.3, // scales with delta to effect training rate --> number between 0 and 1
84+
momentum: 0.1, // scales with next layer's change value --> number between 0 and 1
85+
callback: null, // a periodic call back that can be triggered while training --> null or function
86+
callbackPeriod: 10, // the number of iterations through the training data between callback calls --> number greater than 0
87+
timeout: Infinity, // the max number of milliseconds to train for --> number greater than 0
88+
});
89+
```
90+
</details>
91+
92+
### [Asynchronus Training](https://github.com/BrainJS/brain.js#async-training)
93+
<details>
94+
<summary>code</summary>
95+
96+
```javascript
97+
const net = new brain.NeuralNetwork();
98+
const net2 = new brain.NeuralNetwork();
99+
100+
const p1 = net.trainAsync(data, options);
101+
const p2 = net2.trainAsync(data, options);
102+
103+
Promise.all([p1, p2])
104+
.then((values) => {
105+
const res = values[0];
106+
const res2 = values[1];
107+
console.log(
108+
`net trained in ${res.iterations} and net2 trained in ${res2.iterations}`
109+
);
110+
// do something super cool with my 2 trained networks
111+
})
112+
.catch(handleError);
113+
114+
const crossValidate = new brain.CrossValidate(
115+
brain.NeuralNetwork,
116+
networkOptions
117+
);
118+
```
119+
</details>
120+
121+
### [Cross Validation](https://github.com/BrainJS/brain.js#cross-validation)
122+
<details>
123+
<summary>code</summary>
124+
125+
```javascript
126+
crossValidate.train(data, trainingOptions, k); //note k (or KFolds) is optional
127+
const json = crossValidate.toJSON(); // all stats in json as well as neural networks
128+
const net = crossValidate.toNeuralNetwork(); // get top performing net out of `crossValidate`
129+
130+
// optionally later
131+
const json = crossValidate.toJSON();
132+
const net = crossValidate.fromJSON(json);
133+
```
134+
</details>
135+
136+
### [NodeJS Streams](https://github.com/BrainJS/brain.js#train-stream)
137+
<details>
138+
<summary>code</summary>
139+
140+
```javascript
141+
const net = new brain.NeuralNetwork();
142+
const trainStream = new brain.TrainStream({
143+
neuralNetwork: net,
144+
floodCallback: function () {
145+
flood(trainStream, data);
146+
},
147+
doneTrainingCallback: function (stats) {
148+
// network is done training! What next?
149+
},
150+
});
151+
152+
// kick it off
153+
readInputs(trainStream, data);
154+
155+
function readInputs(stream, data) {
156+
for (let i = 0; i < data.length; i++) {
157+
stream.write(data[i]);
158+
}
159+
// let it know we've reached the end of the inputs
160+
stream.endInputs();
161+
}
162+
```
163+
</details>
164+
165+
### [Forecast](https://github.com/BrainJS/brain.js#forecastinput-count---predictions)
166+
<details>
167+
<summary>code</summary>
168+
169+
```javascript
170+
const net = new brain.LSTMTimeStep();
171+
net.fromJSON(json);
172+
net.forecast(input, 3);
173+
174+
const run = net.toFunction();
175+
const output = run({ r: 1, g: 0.4, b: 0 });
176+
console.log(run.toString()); // copy and paste! no need to import brain.js
177+
```
178+
</details>
179+
180+
### [Standalone Function](https://github.com/BrainJS/brain.js#standalone-function)
181+
<details>
182+
<summary>code</summary>
183+
184+
```javascript
185+
const run = net.toFunction();
186+
const output = run({ r: 1, g: 0.4, b: 0 });
187+
console.log(run.toString()); // copy and paste! no need to import brain.js
188+
```
189+
</details>
190+
191+
### [Activation Function](https://github.com/BrainJS/brain.js#activation)
192+
<details>
193+
<summary>code</summary>
194+
195+
```javascript
196+
const net = new brain.NeuralNetwork({
197+
activation: 'sigmoid', /// relu, leaky-relu, tanh
198+
hiddenLayers: [4],
199+
learningRate: 0.6, // global learning rate, useful when training using streams
200+
});
201+
```
202+
</details>
203+
204+
### [Likely](https://github.com/BrainJS/brain.js#activation)
205+
<details>
206+
<summary>code</summary>
207+
208+
```javascript
209+
const likely = require('brain/likely');
210+
const key = likely(input, net);
211+
```
212+
</details>
213+
214+
## [toSVG](https://github.com/BrainJS/brain.js#tosvg)
215+

Diff for: Python/GUI/PySimpleGUI-cheatsheet.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# PySimpleGui
2+
3+
## Minimal example
4+
<details>
5+
<summary>code</summary>
6+
7+
pip install pysimplegui
8+
```python
9+
import PySimpleGUI as sg
10+
layout = [ [sg.Text('Hello world')] ]
11+
window = sg.Window('Window Title', layout)
12+
while Truee:
13+
event, values = window.rad()
14+
window.close()
15+
```
16+
</details>
17+
18+
## [More Elements](https://pysimplegui.readthedocs.io/en/latest/call%20reference/#here-are-all-of-the-elements-the-window-class-and-all-functions)
19+
20+
## Event Handling & Adding data
21+
<details>
22+
<summary>code</summary>
23+
24+
```python
25+
import PySimpleGUI as sg
26+
# In PySimpleGui we just replace our existing window with a new window containing the updated data
27+
todos = []
28+
def layoutMethod():
29+
return [[sg.Text("Input your todos: ", size=(30,2), auto_size_text=True)],
30+
[sg.Input(key='todo-input')],
31+
*[[sg.Text(text="todo: " + todos[_todo]["source"], size=(30,1), auto_size_text=True)] for _todo in range(len(todos))],
32+
[sg.Button('Add Todo'), sg.Button('Close')]]
33+
34+
layout = layoutMethod()
35+
location = (300, 300)
36+
windowTitle = 'Todo list'
37+
window = sg.Window(windowTitle, location=location).Layout(layout)
38+
def main(window):
39+
event, values = window.read()
40+
if event == sg.WIN_CLOSED or event == 'Close':
41+
window.close()
42+
return
43+
if event == "Add Todo": # notice this matches the text inside the button
44+
todoDict = {
45+
"source": values["todo-input"]
46+
}
47+
todos.append(todoDict)
48+
layout = layoutMethod()
49+
location = window.CurrentLocation()
50+
newWindow = sg.Window(windowTitle, location=location).Layout(layout)
51+
window.Close()
52+
window = newWindow
53+
main(window)
54+
main(window)
55+
```
56+
</details>
57+
58+
### [Or](https://pysimplegui.readthedocs.io/en/latest/cookbook/#recipe-pattern-2b-persistent-window-multiple-reads-using-an-event-loop-updates-data-in-window)
59+
<details>
60+
<summary>code</summary>
61+
62+
```python
63+
import PySimpleGUI as sg
64+
65+
sg.theme('BluePurple')
66+
67+
layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(15,1), key='-OUTPUT-')],
68+
[sg.Input(key='-IN-')],
69+
[sg.Button('Show'), sg.Button('Exit')]]
70+
71+
window = sg.Window('Pattern 2B', layout)
72+
73+
while True: # Event Loop
74+
event, values = window.read()
75+
print(event, values)
76+
if event == sg.WIN_CLOSED or event == 'Exit':
77+
break
78+
if event == 'Show':
79+
# Update the "output" text element to be the value of "input" element
80+
window['-OUTPUT-'].update(values['-IN-'])
81+
82+
window.close()
83+
```
84+
</details>
85+
86+
## Themes
87+
### Assigning a theme
88+
<details>
89+
<summary>code</summary>
90+
91+
```python
92+
sg.theme('themename')
93+
```
94+
</details>
95+
96+
### Theme previewer
97+
<details>
98+
<summary>code</summary>
99+
100+
```python
101+
import PySimpleGUI as sg
102+
sg.theme_previewer()
103+
```
104+
</details>
105+
106+
### Custom Themes
107+
<details>
108+
<summary>code</summary>
109+
110+
```python
111+
themename = {'BACKGROUND': 'DARKBLUE',
112+
'TEXT': 'BLACK',
113+
'INPUT': 'RED',
114+
'TEXT_INPUT': '#000000',
115+
'SCROLL': '#WHITE',
116+
'BUTTON': ('white', 'ORANGE'),
117+
'PROGRESS': ('#01826B', '#D0D0D0'),
118+
'BORDER': 1,
119+
'SLIDER_DEPTH': 0,
120+
'PROGRESS_DEPTH': 0 }
121+
122+
sg.theme_add_new('Athema', athema)
123+
sg.theme('themename')
124+
```
125+
</details>
126+
127+
## [Prevent console launching with your theme](https://pysimplegui.readthedocs.io/en/latest/cookbook/#recipe-no-console-launching)
128+

Diff for: Python/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
- [Python-Cheatsheet by memento](./mementopython3-english.pdf)
1010
- [Advanced Python Cheatsheet-A4.pdf](./cheatsheet-python-A4.pdf)
1111
- [Seaborn](./Seaborn_CS.pdf)
12-
- [Django Rest Framework](./drf-cheatsheet.pdf)
13-
- [Python cheatsheet from OverAPI](https://overapi.com/python)
12+
- [Django Rest Framework](./Django/drf-cheatsheet.pdf)
13+
- [Game dev with pgzero](./pgzero-cheatsheet.md)
14+
- [python cheatsheet.pdf](./python-cheatsheet.pdf)
15+
- [Python cheatsheet from OverAPI](https://overapi.com/python)

0 commit comments

Comments
 (0)