This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function run(products, dataReturnFx) { | |
async function crawlPage(url) { | |
const page = await browser.newPage(); | |
const pageResult = await page.goto(url); | |
let resultObj = { success: pageResult.ok, url }; | |
resultGroup.push(resultObj); | |
dataReturnFx('crawled', resultObj); | |
return page.close(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//products is your array to crawl, if crawlEmitter is passed, it's used (for broadcasting via socket to frontend). | |
//If not, it's aliased to console.log so the code with the logic stays the same (everything calls "crawlEmitter.emit"). | |
async function run(products, crawlEmitter) { | |
if(!crawlEmitter) { | |
crawlEmitter = { | |
emit: function() { | |
console.log.apply(null, Array.from(arguments)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AfterViewInit, Directive, ElementRef } from '@angular/core'; | |
@Directive({ selector: '[ifautofocus]' }) | |
export class IfAutofocus implements AfterViewInit { | |
constructor(private elementRef: ElementRef) {} | |
ngAfterViewInit() { | |
this.elementRef.nativeElement.focus(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const spaceStripStream = require('./multi-space-strip'); | |
const pathSplitter = require('./path-splitter'); | |
const filePath = process.argv[2]; | |
fs.createReadStream(filePath) | |
.pipe(spaceStripStream) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { Transform } = require('stream'); | |
class MultiSpaceStrip extends Transform { | |
constructor(options) { | |
super(options); | |
} | |
_transform(chunk, encoding, callback) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function(filePath, additionalName) { | |
const filePathArray = filePath.split('.'); | |
const lastItemInPath = filePathArray[filePathArray.length - 2]; | |
filePathArray[filePathArray.length - 2] = `${lastItemInPath}-${additionalName}`; | |
return filePathArray.join('.'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const pathSplitter = require('./path-splitter'); | |
const filePath = process.argv[2]; | |
fs.readFile(filePath, (err, data) => { | |
const stripped = data.toString().replace(/\s+/g, ' '); | |
fs.writeFile(pathSplitter(filePath, 'stripped'), stripped); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { readFile, writeFile } = require('fs'); | |
const { join } = require('path'); | |
readFile(join(__dirname, '../dist-server/main.bundle.js'), 'utf-8', (err, data) => { | |
if(err) { return console.log('Error reading file:', err); } | |
const ssrPageScrollBundle = 'ng2-page-scroll/bundles/ng2-page-scroll.umd.js' | |
const newCode = data.replace('ng2-page-scroll', ssrPageScrollBundle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Card key={key}> | |
<CardHeader title={light.name} subtitle={light.type} /> | |
<CardTitle title={ | |
<LightSwitch | |
id={key} switchedOn={light.state.on} | |
updateLightHandler={updateLightHandler} | |
/>} | |
/> | |
<CardActions> | |
<FlatButton label="Manage" primary={true} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//small conversion array, still somewhat ugly helper logic, simple loop in main | |
const conversions = [ | |
{nextLetter: 'X', midLetter: 'V', letter: 'I'}, | |
{nextLetter: 'C', midLetter: 'L', letter: 'X'}, | |
{nextLetter: 'M', midLetter: 'D', letter: 'C'} | |
]; | |
function convert(n, legend) { | |
let origNum = Number(n); |
NewerOlder