diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f1ba3fd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules/ +test +*.log +Dockerfile* +README.md +LICENSE +style.tailwindcss + +.idea/ +.github/ +.travis.yml +.eslintignore diff --git a/Dockerfile b/Dockerfile index f9cdd8f..24a2b67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,14 @@ +# Stage 1: build the application +FROM nginx:alpine AS build +RUN rm -rf /etc/nginx/conf.d/* +COPY nginx.conf /etc/nginx/ +COPY public /usr/share/nginx/html/ +EXPOSE 80 + +# Stage 2: final image FROM alpine:latest - -# Install thttpd -RUN apk add --no-cache thttpd - -# Create a non-root user to own the files and run our server -RUN adduser -D static -USER static -WORKDIR /home/static - -# Copy the static website -# Use the .dockerignore file to control what ends up inside the image! -COPY public . - -# Run thttpd -CMD ["thttpd", "-D", "-h", "0.0.0.0", "-p", "3000", "-d", "/home/static", "-u", "static", "-l", "-", "-M", "60"] - -EXPOSE 3000 \ No newline at end of file +RUN apk add --no-cache nginx && mkdir -p /run/nginx +COPY --from=build /usr/share/nginx/html/ /usr/share/nginx/html/ +COPY --from=build /etc/nginx/nginx.conf /etc/nginx/nginx.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..f038b49 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,49 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /var/log/nginx/access.log ; + error_log /var/log/nginx/error.log; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + server { + listen 80; + listen [::]:80; + + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + # error_page + error_page 404 403 500 502 503 504 /assets/page/oops.htm; + + # Rename cheatsheet + rewrite ^/golang$ /go permanent; + rewrite ^/css$ /css3 permanent; + + location / { + try_files $uri $uri/ @html; + } + + location @html { + # remove .html extension + rewrite ^(.*)\.html$ $1 permanent; + try_files $uri.html $uri/ =404; + } + } +} diff --git a/source/_posts/ai.md b/source/_posts/ai.md index 7c0057c..99fe531 100644 --- a/source/_posts/ai.md +++ b/source/_posts/ai.md @@ -949,6 +949,7 @@ Getting Started ### Education assistant +- [ Brain Buddy](https://brain-buddy.com/) - [ Kobra](https://kobra.dev) - [ Boldvoice](https://boldvoice.com) - [ Prepai](https://prepai.in/us) 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 ------------ diff --git a/source/_posts/css.md b/source/_posts/css3.md similarity index 100% rename from source/_posts/css.md rename to source/_posts/css3.md diff --git a/source/_posts/ejs.md b/source/_posts/ejs.md new file mode 100644 index 0000000..d3cfcf8 --- /dev/null +++ b/source/_posts/ejs.md @@ -0,0 +1,327 @@ +--- +title: EJS +date: 2023-04-07 +background: bg-[#b4ca65] +tags: + - EJS + - Frontend + - Framework +categories: + - Programming +intro: EJS(Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript. +plugins: + - copyCode +--- + +Get Started { .cols-3 } +----------- + +### Hello world + +#### install +``` +npm install ejs +``` + +#### hello.ejs +```html +<% if (user.email) { %> +
Welcome, <%= username %>!
+<% } else { %> +Please log in.
+<% } %> +``` + + +### Using loops +```html +<% if (userLoggedIn) { %> +Welcome, <%= username %>!
+<% } else { %> +Please log in.
+<% } %> +``` + + + +### Custom delimiters + +``` +let ejs = require('ejs'), + users = ['geddy', 'neil', 'alex']; + +// Just one template +ejs.render('= users.join(" | "); ?>', + {users: users}, + {delimiter: '?'}); +// => 'geddy | neil | alex' + +// Or globally +ejs.delimiter = '$'; +ejs.render('<$= users.join(" | "); $>', + {users: users}); +// => 'geddy | neil | alex' +``` + + + + +### Caching + +``` +let ejs = require('ejs'), +LRU = require('lru-cache'); + +// LRU cache with 100-item limit +ejs.cache = LRU(100); +``` + +### Custom file loader + +``` +let ejs = require('ejs'); +let myFileLoader = function (filePath) { + return 'myFileLoader: ' + fs.readFileSync(filePath); +}; + +ejs.fileLoader = myFileLoader; +``` + +### Layouts + +``` +<%- include('header'); -%> ++ My page +
+<%- include('footer'); -%> +``` + +## Client-side support { .cols-2 } + +### Example + +``` + + + +``` + +### Caveats + +``` +let str = "Hello <%= include('file', {person: 'John'}); %>", + fn = ejs.compile(str, {client: true}); + +fn(data, null, function(path, d){ // include callback + // path -> 'file' + // d -> {person: 'John'} + // Put your code here + // Return the contents of file as a string +}); // returns rendered string +``` + + +## Options { .cols-1 } + +### Options list +| Option | Description | +|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| cache | Compiled functions are cached, requires filename | +| filename | Used by cache to key caches, and for includes | +| root | Set project root for includes with an absolute path (e.g., /file.ejs). Can be an array to try to resolve include from multiple directories. | +| views | An array of paths to use when resolving includes with relative paths. | +| context | Function execution context | +| compileDebug | When false, no debug instrumentation is compiled | +| client | Returns standalone compiled function | +| delimiter | Character to use for inner delimiter, by default '%' | +| openDelimiter | Character to use for opening delimiter, by default '<' | +| closeDelimiter | Character to use for closing delimiter, by default '>' | +| debug | Outputs generated function body | +| strict | When set to `true`, generated function is in strict mode | +| _with | Whether or not to use with() {} constructs. If false, then the locals will be stored in the locals object. (Implies `--strict`) | +| localsName | Name to use for the object storing local variables when not using with Defaults to locals | +| rmWhitespace | Remove all safe-to-remove whitespace, including leading and trailing whitespace. It also enables a safer version of -%> line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line). | +| escape | The escaping function used with <%= construct. It is used in rendering and is .toString()ed in the generation of client functions. (By default escapes XML). | +| outputFunctionName| Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags. | +| async | When true, EJS will use an async function for rendering. (Depends on async/await support in the JS runtime. | + +## Tags { .cols-1 } + +### Tags list +| Tag | Description | +|------|----------------------------------------------------------------------| +| <% | 'Scriptlet' tag, for control-flow, no output | +| <%_ | 'Whitespace Slurping' Scriptlet tag, strips all whitespace before it | +| <%= | Outputs the value into the template (HTML escaped) | +| <%- | Outputs the unescaped value into the template | +| <%# | Comment tag, no execution, no output | +| <%% | Outputs a literal '<%' | +| %> | Plain ending tag | +| -%> | Trim-mode ('newline slurp') tag, trims following newline | +| _%> | 'Whitespace Slurping' ending tag, removes all whitespace after it | + +## Cli { .cols-1 } + +### Cli list +| Option | Description | +|----------------|-------------------------------------------------------------------------------------------------------------------------| +| cache | Compiled functions are cached, requires filename | +| -o / --output-file FILE | Write the rendered output to FILE rather than stdout. | +| -f / --data-file FILE | Must be JSON-formatted. Use parsed input from FILE as data for rendering. | +| -i / --data-input STRING | Must be JSON-formatted and URI-encoded. Use parsed input from STRING as data for rendering. | +| -m / --delimiter CHARACTER | Use CHARACTER with angle brackets for open/close (defaults to %). | +| -p / --open-delimiter CHARACTER | Use CHARACTER instead of left angle bracket to open. | +| -c / --close-delimiter CHARACTER| Use CHARACTER instead of right angle bracket to close. | +| -s / --strict | When set to `true`, generated function is in strict mode | +| -n / --no-with | Use 'locals' object for vars rather than using `with` (implies --strict). | +| -l / --locals-name | Name to use for the object storing local variables when not using `with`. | +| -w / --rm-whitespace | Remove all safe-to-remove whitespace, including leading and trailing whitespace. | +| -d / --debug | Outputs generated function body | +| -h / --help | Display this help message. | +| -V/v / --version | Display the EJS version. | + + +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 +``` diff --git a/source/_posts/homebrew.md b/source/_posts/homebrew.md new file mode 100644 index 0000000..d44b085 --- /dev/null +++ b/source/_posts/homebrew.md @@ -0,0 +1,176 @@ +--- +title: Homebrew +date: 2023-04-12 +background: bg-[#fbb041] +tags: + - packages manager + - macos +categories: + - Toolkit +intro: This is a quick reference cheat sheet to getting started with homebrew. +plugins: + - copyCode +--- + +## Getting Started + +### Install + +If not installed, instll Command Line Tools (CTL) + +``` +xcode-select --install +``` + +Install Homebrew : + +``` +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +``` + +### Commands + +| | | +|----------------------------------|----------------------------------------| +| ``` brew install git ``` | Install a package | +| ``` brew uninstall git ``` | Uninstall a package | +| ``` brew upgrade git ``` | Upgrade package | +| ``` brew unlink git ``` | Unlink | +| ``` brew link git ``` | Link | +| ``` brew switch git 1.0.0 ``` | Switch package version | +| ``` brew list --versions git ``` | List the installed versions of package | + + +### Help + +Display the version of Homebrew. +```` +brew --version +```` +Print Help Information +```` +brew help +```` +Print Help Info for a brew command +```` +brew help