a)
Dòng 5: Khai báo trùng biến i
Dòng 6: Thiếu dấu ; sau while (i <= n)
Dòng 16: Thiếu dấu ; sau i++
Dòng 18: Sai index {1}, {2} => {0}, {1}
a)
Dòng 5: Khai báo trùng biến i
Dòng 6: Thiếu dấu ; sau while (i <= n)
Dòng 16: Thiếu dấu ; sau i++
Dòng 18: Sai index {1}, {2} => {0}, {1}
| // Module using the Module Design Pattern | |
| var Module = (function() { | |
| // Private variable | |
| var privateVariable = "I am a private variable"; | |
| // Private function | |
| var privateFunction = function privateFunction() { | |
| console.log("This is a private function"); | |
| } |
| #!/bin/bash | |
| yum update -y | |
| yum install -y httpd | |
| systemctl start httpd | |
| systemctl enable httpd | |
| TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | |
| EC2_AZ=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone) |
Q1:
This calculator takes values that could be written in a browsers route path as a single string. It then returns the result as a number (or an error message).
Route paths use the '/' symbol so this can't be in our calculator. Instead we are using the '$' symbol as our divide operator.
You will be passed a string of any length containing numbers and operators:
| /** | |
| * It takes a function as an argument, and returns a function that will call the original function, and | |
| * if it throws an error, it will call the next function in the middleware chain | |
| * @param req - The request object | |
| * @param res - The response object | |
| * @param next - The next function in the middleware chain. | |
| * @returns A function that takes a function as an argument and returns the result of that function. | |
| */ | |
| const wrapper = (req, res, next) => async (func) => { | |
| try { |
We prefer to have audit logging in our services that leverage databases. It gives us clarity into sources of where ACL issues might originate as well as gives us a general timeline of activity in our application.
Audit logging is tedious to set up so this gist contains our latest iteration of audit logging support for a sequelize based service.
| const db = EXAMPLE_DB; | |
| const expand = "group.permissions.entities.nestedEntities.slug(searchValue)" | |
| const buildAssocOptions = (str) => { | |
| return str | |
| .split('.') | |
| .reverse() | |
| .reduce((acc, val, index, arr) => { | |
| let currentObj = { | |
| model: |
| 'use strict'; | |
| const crypto = require('crypto'); | |
| const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters) | |
| const IV_LENGTH = 16; // For AES, this is always 16 | |
| function encrypt(text) { | |
| let iv = crypto.randomBytes(IV_LENGTH); | |
| let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv); |
| // Examples of Dependency Injection | |
| // Example 1 | |
| class LoggerConstructorInjection { | |
| constructor(config) { | |
| this.config = config; | |
| } | |
| getConfig() { | |
| return this.config; |
| user www-data; | |
| pid /run/nginx.pid; | |
| worker_processes auto; | |
| worker_rlimit_nofile 65535; | |
| include /etc/nginx/modules-enabled/*.conf; | |
| events { | |
| worker_connections 65535; |