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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Form controls and validation</title> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
</head> | |
<body> | |
<form onsubmit="handleSubmit(event)" noValidate> <!-- noValidate --> |
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
function reverseString(str) { | |
return !str ? '' : reverseString(str.substr(1)) + str.charAt(0); | |
} | |
reverseString("hello"); | |
function reverse(str){ | |
for (var i = str.length - 1, s=""; i >= 0; i--) s += str[i]; | |
return s; | |
}; | |
reverse("your string comes here") |
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
function isBase64(v) { | |
if (typeof v !== 'string') return false; | |
const regEx = /^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/gi; | |
const isBase64 = regEx.test(v); | |
return isBase64; | |
} | |
// Test | |
var pngString = 'iVBORw0KGgoAAAANSUhEUgAABQAAAALQAQMAAAD1s08VAAAAA1BMVEX/AAAZ4gk3AAAAh0lEQVR42u3BMQEAAADCoPVPbQlPoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4GsTfAAGc95RKAAAAAElFTkSuQmCC'; |
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
class Storage { | |
static getItem(key) { | |
if (key.match(/^([a-z0-9]+)\[['"]?(.*?)['"]?\]$/i)) { // array format e.g., groupName["foo"] | |
const [_, groupKey, itemKey] = key.match(/^([a-z0-9]+)\[['"]?(.*?)['"]?\]$/i); | |
const storageData = sessionStorage.getItem(groupKey); | |
const storageObj = JSON.parse(storageData); | |
return storageObj?.[itemKey]; | |
} else if (key.match(/^([a-z0-9]+)\.([a-z0-9]+)/i)) { // key format groupName.foo | |
const [groupKey, itemKey] = key.split('.'); |
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
import * as crypto from 'crypto'; | |
import * as zlib from 'zlib'; | |
const assert = require('assert'); | |
const encrypt = (val, password='p@55w07d') => { | |
const key = password.repeat(16).substring(0, 32); | |
const iv = key.substring(0, 16).split('').reverse().join(''); | |
let cipher = crypto.createCipheriv('aes-256-cbc', key, iv); | |
let encrypted = cipher.update(val, 'utf8', 'base64'); | |
return (encrypted + cipher.final('base64')).replace(/[=]+/,''); |
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
import pako from 'pako'; | |
// Usage: | |
// console.log(compress('hello'), decompress(compress('hello'))); | |
export function compress(str) { | |
var unit8arr = pako.deflate(str); | |
return base64EncArr(unit8arr); | |
} |
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
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock'; | |
// usage example: | |
// <resize-handle bottom left></resize-handle> | |
// <resize-handle bottom left single></resize-handle> | |
export class ResizeHandle extends HTMLElement { | |
static css = ` | |
resize-handle { position: absolute; } | |
resize-handle:after { content: ' '; display: block; width: 12px; height: 12px; opacity: .5; } |
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
[ req ] | |
default_bits = 2048 | |
default_keyfile = server-key.pem | |
distinguished_name = subject | |
req_extensions = req_ext | |
x509_extensions = x509_ext | |
string_mask = utf8only | |
# The Subject DN can be formed using X501 or RFC 4514 (see RFC 4519 for a description). | |
# Its sort of a mashup. For example, RFC 4514 does not provide emailAddress. |
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
import express from 'express'; | |
import session from 'express-session'; | |
import crypto from 'crypto'; | |
import { Issuer, generators, TokenSet } from 'openid-client'; | |
declare module 'express-session' { | |
export interface SessionData { | |
tokenSet: TokenSet; | |
state: string; | |
codeVerifier: string; |
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
/** | |
given two non-empty arrays A and B consisting of N integers, returns the number of fish that will stay alive. | |
For example, given the arrays shown above, the function should return 2, as explained above. | |
Write an efficient algorithm for the following assumptions: | |
N is an integer within the range [1..100,000]; | |
each element of array A is an integer within the range [0..1,000,000,000]; | |
each element of array B is an integer that can have one of the following values: 0, 1; |