Skip to content

Instantly share code, notes, and snippets.

Avatar

Allen Kim allenhwkim

View GitHub Profile
@allenhwkim
allenhwkim / konsole.js
Created Oct 7, 2021
konsole, console wrapper with log level
View konsole.js
export const konsole = {
LOG_LEVEL: 'log',
LOG_LEVELS:
{ all: 0, debug: 1, log: 2, info: 3, warn: 4, error: 5, none: 6 },
debug: function() { konsole.write('debug', arguments) },
info: function() { konsole.write('info', arguments) },
log: function() { konsole.write('log', arguments) },
warn: function() { konsole.write('warn', arguments) },
error: function() { konsole.write('error', arguments) },
@allenhwkim
allenhwkim / text-editable.directive.ts
Created Sep 30, 2021
Angular text-editable directive
View text-editable.directive.ts
import { Component, ElementRef, HostListener, forwardRef, AfterViewInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
@Component({
selector: '[text-editable]',
template: '<ng-content></ng-content>',
providers: [ {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => TextEditableComponent), multi: true
@allenhwkim
allenhwkim / fire-dom-change.js
Created Sep 20, 2021
fireDOMChange(el) and waitForIdle(el)
View fire-dom-change.js
function fireDOMChange(el, options={attributes: false, childList: true, subtree: true}) {
const observer = new MutationObserver(list => el.dispatchEvent(new CustomEvent('dom-change', {detail: list})));
observer.observe(el, options);
}
function waitForIdle(el, options) {
options = Object.assign({
wait: 100, attributes: false, childList: true, subtree: true
}, options);
return new Promise(resolve => {
@allenhwkim
allenhwkim / del-remote-stale-branches.js
Last active Sep 15, 2021
Delete all remote stale branches
View del-remote-stale-branches.js
#!/usr/bin/env node
console.log(`*************************************************************************
* This script will
* 1. Clean up local branches after merge and deleted (git remote prune origin)
* 2. Ask you to delete remote your stale branches that are
* - more than 3 months old
* - and, created by you
* To delete all users' stale branches, add --all at the end
************************************************************************`);
const execSync = require('child_process').execSync;
View clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@allenhwkim
allenhwkim / touch-swipe.js
Created Jul 20, 2021
Mobile TouchSwipe Class
View touch-swipe.js
export class XTouchSwipe {
constructor(el) {
this.touchStaX;
this.toucnendX; // touch position
this.touchSta;
this.touchEnd; // touch time
el = el || document.body;
if (el.getAttribute('x-swipe') === null) {
View conturies.json
[
{
"flag": "https://restcountries.eu/data/afg.svg",
"name": "Afghanistan",
"alpha2Code": "AF",
"alpha3Code": "AFG",
"capital": "Kabul",
"subregion": "Southern Asia",
"population": 27657145
},
@allenhwkim
allenhwkim / color.js
Created Jan 26, 2021
ES5+ Color class
View color.js
export class Color {
constructor(color) {
this.r = this.g = this.b = 0; // red, green, blue
this.h = this.s = this.l = 0; // hue, saturation, lightness
this.set(color);
};
set(color) { // 'rgb(255,255,255)', 'hsl(145, 50%, 50%)', '#FFFFFF'
const hex = color.match(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i);
View example.component.spect.ts
// tslint:disable
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Pipe, PipeTransform, Injectable, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, Directive, Input, Output } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { Observable, of as observableOf, throwError } from 'rxjs';
import { Component, PLATFORM_ID } from '@angular/core';
import { ExampleComponent } from './example.component';
View gist:c58417690dd89077c4bf3c99fdd2426b
import { Component, ViewEncapsulation, ElementRef, AfterViewInit, HostBinding } from '@angular/core';
@Component({
selector: '[oneview-checkbox]',
template: `<ng-content></ng-content>`,
styles: [`
input[oneview-checkbox][type="checkbox"] {
-webkit-appearance: unset;
position: relative;
width: 24px;