Skip to content

Instantly share code, notes, and snippets.

View lukasbach's full-sized avatar
🦕

Lukas Bach lukasbach

🦕
View GitHub Profile
{
standalone:true,
src_folders:[
'__nightwatch__/testOrchestration'
],
output_folder:'reports',
custom_assertions_path:'',
page_objects_path:'__nightwatch__/pageObjects',
globals_path:'',
selenium:{
@lukasbach
lukasbach / deepReplace.js
Created July 5, 2018 17:55
Replace object members by member name in a deeply nested object
const deepReplace = (obj: object, keyName: string, replacer: (from: any) => string) => {
for (const key in obj) {
if (key === keyName) {
obj[key] = replacer(obj[key]);
} else if (Array.isArray(obj[key])) {
(obj[key] as any[]).forEach(member => deepReplace(member, keyName, replacer));
} else if (typeof obj[key] === "object") {
deepReplace(obj[key], keyName, replacer);
}
}
let funRun = (w1, w2, b) => {
let obj = {};
obj.ga1 = w1 * -0.4 + w2 * 0.5 + b;
obj.ga2 = w1 * -0.8 + w2 * (-0.2) + b;
obj.gb1 = w1 * 0.5 + w2 * 1.2 + b;
obj.gb2 = w1 * -0.4 + w2 * 2.5 + b;
return obj;
}
nextIter = (w1, w2, b) => {
@lukasbach
lukasbach / getUrlParams.js
Created May 14, 2018 14:41
Get url parameters in JavaScript
const getUrlParams = locationSearch => locationSearch.substring(1).split('&')
.reduce((map, obj) => {let [a, b] = obj.split('='); map[a] = b; return map; }, {});
/*
Example:
const params = getUrlParams(window.location.search);
Assuming window.location.search = ?a=b&c=d
Then: params = {a: 'b', c: 'd'}
*/