From 0036abeffd8d70a5f46f552d1d532bee27614b83 Mon Sep 17 00:00:00 2001 From: fechin Date: Thu, 6 Apr 2023 13:45:07 +0800 Subject: [PATCH 1/6] Fixed #403: C++ Classes & Objects section bugged --- source/_posts/cpp.md | 138 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 133 insertions(+), 5 deletions(-) diff --git a/source/_posts/cpp.md b/source/_posts/cpp.md index af48868..0e8132a 100644 --- a/source/_posts/cpp.md +++ b/source/_posts/cpp.md @@ -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 ------------ From 160d9d0b0babfa965e401ed5b11c397a95424c99 Mon Sep 17 00:00:00 2001 From: HoangLong Date: Sat, 8 Apr 2023 17:25:05 +0700 Subject: [PATCH 2/6] adding taskset --- source/_posts/taskset.md | 133 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 source/_posts/taskset.md diff --git a/source/_posts/taskset.md b/source/_posts/taskset.md new file mode 100644 index 0000000..1c447d7 --- /dev/null +++ b/source/_posts/taskset.md @@ -0,0 +1,133 @@ +--- +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 +-------- + +### Usage #1 +The default behavior is to run a new command with a given +affinity mask +```shell +$ taskset [mask] [command] [arguments] +``` + +### Usage #2 +You can also retrieve the CPU affinity of an existing task: +```shell +$ taskset -p [pid] +``` + Or set it: + ```shell +$ taskset -p [mask] [pid] + ``` + + + ### Common Options +| 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. 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 + ``` + Output: `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 +``` +Output: `pid 14846's current affinity list: 0-15` + +Change CPU affinity to 1 +```shell +$ taskset -cp 1 14846 +``` +Output: + +`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 +```shell +$ taskset -cp 0-3 14846 +``` +Output: + +`pid 14846's current affinity list: 1` + +`pid 14846's new affinity list: 0-3` + +**That mean new CPU affinity list is `[0,1,2,3]`** + +You can set single CPU with the following command: + +```shell +$ taskset -cp 5,8,12 14846 +``` + +Output: + +`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 +-------- +[About taskset](https://man7.org/linux/man-pages/man1/taskset.1.html) From 8b14d019af288756294896fcec898c906722f309 Mon Sep 17 00:00:00 2001 From: Antti Plathan Date: Mon, 10 Apr 2023 11:08:45 +0300 Subject: [PATCH 3/6] Update swift.md Fixed typos in the code examples --- source/_posts/swift.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/_posts/swift.md b/source/_posts/swift.md index 994ce83..71a2147 100644 --- a/source/_posts/swift.md +++ b/source/_posts/swift.md @@ -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: ¤tSeason) +season(month: 4, name: ¤tSeason) 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) } ``` From 9d5b47f0a2f468cfae34dfb2177babf665cec476 Mon Sep 17 00:00:00 2001 From: fechin Date: Tue, 11 Apr 2023 17:26:33 +0800 Subject: [PATCH 4/6] Add some cards to the ejs Cheat sheet --- source/_posts/ejs.md | 149 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 27 deletions(-) diff --git a/source/_posts/ejs.md b/source/_posts/ejs.md index 2a0803f..d3cfcf8 100644 --- a/source/_posts/ejs.md +++ b/source/_posts/ejs.md @@ -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) { %> +

<%= user.email %>

+<% } %> +``` + +#### 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. ``` ``` +Use ejs in a script tag. -## Docs -### Example -``` -<% if (user) { %> -

<%= user.name %>

-<% } %> +### 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
    <% users.forEach(function(user){ %> - <%- include('user/show', {user: user}); %> + <%- include('item', {user: user}); %> <% }); %>
``` +To include a template, needs a file name option, paths are relative + + + +Docs {.cols-3} +-------- + + +### Conditionals +```html +<% if (userLoggedIn) { %> +

Welcome, <%= username %>!

+<% } else { %> +

Please log in.

+<% } %> +``` + + +### Using loops +```html +<% if (userLoggedIn) { %> +

Welcome, <%= username %>!

+<% } else { %> +

Please log in.

+<% } %> +``` + + + ### Custom delimiters ``` @@ -90,22 +178,29 @@ let ejs = require('ejs'), users = ['geddy', 'neil', 'alex']; // Just one template -ejs.render('', {users: users}, +ejs.render('', + {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 -``` \ No newline at end of file +``` From 3c7a7541035d38f0dec4cedc04d3c207df6283fd Mon Sep 17 00:00:00 2001 From: fechin Date: Tue, 11 Apr 2023 17:47:25 +0800 Subject: [PATCH 5/6] Reformat the taskset command cheat sheet --- source/_posts/taskset.md | 90 +++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 53 deletions(-) diff --git a/source/_posts/taskset.md b/source/_posts/taskset.md index 1c447d7..1feaeae 100644 --- a/source/_posts/taskset.md +++ b/source/_posts/taskset.md @@ -12,50 +12,48 @@ intro: of a running process given its pid, or to launch a new command with a given CPU affinity. plugins: - -copyCode + - copyCode --- -Getting Started +Getting Started {.cols-3} -------- -### Usage #1 -The default behavior is to run a new command with a given -affinity mask +### Usage +The default behavior is to run a new command with a given affinity mask ```shell $ taskset [mask] [command] [arguments] ``` -### Usage #2 -You can also retrieve the CPU affinity of an existing task: +#### Usage #2 ```shell $ taskset -p [pid] ``` - Or set it: - ```shell +--------- +```shell $ taskset -p [mask] [pid] - ``` +``` +You can also retrieve the CPU affinity of an existing task - ### Common Options -| 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. 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. | + ### 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.
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 - ``` - Output: `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. +### 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 @@ -65,53 +63,39 @@ _If you run the above command but get the message `bad usage`, try with PID = 1_ $ 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 +### 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 +Let's see the CPU affinity list of this process first: ```shell $ taskset -cp 14846 +pid 14846's current affinity list: 0-15 ``` -Output: `pid 14846's current affinity list: 0-15` -Change CPU affinity to 1 +#### 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 ``` -Output: - -`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 ``` -Output: - -`pid 14846's current affinity list: 1` - -`pid 14846's new affinity list: 0-3` - -**That mean new CPU affinity list is `[0,1,2,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 ``` - -Output: - -`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]`** +That mean new CPU affinity list is `[5,8,12]` ### Other You can set affinity by range with other like a specify CPU @@ -130,4 +114,4 @@ The suffix ":N" specifies stride in the range, for example 0-10:3 is interpreted Also see -------- -[About taskset](https://man7.org/linux/man-pages/man1/taskset.1.html) +[taskset โ€” Linux manual page](https://man7.org/linux/man-pages/man1/taskset.1.html) _(man7.org)_ From 44cb045a376a11bff0875b0803caac1fda78a7b0 Mon Sep 17 00:00:00 2001 From: fechin Date: Tue, 11 Apr 2023 19:15:46 +0800 Subject: [PATCH 6/6] Added export command to mitmproxy cheat sheet. --- source/_posts/mitmproxy.md | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/source/_posts/mitmproxy.md b/source/_posts/mitmproxy.md index 0e41d58..cc69528 100644 --- a/source/_posts/mitmproxy.md +++ b/source/_posts/mitmproxy.md @@ -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 | - | - |