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 / how-to-squash-commits-in-git.md
Created September 1, 2021 16:44 — forked from patik/how-to-squash-commits-in-git.md
How to squash commits in git
View how-to-squash-commits-in-git.md

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

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

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

@dhwang
dhwang / README.md
Created November 16, 2020 07:11 — forked from bergie/README.md
Backbone.js Collection View example
View README.md

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

@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
View node-server.js
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';
View gist:339fedaf10e8bd862dca99aded537465
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);
View canUseSVG.js
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();
View export CSV save to file
// 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();
};
View postMessage pubsub
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);
});
};
View jsonstringify
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
@dhwang
dhwang / lodash.extends
Created April 6, 2017 00:19
lodash subclass
View lodash.extends
_.mixin({
'extends': function(child, base, props) {
child.prototype = _.create(base.prototype, _.assign({
'_super': base.prototype,
'constructor': child
}, props));
return child;
}
});