Skip to content

Instantly share code, notes, and snippets.

View allenhwkim's full-sized avatar

Allen Kim allenhwkim

View GitHub Profile
@allenhwkim
allenhwkim / Storage.js
Last active January 24, 2024 14:30
session storage data management
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('.');
@allenhwkim
allenhwkim / cookie.ts
Last active December 11, 2023 08:59
Cookie Class
@allenhwkim
allenhwkim / websocket_client.rb
Created April 18, 2012 21:31
Ruby websocket client
#
# This is modified version of https://github.com/gimite/web-socket-ruby/blob/master/lib/web_socket.rb
#
# Lincense: New BSD Lincense
#
require "base64"
require "socket"
require "uri"
require "digest/md5"
@allenhwkim
allenhwkim / enctypt-decrytp.pipe.ts
Created July 6, 2020 17:03
Angular: Encrypt/Decrypt
import { Pipe, PipeTransform } from '@angular/core';
import * as CryptoJS from 'crypto-js';
const key = 'TUc0emRqRXpkdw==';
@Pipe({name: 'encrypted'})
export class EncryptPipe implements PipeTransform {
transform(value: string) {
if (value) {
return CryptoJS.AES.encrypt(value, key).toString();
@allenhwkim
allenhwkim / encrypt.mjs
Last active April 30, 2023 03:20
NodeJS Compress / Encrypt / Base64
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(/[=]+/,'');
@allenhwkim
allenhwkim / clock.svg
Last active April 24, 2023 11:25
Clock SVG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@allenhwkim
allenhwkim / compress.js
Last active April 20, 2023 13:59
pako string compression to/from base64 in a browser
import pako from 'pako';
// Usage:
// console.log(compress('hello'), decompress(compress('hello')));
export function compress(str) {
var unit8arr = pako.deflate(str);
return base64EncArr(unit8arr);
}
import { Directive, ElementRef, AfterViewInit } from '@angular/core';
@Directive({
selector: '[trapFocus]'
})
export class TrapFocusDirective implements AfterViewInit {
constructor(private el: ElementRef) {}
ngAfterViewInit() {
this.trapFocus(this.el.nativeElement);
@allenhwkim
allenhwkim / resize-handle.js
Created March 3, 2023 21:33
resize handle like <textarea>
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; }
[ 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.