Skip to main content

CHS

User since Oct 28, 2022
44 Posts
JavaScript
Markdown
Shell
Plaintext
TypeScript
JSON
C++
Java
Python

Recent Posts

VSCode Project Settings

CHS
0 likes • Mar 6, 2024 • 1 view
JSON
{
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
"javascript.preferences.importModuleSpecifier": "non-relative",
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.updateImportsOnFileMove.enabled": "always",
"search.exclude": {
"**/node_modules": true,
"**/package-lock.json": true,
"**/dist": true
}
}

Nginx Serve Storybook

CHS
2 likes • Oct 17, 2023 • 10 views
Shell
# ---------------- FIREWALL STEPS ----------------
# Check if firewalld is installed and running
sudo systemctl status firewalld
# If it's not running, you can start and enable it
sudo systemctl start firewalld
sudo systemctl enable firewalld
# Add a rule to allow traffic on port 6006. Port 6006 is the default port that storybook runs on.
sudo firewall-cmd --permanent --add-port=6006/tcp
# Reload the firewall for the changes to take effect
sudo firewall-cmd --reload
# Check the list of allowed ports
sudo firewall-cmd --list-ports
# ---------------- NGINX STEPS ----------------
# Install Nginx (if not already installed)
sudo yum install nginx
# Start and enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
# Copy your storybook-static directory to a location that Nginx can serve from.
# The default web root directory for Nginx is /usr/share/nginx/html.
sudo cp -r /path/to/storybook-static /usr/share/nginx/html/
# Adjust file permissions if needed to ensure that Nginx can read the files
sudo chown -R nginx:nginx /usr/share/nginx/html/storybook-static
# Put the following server block in /etc/nginx/conf.d/storybook.conf
server {
listen 6006;
server_name your_domain.com;
location / {
root /usr/share/nginx/html/storybook-static;
index index.html;
}
}
# Test the Nginx configuration for syntax errors
sudo nginx -t
# If there are no errors, reload Nginx to apply the changes
sudo systemctl reload nginx

Tree Traversal

CHS
0 likes • Oct 16, 2023 • 7 views
JavaScript
class TreeNode {
constructor(data, depth) {
this.data = data;
this.children = [];
this.depth = depth;
}
}
function buildNaryTree(hosts) {
const nodeMap = {};
// Step 1: Create a map of nodes using fqdn as the key
hosts.forEach((host) => {
nodeMap[host.fqdn] = new TreeNode(host, 0); // Initialize depth to 0
});
// Step 2: Iterate through the array and add each node to its parent's list of children
hosts.forEach((host) => {
if (host.displayParent) {
if (nodeMap[host.displayParent]) {
const parent = nodeMap[host.displayParent];
const node = nodeMap[host.fqdn];
node.depth = parent.depth + 1; // Update the depth
parent.children.push(node);
} else {
console.error(`Parent with fqdn ${host.displayParent} not found for ${host.fqdn}`);
}
}
});
// Find the root nodes (nodes with no parent)
const rootNodes = hosts.filter((host) => !host.displayParent).map((host) => nodeMap[host.fqdn]);
return rootNodes;
}
function treeToObjects(node) {
const result = [];
function inOrder(node) {
if (!node) {
return;
}
// Visit the current node and add it to the result
result.push(node.data);
// Visit children nodes first
node.children.forEach((child) => {
inOrder(child);
});
}
inOrder(node);
return result;
}
// Usage example
const hosts = [
{
fqdn: 'fqdn_1',
display_name: 'Host 1',
},
{
fqdn: 'fqdn_2',
display_name: 'Host 2',
displayParent: 'fqdn_1',
},
{
fqdn: 'fqdn_3',
display_name: 'Host 3'
},
{
fqdn: 'fqdn_4',
display_name: 'Host 4',
displayParent: 'fqdn_3',
},
{
fqdn: 'fqdn_5',
display_name: 'Host 5',
displayParent: 'fqdn_1',
},
];
const tree = buildNaryTree(hosts);
// Function to convert the tree to an array of objects
function convertTreeToArray(nodes) {
const result = [];
nodes.forEach((node) => {
result.push(...treeToObjects(node));
});
return result;
}
// Convert the tree back to an array of objects
const arrayFromTree = convertTreeToArray(tree);
console.log(arrayFromTree);

Update Prefixed Dependencies

CHS
0 likes • Oct 9, 2023 • 42 views
Shell
# Update all npm packages under the scope defined by the PREFIX variable ("foo").
PREFIX="foo"; npm ls | grep "$PREFIX" | awk -F/ '{print $NF}' | sed 's/@.*//' | xargs -I package npm update @"$PREFIX"/package

LeetCode Product Except Self

CHS
0 likes • Sep 13, 2023 • 6 views
JavaScript
/**
* @param {number[]} nums
* @return {number[]}
*/
var productExceptSelf = function(nums) {
var output = [];
var leftMult = 1;
var rightMult = 1;
for (var i=nums.length - 1; i >= 0; i--) {
output[i] = rightMult;
rightMult *= nums[i];
console.log({output: JSON.stringify(output), i})
}
for (var j=0; j < nums.length; j++) {
output[j] *= leftMult;
leftMult *= nums[j];
console.log({output: JSON.stringify(output), j})
}
return output;
};
console.log(productExceptSelf([1, 2, 3, 4]))

LeetCode Contains Duplicate

CHS
0 likes • Sep 13, 2023 • 2 views
JavaScript
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
return new Set(nums).size !== nums.length
};

Post Statistics

Posts

No Posts Found

It looks like CHS hasn't uploaded a post yet

Likes

Please Log In

You must be authenticated to view a user's likes

Shared

Please Log In

You must be authenticated to view a user's shared posts

Profile Privacy

Multi-Factor Authentication

Multi-Factor Authentication (MFA) is an authentication method that requires you to provide two or more verification factors to gain access to your account. In addition to username and password, MFA requires you to verify your email on every login, which decreases the likelihood of someone stealing your account.

Change Password

Forgot Password?

Identity Color

Changes the color of your profile icon and cursor highlight in the live code editor. You and other users will be able to view this change.

Delete Account

Deleting your account is permanent. All data associated with your account will be lost.