Skip to content

Instantly share code, notes, and snippets.

View _nav_tabs.html.erb
<header class="row mb-3">
<div class="col-sm-12 col-md-6 text-primary">
<h2 class="mb-0 <%= level == 1 ? 'font-weight-bold' : ''%>"><%= title %></h2>
</div>
<ul class="nav nav-tabs justify-content-end col-sm-6 col-md-6 mt-2">
<% tabs.each do |tab| %>
<li class="nav-item">
<%= link_to tab[:label], tab[:path],
class: "nav-link #{(active == tab[:key] ? ' active font-weight-bold' : '')}"
%>
@tohagan
tohagan / herokuconfig.sh
Last active Nov 27, 2021
Read .env format file from stdtin and sets environment on Heroku app
View herokuconfig.sh
#!/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 Aug 21, 2021
Remove Windows paths from WSL
View RemoveWindowsPathsWsl.md

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 Nov 5, 2021
Download CSV and PNG
View download.js
/*
* 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 — forked from benwong/event.video.youtube.js
YouTube iFrame API wrapper for event videos
View event.video.youtube.js
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 Mar 18, 2021
Select search box using key stroke
View searchFocus.vue
```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 Mar 15, 2021
Vue: Compute slide transition on route change
View Vue: watch $route
// 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 Sep 28, 2020
Vue / HTML slow loading warning
View index_insert.html
<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 Feb 27, 2020
Fast SVG QR Code for Vue
View QrCode.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 Jan 18, 2020
JavaScript - Expand variables in string
View expandVars.js
// 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;
});