Skip to content

Instantly share code, notes, and snippets.

View hawkeye64's full-sized avatar

Jeff Galbraith hawkeye64

View GitHub Profile
// -----------------------------------------------
// eslint-plugin.js - put into plugins folder
// see below for usage
// -----------------------------------------------
const path = require('path')
const fs = require('fs').promises
const ESLint = require('eslint').ESLint
const cwd = process.cwd()
const eslint = new ESLint({ cwd })
@hawkeye64
hawkeye64 / Vite Import Blobs.txt
Created January 10, 2021 18:34
Vite v2.0.0-beta.19 import.meta.glob usage
// The main use-case for the code below is to be able to test
// components in isolation of various properties and functionality
// -------------------------------------------------------
// children.js
// The code below (children.js) imports all files from 'src/pages' folder
// It will exclude any index file (ie: index.js, Index.vue, etc)
// Look below for usage...
const modules = import.meta.glob('../pages/*.vue')
@hawkeye64
hawkeye64 / Quasar and Tailwind CSS
Created October 19, 2020 19:32
Quasar and Tailwind CSS
timsayshey commented on 21 Jul •
We came up with a workaround on our team to get Quasar and Tailwind to work together. Our goal was to build everything in Tailwind on Quasar but we didn't want Quasar styles loading in and taking over or conflicting with our Tailwind styles. The first thing we had to do was prevent the Quasar stylesheet from loading in however there is no option to disable it so we do a find/replace to remove it when webpack builds.
Run npm i string-replace-loader then add the following code to the extendWebpack() method in your quasar.conf.js file:
cfg.module.rules.push({
test: /client-entry\.js$/,
loader: 'string-replace-loader',
options: {
search: "import 'quasar/dist/quasar.sass'",
@hawkeye64
hawkeye64 / format.js
Created October 18, 2020 20:53
Formatted output like: print("Hello, {0}! The answer is {1}.", "World", 42);
function format(fmt, ...args) {
if (!fmt.match(/^(?:(?:(?:[^{}]|(?:\{\{)|(?:\}\}))+)|(?:\{[0-9]+\}))+$/)) {
throw new Error('invalid format string.');
}
return fmt.replace(/((?:[^{}]|(?:\{\{)|(?:\}\}))+)|(?:\{([0-9]+)\})/g, (m, str, index) => {
if (str) {
return str.replace(/(?:{{)|(?:}})/g, m => m[0]);
} else {
if (index >= args.length) {
throw new Error('argument index is out of range in format');
@hawkeye64
hawkeye64 / loadComponents.js
Created December 23, 2019 14:27
Dynamically load Vue components from a folder
export default ({ Vue }) => {
const examples = require('../assets/examples').default
for (const index in examples) {
import(
/* webpackChunkName: "examples" */
/* webpackMode: "lazy-once" */
`../examples/${examples[index].file}.vue`
).then(comp => {
Vue.component(examples[index].file, comp.default)
})
@hawkeye64
hawkeye64 / launch.json
Created August 24, 2019 23:23
launch.json for vscode
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
@hawkeye64
hawkeye64 / setViewport
Created August 3, 2019 17:00
dynamically set meta based on screen width
//sweet hack to set meta viewport for desktop sites squeezing down to mobile that are big and have a fixed width
//first see if they have window.screen.width avail
(function() {
if (window.screen.width)
{
var setViewport = {
//smaller devices
phone: 'width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no',
//bigger ones, be sure to set width to the needed and likely hardcoded width of your site at large breakpoints
other: 'width=1045,user-scalable=yes',
@hawkeye64
hawkeye64 / css_colors.js
Created July 15, 2019 16:13 — forked from bobspace/css_colors.js
All of the CSS Color names as an array in javascript.
// CSS Color Names
// Compiled by @bobspace.
//
// A javascript array containing all of the color names listed in the CSS Spec.
// The full list can be found here: http://www.w3schools.com/cssref/css_colornames.asp
// Use it as you please, 'cuz you can't, like, own a color, man.
var CSS_COLOR_NAMES = ["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","Darkorange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory"
function getRegexForDateFromat(dateFormat) {
var dateValueRegexString =
dateFormat.replace(/MM|M|DD|D|YYYY/g, function(match, position, original) {
switch (match) {
case "M":
return "([1-9]||1[0-1])";
break;
case "MM":
return "(0[1-9]||1[0-1])";
break;
@hawkeye64
hawkeye64 / dateTimeParser.js
Created June 1, 2019 17:29
Date/Time Parser (javascript)
const parse = (input: string, format: string, key: string): string => {
const index = format.indexOf(key);
return input.slice(index, index + key.length);
};
export const dateParse = (input: string, format: string = 'YYYY-MM-DD HH.mm.ss', { epoch = 2000 } = {}): Date => {
let year = 2000;
if (format.includes('YYYY')) {
year = parseInt(parse(input, format, 'YYYY'), 10);