Skip to content

Instantly share code, notes, and snippets.

const conversions = {
0: '', 1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V',
6: 'VI', 7: 'VII', 8: 'VIII', 9: 'IX', 10: 'X',
20: 'XX', 30: 'XXX', 40: 'XL', 50: 'L', 60: 'LX',
70: 'LXX', 80: 'LXXX', 90: 'XC', 100: 'C', 200: 'CC',
300: 'CCC', 400: 'CD', 500: 'D', 600: 'DC', 700: 'DCC',
800: 'DCCC', 900: 'CM', 1000: 'M', 2000: 'MM', 3000: 'MMM'
};
function convertToRoman(num) {
//smaller conversions map object, large ugly helper function, too specific conditional logic in main
const conversions = {
thousandsLetter: 'M', fiveHundredLetter: 'D', hundredsLetter: 'C', fiftyLetter: 'L',
tensLetter: 'X', fiveLetter: 'V', onesLetter: 'I'
};
function convert(n, letter, midLetter, nextLetter) {
let origNum = Number(n);
if(origNum === 0) {
//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);
<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} />
@J2D2Development
J2D2Development / path-splitter.js
Created August 25, 2017 12:59
Insert new string into path
'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('.');
};
@J2D2Development
J2D2Development / strip-fs.js
Last active August 25, 2017 13:01
Using Node's fs module to strip multi spaces from a file
'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);
@J2D2Development
J2D2Development / multi-space.strip.js
Last active August 25, 2017 13:04
Custom Node Transform Stream (just removes multi-spaces)
'use strict';
const { Transform } = require('stream');
class MultiSpaceStrip extends Transform {
constructor(options) {
super(options);
}
_transform(chunk, encoding, callback) {
@J2D2Development
J2D2Development / strip-stream.js
Created August 25, 2017 13:07
Take a file, use transform stream to strip multi-spaces, stream to different path
'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)
import { AfterViewInit, Directive, ElementRef } from '@angular/core';
@Directive({ selector: '[ifautofocus]' })
export class IfAutofocus implements AfterViewInit {
constructor(private elementRef: ElementRef) {}
ngAfterViewInit() {
this.elementRef.nativeElement.focus();
}
}
@J2D2Development
J2D2Development / argument-alias-alt.js
Last active September 23, 2017 23:31
Pass function for returning data directly to "run"
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();
}