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 / last-demo.js
Last active October 20, 2020 15:54
Modify a function so it only resolves the last call
// decorated search function
const search = last(function (query) {
return new Promise(function (resolve, reject) {
setTimeout(() => {
// randomly fail
Math.random() < .25
? reject(new Error('failed for query ' + query))
: resolve(String(query).toUpperCase())
}, Math.random() * 2000)
})
/**
* INSTRUCTIONS
*
* Video at: https://youtube.com/watch?v=AzSDmfDDijQ
*
* 1. copy the code below into a bookmark
* 2. go to https://www.facebook.com/stories/
* 3. click on a story
* 4. hit pause on one you like
* 5. find and run your bookmark
@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')