Skip to content

Instantly share code, notes, and snippets.

View dhwang's full-sized avatar
💭
I may be slow to respond.

Darren Hwang dhwang

💭
I may be slow to respond.
  • San Jose
View GitHub Profile
@dhwang
dhwang / ReportView.js
Created September 28, 2015 19:06
Backular, injecting Angular view into Backbone
render: function (el) {
var self = this;
self.$el.empty();
self.$el.html(PageTemplate);
if (!window.quotainjector) {
window.quotainjector = window.angular.bootstrap(document, ['QuotaReportView'])
window.quotainjector.invoke(function($rootScope) {
console.log('invoke self.periodYears',self.periodYears)
@dhwang
dhwang / lodash.extends
Created April 6, 2017 00:19
lodash subclass
_.mixin({
'extends': function(child, base, props) {
child.prototype = _.create(base.prototype, _.assign({
'_super': base.prototype,
'constructor': child
}, props));
return child;
}
});
app.service('appPubSub', function($window) {
this.subscribe = function(subject, cb) {
$window.addEventListener('message', function(event) {
if (typeof(event.data.message) === 'string') {
event.data.message = JSON.parse(event.data.message.replace(/\&dquot/g, '"').replace(/\&squot/g, "'"));
}
return event.data.subject === subject && cb(event.data.message);
});
};
// http://buildwebthings.com/create-csv-export-client-side-javascript/
function exportToCsv(filename, rows) {
var processRow = function (row) {
var finalVal = '';
for (var j = 0; j < row.length; j++) {
var innerValue = row[j] === null ? '' : row[j].toString();
if (row[j] instanceof Date) {
innerValue = row[j].toLocaleString();
};
function JSONstringify( obj ) {
var val, results = [];
results.push('{')
for(var key in obj) {
val = obj[key];
results.push('"'+ key + '": ')
if (typeof(val) === 'number') {
results.push(val)
} else
import _ from 'lodash';
/**
* Check to see if a particular SVG tag is supported in the browser.
* <code> console.log('foreignObject', canUseSVG('foreignObject')); </code>
* @returns Boolean
*/
export const canUseSVG = (tagStr) => {
if (!_.isEmpty(tagStr)) {
const lowerCaseTag = tagStr.toLowerCase();
function appendFragment(element, data) {
var tagMap = { ul: 'li', table: 'tr', tr: 'td' };
var tag = tagMap[element.tagName] || 'li';
var fragment = document.createDocumentFragment();
data.forEach(function(item) {
var li = document.createElement(tag);
li.textContent = item;
fragment.appendChild(li);
@dhwang
dhwang / node-server.js
Created April 25, 2020 00:50 — forked from ramandeep-singh-1983/node-server.js
Sample node.js server code for Keycloak based authentication
var Keycloak = require('keycloak-connect');
var fs = require('fs');
var express = require('express')
var session = require('express-session');
var https = require('https');
var atob = require('atob');
const path = require('path');
var cors = require('cors');
const HOST = 'my-awesome-sauce-app.com';
@dhwang
dhwang / README.md
Created November 16, 2020 07:11 — forked from bergie/README.md
Backbone.js Collection View example

This is an example of using a Collection view with Backbone.

@dhwang
dhwang / e2e-shadowdom.md
Created April 8, 2021 07:59 — forked from ChadKillingsworth/e2e-shadowdom.md
Selenium Testing with Shadow DOM

End-to-end Testing with Shadow DOM

As the web component specs continue to be developed, there has been little information on how to test them. In particular the /deep/ combinator has been deprecated in Shadow DOM 1.0. This is particularly painful since most end-to-end testing frameworks rely on elements being discoverable by XPath or calls to querySelector. Elements in Shadow DOM are selectable by neither.

WebDriver.io

Webdriver.io has the standard actions by selectors, but also allows browser executable scripts to return an element