Skip to content

Instantly share code, notes, and snippets.

Avatar
💫

Hyeonjun Moon QuatoHub

💫
View GitHub Profile
View Quato.js
// naive solution
const balancedBrackets = function (str) {
const stack = [];
const opener = '(';
const closer = ')';
for (let i = 0; i < str.length; i++) {
if (str[i] === opener) {
stack.push(str[i]);
} else if (str[i] === closer) {
View Quato.js
let output = balancedBrackets('[](){}');
console.log(output); // --> true
output = balancedBrackets('[({})]');
console.log(output); // --> true
let output3 = balancedBrackets('[(]{)}');
console.log(output); // --> false
View Quato.js
let output = balancedBrackets('(');
console.log(output); // // -> false
output = balancedBrackets('()');
console.log(output); // --> true
View Quato.js
encoder.encode('b') // Uint8Array [98]
(98).toString(2) // "1100010"
View Quato.js
let encoder = new TextEncoder(); // 기본 인코딩은 'utf-8'
encoder.encode('코') // Uint8Array(3) [236, 189, 148]
(236).toString(2) // "11101100"
(189).toString(2) // "10111101"
(148).toString(2) // "10010100"
View Quato.js
1110xxxx 10xxxxxx 10xxxxxx // x 안에 순서대로 값을 채워넣습니다.
11101100 10111101 10010100
View Quato.js
const secretKey = ''; // 아까 token 만들때 썼던 secretkey
const router = (req, res) => {
const token = req.headers['x-access-token'] || req.query.token;
jwt.verify(token, secretKey,
function(err, decoded){
console.log(err) // 유효하지 않은 토큰
console.log(decoded) // 유효한 토큰, 유저 정보 Object 반환
}
}
View Quato.js
const jwt = require('jsonwebtoken');
const userInfo = {id: 1, username: 'inyong'};
const secretKey = 'SeCrEtKeYfOrHaShInG';
const options = {expiresIn: '7d', issuer: 'inyongTest', subject: 'userInfo'};
jwt.sign(userInfo, secretKey, options,
function(err,token){
if(err) console.log(err);
else console.log(token);