Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tohagan
tohagan / herokuconfig.sh
Last active November 27, 2021 04:45
Read .env format file from stdtin and sets environment on Heroku app
#!/bin/bash
#
# Read .env format file from stdtin and sets environment on Heroku app
# Usage:
# $ grep '^SOME_PREFIX' .env.production | herokuconfig.sh | sh -x
#
sed -e '/^#/d' -e '/^$/d' -e 's/^/heroku config:set /'
@tohagan
tohagan / RemoveWindowsPathsWsl.md
Last active August 21, 2021 03:26
Remove Windows paths from WSL

If you have node / nvm installed in Windows and then run WSL ... you may end up running Node or NVM from Windows.

To fix this ... remove Windows PATH folders from your WSL environment by ...

  • Confirming that you have Windows paths in WSL

    $ echo $PATH | tr : '\n'

For Windows build HIGHER than 17713 (safer option)

  • Inside WSL ... create a /etc/wsl.conf file containing ...
@tohagan
tohagan / download.js
Last active November 5, 2021 06:09
Download CSV and PNG
/*
* Copyright 2021 Anthony M. J. O'Hagan
* MIT License
*/
/**
* Convert Quasar QTable rows/columns to CSV format string
* @param {*} columns QTable columns
* @param {*} rows QTable rows
* @returns CSV as a string
@tohagan
tohagan / event.video.youtube.js
Created May 1, 2021 06:09 — forked from benwong/event.video.youtube.js
YouTube iFrame API wrapper for event videos
var EventYouTubeVideo = (function(){
var module = {};
module.init = function(){
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
};
@tohagan
tohagan / searchFocus.vue
Last active March 18, 2021 01:30
Select search box using key stroke
```js
<!-- watch for ctrl-/ - Vue2 only. -->
<div @keyup.ctrl.191="$root.$emit('onSearchFocus')" />
...
<v-text-field ref="search" ... >
...
</v-text-field>
@tohagan
tohagan / Vue: watch $route
Created March 15, 2021 22:46
Vue: Compute slide transition on route change
// then, in the parent component,
// watch the `$route` to determine the transition to use
watch: {
'$route' (to, from) {
const toDepth = to.path.split('/').length
const fromDepth = from.path.split('/').length
this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
}
}
@tohagan
tohagan / index_insert.html
Last active September 28, 2020 08:08
Vue / HTML slow loading warning
<html>
<head>
<style>
#showWarning {
opacity: 0;
animation: cssAnimation 0s 10s forwards;
-moz-animation: cssAnimation 10s; /* Firefox */
-webkit-animation: cssAnimation 10s; /* Safari/Chrome */
-o-animation: cssAnimation 10s; /* Opera */
animation: cssAnimation 10s;
@tohagan
tohagan / QrCode.Vue
Created February 27, 2020 12:54
Fast SVG QR Code for Vue
// Fast and does not need width/height (CSS sizing is more powerful)
// https://github.com/udwarf/qrcode-compact-svg
import { QRCode as QRCodeSvg } from "./qrcode-compact-svg";
export default {
name: "qr-code",
props: {
content: { type: String, required: true }, // URL or text to encode
padding: { type: Number, default: 1 }, // 0 .. 1 padding
color: { type: String, default: "black" }, // Foreground color
@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;
});
@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: