Skip to content

Instantly share code, notes, and snippets.

View davestewart's full-sized avatar
⚙️
Workin' on Chrome extensions!

Dave Stewart davestewart

⚙️
Workin' on Chrome extensions!
View GitHub Profile
@davestewart
davestewart / decorators.ts
Last active May 12, 2020 13:09
TypeScript decorator to add Vue computed getters to a TypeScript class
import Vue from 'vue'
export function cached (target: Function) {
// get descriptors
const descriptors: any = Object.getOwnPropertyDescriptors(target.prototype)
const getters = Object
.keys(descriptors)
.filter(key => descriptors[key].get && !descriptors[key].set)
// we have getters!
@davestewart
davestewart / git extract feature with history.md
Last active April 25, 2020 21:24
Git: Extract feature to new repo, retaining history

Git: Extract a feature to a new repo, retaining history

Abstract

I recently needed to extract a feature from a project to its own repo so I could publish as a standalone library:

# from
/some-project/src/some-folder/some-feature/*
@davestewart
davestewart / mixcloud.css
Created April 3, 2020 08:41
Mixcloud vertical playlist
body {
padding-left: 400px;
}
div[class^=RebrandPlayerQueueItem__QueueItem] {
width: 400px;
}
div.player-height-placeholder div[class^=playerQueue__UpNextArea] {
z-index: 1000 !important;
@davestewart
davestewart / helpers.js
Last active November 26, 2019 04:31
Vue "route helpers" example
/**
* Helper function to reduce boilerplate in route creation
*
* @param {string} path The route's path
* @param {object} page A page component definition
* @param {Function} page A function that returns a page import
* @param {string} page A string path to a file in the view/pages folder
* @param {object} attrs Any additional attributes
*/
export function route (path, page, attrs = {}) {
@davestewart
davestewart / table-factory-hooks.js
Created October 3, 2019 09:46
Handsontable hooks
cells (row, col, name) {
if (!this.hot) {
return null
}
const rowData = this.hot.getSourceDataAtRow(row)
if (rowData) {
if (rowData.state === NegotiationItemState.removed) {
return { readOnly: true }
}
@davestewart
davestewart / workflowy x 2.js
Last active February 20, 2024 16:25
WorkFlowy x 2 - a browser bookmarklet to give you a dual panel WorkFlowy view
javascript:
`
WorkFlowy x 2
=============
- A browser Bookmarklet to give you a dual panel WorkFlowy view
Features / Usage:
// collection.js
export function forEach (arr, callback) { ... }
export function map (arr, callback) { ... }
export function get (arr, id, key = 'id') { ... }
export function getIndex (arr, id, key = 'id') { ... }
export function add (arr, item, index = -1) { ... }
export function update (arr, id, values) { ... }
export function move (fromArr, id, toIndex, toArr = fromArr) { ... }
export function moveByIndex (fromArr, fromIndex, toIndex, toArr = fromArr) { ... }
export function remove (arr, id) { ... }
@davestewart
davestewart / ga.js
Created July 8, 2018 19:27
Google Analytics - single file include
(function track (id) {
// prepare data
window.dataLayer = window.dataLayer || []
function gtag () { dataLayer.push(arguments) }
gtag('js', new Date())
gtag('config', id)
// load analytics
var script = document.createElement('script')
@davestewart
davestewart / App.vue
Created March 19, 2018 22:36
Vue provide inject example for customisable icons
<template>
<ui-icon name="notes" />
<ui-icon name="book" />
<ui-icon name="map" />
</template>
@davestewart
davestewart / AddressForm.vue
Created November 13, 2017 16:41
Trifecta of Parent, Child and Layout components for reusable Form family
<template>
<ui-form name="address">
<div class="fields">
<ui-input
name="house_no"
label="House name / no"
:value.sync="values.house_no"