Skip to content

Instantly share code, notes, and snippets.

@tohagan
tohagan / index.js
Created August 25, 2018 02:22
RoughAverageDictionaries created by tohagan - https://repl.it/@tohagan/RoughAverageDictionaries
// This line is only needed for server-side NodeJS.
// You should have fetch() available in your client-side browser.
const fetch = require('node-fetch');
// https://jsonplaceholder.typicode.com - Provides test JSON data
var urls = [
'https://jsonplaceholder.typicode.com/todos/1',
'https://jsonplaceholder.typicode.com/todos/2',
'https://jsonplaceholder.typicode.com/posts/1',
@tohagan
tohagan / index.js
Created August 25, 2018 02:23
RoughAverageDictionaries created by tohagan - https://repl.it/@tohagan/RoughAverageDictionaries
// This line is only needed for server-side NodeJS.
// You should have fetch() available in your client-side browser.
const fetch = require('node-fetch');
// https://jsonplaceholder.typicode.com - Provides test JSON data
var urls = [
'https://jsonplaceholder.typicode.com/todos/1',
'https://jsonplaceholder.typicode.com/todos/2',
'https://jsonplaceholder.typicode.com/posts/1',
@tohagan
tohagan / traverse.ts
Last active February 29, 2024 06:09
Typescript function to visit all nodes in a JS object. Visitor pattern
export type TraversePath = Array<string|number> | undefined;
export type TraverseVisitor = (parent: any, key: string | number, val: any, path: TraversePath) => void;
export function traverse(obj: any, visit: TraverseVisitor, path: TraversePath) {
function perNode(key: string | number, val: any) {
const path1 = path ? path.concat([key]) : undefined;
visit(obj, key, val, path1);
traverse(val, visit, path1);
}
@tohagan
tohagan / add-to-app.js
Created July 11, 2019 22:13
Clear Vue Webpack console on hot reload.
// Clear Webpack console on hot reload.
// https://stackoverflow.com/a/53933757/365261
// add to main.js or app.js file
if (module.hot) {
module.hot.accept(); // already had this init code
module.hot.addStatusHandler(status => {
if (status === "prepare") console.clear();
});
}
@tohagan
tohagan / props.js
Last active September 8, 2019 14:33
Get / Set / Delete / Toggle / Increment Object Properties - VueJS Reactive Objects
import Vue from "vue";
function getProp(obj, props) {
let val = obj;
let i = 0;
for (i = 0; i < props.length - 1; i++) {
val = val[props[i]];
if (typeof val !== "object") return undefined;
}
@tohagan
tohagan / AboutPage.vue
Created August 20, 2019 23:42
Vue typescript - Fix type mismatch in component property of Router rules.
<template>
<q-page padding>
<p>This is an about page</p>
</q-page>
</template>
<script>
import Vue, * as VueTypes from "vue" // <<< Fix type mismatch in component property of Router rules.
@Component
const express = require('express');
const app = express();
// Application
app.get('/', function(req, res) {
if (process.env.NODE_ENV === 'development') {
for (var key in require.cache) {
delete require.cache[key];
}
}
@tohagan
tohagan / ts-quasar-cli.md
Last active July 5, 2021 08:30
Add typescript supports to quasar framework

Note: This guide applies to the project created by quasar-cli.

First install typescript and ts-loaderpackages in your project.

npm i -D typescript ts-loader

Then modified the quasar.conf.js file in your project:

@tohagan
tohagan / expandVars.js
Created January 18, 2020 03:07
JavaScript - Expand variables in string
// Polyfill to expand variables in a string
// Example: "Welcome back ${name}. Glad to see you".expandVars({name: "Fred"});
// Variables defined in `vars` can be string/number values or a getter function.
// eslint-disable-next-line no-extend-native
String.prototype.expandVars = function(vars) {
return this.replace(/\${([^{}]*)}/g, function(str, varName) {
var value = vars[varName];
return typeof value === "string" || typeof value === "number" ? value : str;
});