Merge branch 'Fechin:main' into main

This commit is contained in:
Alin Gavriliuc authored and GitHub committed 2023-04-12 17:21:38 +02:00
commit 8513e809f0
5 files changed
+423 -38

No files matched your search

+133 -5
View File
@@ -571,33 +571,161 @@ int main() {
}
```
C++ Classes & Objects
C++ Classes & Objects {.cols-2}
-----------------
### If statement
### Defining a Class
```cpp
class MyClass {
public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};
```
### If statement
### Creating an Object
```cpp
MyClass myObj; // Create an object of MyClass
myObj.myNum = 15; // Set the value of myNum to 15
myObj.myString = "Hello"; // Set the value of myString to "Hello"
cout << myObj.myNum << endl; // Output 15
cout << myObj.myString << endl; // Output "Hello"
```
### If statement
### Constructors
```cpp
class MyClass {
public:
int myNum;
string myString;
MyClass() { // Constructor
myNum = 0;
myString = "";
}
};
MyClass myObj; // Create an object of MyClass
cout << myObj.myNum << endl; // Output 0
cout << myObj.myString << endl; // Output ""
```
### If statement
### Destructors
```cpp
class MyClass {
public:
int myNum;
string myString;
MyClass() { // Constructor
myNum = 0;
myString = "";
}
~MyClass() { // Destructor
cout << "Object destroyed." << endl;
}
};
MyClass myObj; // Create an object of MyClass
// Code here...
// Object is destroyed automatically when the program exits the scope
```
### Class Methods
```cpp
class MyClass {
public:
int myNum;
string myString;
void myMethod() { // Method/function defined inside the class
cout << "Hello World!" << endl;
}
};
MyClass myObj; // Create an object of MyClass
myObj.myMethod(); // Call the method
```
### Access Modifiers
```cpp
class MyClass {
public: // Public access specifier
int x; // Public attribute
private: // Private access specifier
int y; // Private attribute
protected: // Protected access specifier
int z; // Protected attribute
};
MyClass myObj;
myObj.x = 25; // Allowed (public)
myObj.y = 50; // Not allowed (private)
myObj.z = 75; // Not allowed (protected)
```
### Getters and Setters
```cpp
class MyClass {
private:
int myNum;
public:
void setMyNum(int num) { // Setter
myNum = num;
}
int getMyNum() { // Getter
return myNum;
}
};
MyClass myObj;
myObj.setMyNum(15); // Set the value of myNum to 15
cout << myObj.getMyNum() << endl; // Output 15
```
### Inheritance
```cpp
class Vehicle {
public:
string brand = "Ford";
void honk() {
cout << "Tuut, tuut!" << endl;
}
};
class Car : public Vehicle {
public:
string model = "Mustang";
};
Car myCar;
myCar.honk(); // Output "Tuut, tuut!"
cout << myCar.brand + " " + myCar.model << endl; // Output "Ford Mustang"
```
C++ Preprocessor
------------
+122 -27
View File
@@ -8,38 +8,52 @@ tags:
- Framework
categories:
- Programming
intro: What is the "E" for? "Embedded?" Could be. How about "Effective," "Elegant," or just "Easy"? EJS is a simple templating language that lets you generate HTML markup with plain JavaScript. No religiousness about how to organize things. No reinvention of iteration and control-flow. It's just plain JavaScript.
intro: EJS(Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript.
plugins:
- copyCode
---
## Get Started { .cols-2 }
Get Started { .cols-3 }
-----------
### Install
### Hello world
#### install
```
npm install ejs
```
### Use
#### hello.ejs
```html
<% if (user.email) { %>
<h1><%= user.email %></h1>
<% } %>
```
#### CLI
```shell
$ ejs hello.ejs -o hello.html
```
### Render with Data
Pass EJS a template string and some data. BOOM, you've got some HTML.
```
let ejs = require('ejs');
let people = ['geddy', 'neil', 'alex'];
let html = ejs.render('<%= people.join(", "); %>', {people: people});
```
let tpl = '<%= people.join(", "); %>';
let html = ejs.render(tpl, {people: people});
console.log(html);
```
Pass EJS a template string and some data.
### CLI
Feed it a template file and a data file, and specify an output file.
```
ejs ./template_file.ejs -f data_file.json -o ./output.html
```
### Browser Support
Download a browser build from the latest release, and use it in a script tag.
```
<script src="ejs.js"></script>
<script>
@@ -47,21 +61,53 @@ Download a browser build from the latest release, and use it in a script tag.
let html = ejs.render('<%= people.join(", "); %>', {people: people});
</script>
```
Use ejs in a script tag.
## Docs
### Example
```
<% if (user) { %>
<h2><%= user.name %></h2>
<% } %>
### Variables
| | |
|--------------|----------------------------------|
| `<%= var %>` | Prints the value of the variable |
| `<%- var %>` | Prints without HTML escaping |
### CLI
Render and specify an output file.
```shell
$ ejs hello.ejs -o hello.html
```
### Usage
Feed it a template file and a data file
```shell
$ ejs hello.ejs -f data.json -o hello.html
```
### Comments
```html
<%# This line will denote a comment %>
```
---------
```html
<%# This is a multi-line EJS comment.
It can span multiple lines,
but will not be displayed
in the final HTML output.
%>
```
### Method
```
let ejs = require('ejs');
let template = ejs.compile(str, options);
template(data);
// => Rendered HTML string
@@ -73,16 +119,58 @@ ejs.renderFile(filename, data, options, function(err, str){
});
```
### Includes
### Including Files
```html
<%- include('partials/navbar.ejs') %>
```
Include a template with data:
```html
<% include('header', { title: 'My Page' }) %>
```
------------
```html
<ul>
<% users.forEach(function(user){ %>
<%- include('user/show', {user: user}); %>
<%- include('item', {user: user}); %>
<% }); %>
</ul>
```
To include a template, needs a file name option, paths are relative
Docs {.cols-3}
--------
### Conditionals
```html
<% if (userLoggedIn) { %>
<p>Welcome, <%= username %>!</p>
<% } else { %>
<p>Please log in.</p>
<% } %>
```
### Using loops
```html
<% if (userLoggedIn) { %>
<p>Welcome, <%= username %>!</p>
<% } else { %>
<p>Please log in.</p>
<% } %>
```
### Custom delimiters
```
@@ -90,22 +178,29 @@ let ejs = require('ejs'),
users = ['geddy', 'neil', 'alex'];
// Just one template
ejs.render('<?= users.join(" | "); ?>', {users: users},
ejs.render('<?= users.join(" | "); ?>',
{users: users},
{delimiter: '?'});
// => 'geddy | neil | alex'
// Or globally
ejs.delimiter = '$';
ejs.render('<$= users.join(" | "); $>', {users: users});
ejs.render('<$= users.join(" | "); $>',
{users: users});
// => 'geddy | neil | alex'
```
### Caching
```
let ejs = require('ejs'),
LRU = require('lru-cache');
ejs.cache = LRU(100); // LRU cache with 100-item limit
// LRU cache with 100-item limit
ejs.cache = LRU(100);
```
### Custom file loader
@@ -132,7 +227,7 @@ ejs.fileLoader = myFileLoader;
<%- include('footer'); -%>
```
## Client-side support { .cols-1 }
## Client-side support { .cols-2 }
### Example
@@ -229,4 +324,4 @@ Examples of use :
$ ejs -p [ -c ] ./template_file.ejs -o ./output.html
$ ejs ./test/fixtures/user.ejs name=Lerxst
$ ejs -n -l _ ./some_template.ejs -f ./data_file.json
```
```
+45
View File
@@ -54,6 +54,51 @@ h ◀ ─── + ─── ▶ l ││ page
### Copy to Clipboard
Command Syntax:
```
:export.clip format flow
```
----------------
Example:
| Description | Command Example |
|--------------------------------|------------------------------------|
| 1. Copy as a curl command | `:export.clip curl @focus` |
| 2. Copy as a httpie | `:export.clip httpie @focus` |
| 2. Copy as a raw | `:export.clip raw @focus` |
| 2. Copy as a raw HTTP request | `:export.clip raw_request @focus` |
| 2. Copy as a raw HTTP response | `:export.clip raw_response @focus` |
{.style-list}
Export a flow to the system clipboard.
### Save to File
Command Syntax:
```
:export.file format flow path
```
----------------
Example:
| Description | Command Example |
|------------------------------|----------------------------------------------------|
| 1. Export to /tmp/a.curl | `:export.file curl @focus /tmp/a.curl` |
| 2. Export to /tmp/a.httpie | `:export.file httpie @focus /tmp/a.httpie` |
| 2. Export to /tmp/a.raw | `:export.file raw @focus /tmp/a.raw` |
| 2. Export to /tmp/a.request | `:export.file raw_request @focus /tmp/a.request` |
| 2. Export to /tmp/a.response | `:export.file raw_response @focus /tmp/a.response` |
{.style-list}
Export a flow to the system clipboard.
### Common Keybindings
| - | - |
+6 -6
View File
@@ -910,7 +910,7 @@ print(setC) // print: ["D", "C"]
```
### .union() 合并去重
### .union()
```swift
var setA: Set = ["A", "B", "C", "D"]
@@ -1275,7 +1275,7 @@ func season(month: Int, name: inout String) {
name = "Unknown"
}
}
season(monthNum: 4, name: &currentSeason)
season(month: 4, name: &currentSeason)
print(currentSeason) // Spring 🌱
```
@@ -1369,7 +1369,7 @@ struct TV {
var type: String
init(size: Int, type: String) {
self. size = size
self.size = size
self.type = type
}
}
@@ -1407,8 +1407,8 @@ Using the `Menu` class
```swift
var dinerMenu = Menu()
dinerMenu. addToMenu(dish: "Toast")
print(dinerMenu. menuItems)
dinerMenu.addToMenu(dish: "Toast")
print(dinerMenu.menuItems)
// prints: ["Fries", "Burgers", "Toast"]
```
@@ -1633,7 +1633,7 @@ enum Season: CaseIterable {
case falls
}
for season in Season. allCases {
for season in Season.allCases {
print(season)
}
```
+117
View File
@@ -0,0 +1,117 @@
---
title: Taskset
date: 2023-04-07 14:25:44
background: bg-[#8bbb55]
tags:
- process
- process manager
categories:
- Linux Command
intro:
The taskset command is used to set or retrieve the CPU affinity
of a running process given its pid, or to launch a new command
with a given CPU affinity.
plugins:
- copyCode
---
Getting Started {.cols-3}
--------
### Usage
The default behavior is to run a new command with a given affinity mask
```shell
$ taskset [mask] [command] [arguments]
```
#### Usage #2
```shell
$ taskset -p [pid]
```
---------
```shell
$ taskset -p [mask] [pid]
```
You can also retrieve the CPU affinity of an existing task
### Common Options {.col-span-2}
| Command | Alternavite | Meaning |
|---------|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-a` | --all-tasks | Set or retrieve the CPU affinity of all the task (threads) for a given PID. |
| `-c` | --cpu-list | Interpret mask as numerical list of processors instead of a bitmask.</br>Numbers are separated by commas and may include ranges. For example: `0,5,8-11` |
| `-p` | --pid | Operate on an existing PID and do not launch a new task. |
| `-h` | --help | Display help text and exit. |
| `-v` | --version | Print version and exit. |
{.show-header}
Example
--------
### View CPU Affinity
```shell
$ taskset -cp 29523
pid 29523's current affinity list: 0-15
```
That mean process with PID `29523` is active on CPU range from `[0,1,...,15]` which means `16` total.
**PID**: Process Identifier - is a unique numerical identifier given to each running process, you can view PID of processes in `top` or `htop` tools
_If you run the above command but get the message `bad usage`, try with PID = 1_
```shell
$ taskset -cp 1
```
### Set CPU Affinity
Now let's try to set process in to a specify CPU. For example, we have a process has PID = 14846
Let's see the CPU affinity list of this process first:
```shell
$ taskset -cp 14846
pid 14846's current affinity list: 0-15
```
#### Change CPU affinity to 1:
```shell
$ taskset -cp 1 14846
pid 14846's current affinity list: 0-15
pid 14846's new affinity list: 1
```
As we see, CPU affinity was changed
### Set CPU Affinity with muliple value
That mean new CPU affinity list is `[0,1,2,3]`
```shell
$ taskset -cp 0-3 14846
pid 14846's current affinity list: 1
pid 14846's new affinity list: 0-3
```
You can set single CPU with the following command:
```shell
$ taskset -cp 5,8,12 14846
pid 14846's current affinity list: 0-3
pid 14846's new affinity list: 5,8,12
```
That mean new CPU affinity list is `[5,8,12]`
### Other
You can set affinity by range with other like a specify CPU
```shell
$ taskset -cp 1-3,12 14846
```
Or
```shell
$ taskset -cp 1-6:2 14846
```
The suffix ":N" specifies stride in the range, for example 0-10:3 is interpreted as 0,3,6,9 list.
Also see
--------
[taskset — Linux manual page](https://man7.org/linux/man-pages/man1/taskset.1.html) _(man7.org)_