Skip to content

Instantly share code, notes, and snippets.

View allenhwkim's full-sized avatar

Allen Kim allenhwkim

View GitHub Profile
function fireEvent(el, type, options) {
var event;
if (type === 'click' || type.match(/^mouse/)) {
event = new MouseEvent(type, options);
} else if (type.match(/^key/)) {
event = new KeyboardEvent(type, options);
} else if (type.match(/^touch/)) {
event = new TouchEvent(type, options);
}
el.dispatchEvent(event);
@allenhwkim
allenhwkim / auto-detect-changes.md
Last active May 4, 2020 19:42
Angular5+ Unit Tests

I do not want fixture.detectChanges() called automatically.

test

import { async, ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';

describe('NguiVirtualListComponent', () => {
  ...
  beforeEach(async(() => {
 TestBed.configureTestingModule({
@allenhwkim
allenhwkim / webpack.js
Created June 5, 2018 15:11 — forked from couto/webpack.js
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
@allenhwkim
allenhwkim / cassandra.yaml
Created June 26, 2018 20:20
cassandra.yaml
# Cassandra storage config YAML
# NOTE:
# See http://wiki.apache.org/cassandra/StorageConfiguration for
# full explanations of configuration directives
# /NOTE
# The name of the cluster. This is mainly used to prevent machines in
# one logical cluster from joining another.
cluster_name: 'Test Cluster'
@allenhwkim
allenhwkim / get-class-name.js
Created September 28, 2018 19:47
obj.constructor.name polyfill
const getClassName = function(obj) {
if (obj.constructor.name) return obj.constructor.name;
// Chrome "function HTMLButtonElement() { [native code] }"
var funcMatch = obj.constructor.toString().match(/^\s*function\s*(\S+)\s*\(/);
// IE11 "[object HTMLButtonElement]"
var objMatch = obj.constructor.toString().match(/\[object\s(\S+)\]/);
return objMatch ? objMatch[1] : funcMatch[1];
}
@allenhwkim
allenhwkim / drag-and-drop.js
Last active November 28, 2018 01:23
Fire Dragstart and drop manually
var dragDataTransfer = {
data: {},
setData: function(type, value) { this.data[type] = value; },
getData: function(type) { return this.data[type] }
};
function getDragDropEvent(type, dataTransfer) {
var dragDropEvent = new DragEvent(type);
console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', dataTransfer);
Object.defineProperty(dragDropEvent.constructor.prototype, 'dataTransfer', dataTransfer);
@allenhwkim
allenhwkim / sort.js
Created March 19, 2019 23:48
sorting servivces
const getSortKey = function(el) {
const pad = function(str, len) {
return ('' + str + ' ').slice(0, len);
};
const addr = [pad(el.streetName || '', 5), pad(el.streetNumber || '', 5), pad(el.unit || '', 5)].join('');
const name = [pad((el.firstName||'').toLowerCase(), 5), pad((el.lastName||'').toLowerCase(), 5)].join('');
if (el.product === 'wireless') {
return [pad('', 15), name, el.ctn, '0-wls'].join('');
} else if (el.product === 'internet') {
return [addr, pad('', 20), '1-hsi'].join('');
@allenhwkim
allenhwkim / timing.js
Created March 20, 2019 04:32
animate timing functions
export const timing = {
'linear': function(k) {
return k;
},
'ease-in': function(k) {
return Math.pow(k, 1.675);
},
'ease-out': function(k) {
return 1 - Math.pow(1 - k, 1.675);
},
@allenhwkim
allenhwkim / bounce-in-left.css
Created March 23, 2019 18:41
css animation bounce in left
.bounce-in-left {
animation: bounce-in-left 1.1s both;
}
@keyframes bounce-in-left {
0% {
transform: translateX(-600px);
animation-timing-function: ease-in;
opacity: 0;
}
@allenhwkim
allenhwkim / ng.probe.js
Last active March 25, 2019 01:51
Debugging from console
//
// https://blog.angularindepth.com/everything-you-need-to-know-about-debugging-angular-applications-d308ed8a51b4
//
ng.probe($0).triggerEventHandler('click');
ng.probe($0).parent.nativeElement
ng.probe($0).injector.get('MyService');
ng.probe($0).componentInstance.name;