Skip to content

Instantly share code, notes, and snippets.

@prodrammer
prodrammer / main.js
Created October 15, 2021 05:43
Coin problem
const calc = (coins, value) => {
return coins.reduce((acc, coin) => {
while (acc.balance >= coin) {
if (!acc.result[coin]) acc.result[coin] = 0;
acc.result[coin]++;
acc.balance -= coin;
}
return acc;
}, { balance: value, result: {}});
}
@prodrammer
prodrammer / server.js
Last active January 8, 2020 01:08
Custom static file server + reverse proxy with clean HTML5 SPA routing support.
const fs = require('fs')
const url = require('url')
const path = require('path')
const http = require('http')
const static = require('node-static')
const httpProxy = require('http-proxy')
const file = new static.Server('./', { cache: 0 })
const proxy = httpProxy.createProxyServer({})
@prodrammer
prodrammer / machine.js
Last active October 30, 2019 07:54
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@prodrammer
prodrammer / commands.js
Last active March 16, 2020 16:47
vuedraggable / sortablejs support files for cypress.io
/// <reference types="Cypress" />
import draggable from './draggable'
// drag and drop a source element to a target selector, anchoring the drop to the given
// position of the selector. positions are the same as the cypress trigger command
Cypress.Commands.add('drop', { prevSubject: 'element' }, ($source, selector, position) => {
cy.get(selector).then($target => {
const source = $source[0]
const target = $target[0]
draggable(source, target, position)
@prodrammer
prodrammer / Zoom_Debigulator.scpt
Last active September 6, 2018 23:59
Changes resolution when sharing during a ZOOM.us meeting.
on main()
set hugeMonitor to "LG ULTRAWIDE" -- set to name shown at top of displays system prefs applet
set debigulateIndex to 2 -- set to 1-based index of preferred "scaled" size from displays system prefs applet
set debigulateWidth to 2560 -- set to width of preferred "scaled" size from displays system prefs applet
set debigulateHeight to 1100 -- set to height of preferred "scaled" size from displays system prefs applet
set embiggenWidth to 3840 -- set to width of "default for display" size from displays system prefs applet
set embiggenHeight to 1600 -- set to height of "default for display" size from displays system prefs applet
tell current application
tell application "System Events"
repeat while true
@prodrammer
prodrammer / PlainClipboard.js
Created July 10, 2018 00:03
Example enforcing plain text paste in Quill.
import Quill from 'quill'
const Clipboard = Quill.import('modules/clipboard')
const Delta = Quill.import('delta')
class PlainClipboard extends Clipboard {
onPaste (e) {
e.preventDefault()
const range = this.quill.getSelection()
const text = e.clipboardData.getData('text/plain')
const delta = new Delta()
@prodrammer
prodrammer / cypress-plugins-index.js
Last active April 7, 2021 18:41
Configure cypress.io using dotenv-extended, and getenv
// ***********************************************************
// https://on.cypress.io/plugins-guide
// ***********************************************************
const dotenv = require('dotenv-extended')
const getenv = require('getenv')
dotenv.load()
const overrideBaseUrl = () => {
let baseUrl = getenv.string('CYPRESS_BASE_URL', '')
@prodrammer
prodrammer / A QuillJS No-Focus Placeholder Example.markdown
Last active April 15, 2018 03:08
QuillJS No-focus Placeholder Example