This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select id="selectOptgroup" defaultValue=""> | |
<option disabled="disabled" value="">Select option...</option> | |
<optgroup label="First section"> | |
<option value="1.1">1.1</option> | |
<option value="1.2">1.2</option> | |
</optgroup> | |
<optgroup label="Second section"> | |
<option value="2.1">2.1</option> | |
<option value="2.2">2.2</option> | |
</optgroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
echo -n 'Password: ' | |
read -s password | |
plain=$(mktemp) | |
openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -pass pass:$password -d <$1 >$plain 2>/dev/null | |
prev=$(mktemp) | |
cp $plain $prev | |
vi $plain | |
if ! (cmp -s $prev $plain); then | |
openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -pass pass:$password <$plain >$1 2>/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
npm i --save mysql | |
const conn = await pool.getAsyncConnection(); | |
await conn.beginTransaction(); | |
try { | |
await conn.query(sql1); | |
await conn.query(sql2); | |
await conn.commit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
SHA256 pure JavaScript implementation. | |
const hexContent = '278f0c9f473ddca628240ac41bfab9fec90612a929ad2d7b'; | |
const aContent = hexToBytes(hexContent); | |
const hash = createHash('sha256'); | |
hash.update(aContent); | |
const aHash = hash.digest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isTokenExpired = token => Date.now() >= (JSON.parse(atob(token.split('.')[1]))).exp * 1000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node ./mem-limit-test.js | |
// node --max-old-space-size=4096 ./mem-limit-test.js | |
// NODE_OPTIONS=--max-old-space-size=4096 node ./mem-limit-test.js | |
const array = []; | |
while (true) { | |
// increase array | |
array.push(new Array(10000000)); | |
const memory = process.memoryUsage(); | |
console.log((memory.heapUsed / 1024 / 1024 / 1024).toFixed(4), 'GB'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nullish coalescing | |
// Нулевое слияние | |
// if data is undefined | |
const getUserName = (user) => { | |
return user?.name ?? "Anonymous"; | |
}; | |
// will display `fallbackData` | |
// if data is false-ish (e.g., null, undefined, '', 0, etc.) | |
console.log(data || fallbackData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
function createFizzBuzzGenerator() { | |
const values = Array(16).fill(null).map((_, i) => { | |
const x = i + 1 | |
if (x % 3 !== 0 && x % 5 !== 0) | |
return x | |
let result = '' | |
if (x % 3 === 0) | |
result += 'Fizz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test task: check if brackets string balanced | |
const bracketsMatch = { | |
'{': '}', | |
'[': ']', | |
'(': ')', | |
} | |
function isBalanced(brackets) { | |
const stack = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Brute-force solution of the Zebra Puzzle | |
// https://code.energy/solving-zebra-puzzle/ | |
// | |
// Result: | |
// Norwegian from 1 house drinks water. | |
// Japanese from 5 house owns zebra. | |
package main | |
import ( |