Skip to content

Instantly share code, notes, and snippets.

View matthewblewitt's full-sized avatar

Matt Blewitt matthewblewitt

View GitHub Profile
@matthewblewitt
matthewblewitt / calc.ts
Last active October 26, 2023 14:52
Income tax calc
type Brackets = {
min: number;
max: number;
rate: number;
}[];
export const calculateIncomeTax = (salary: number, brackets: Brackets) => {
return brackets.reduce<number>((acc, b) => {
if (salary > b.min) {
const taxableAmount = Math.min(salary, b.max) - b.min;
@matthewblewitt
matthewblewitt / test.ts
Created October 19, 2023 11:16
Excercise
/**
*
Unreliable Webhook
There's a webhook that's calling webhookHandle that is unreliable.
It is possible that after it receives a paid status, it triggers a failed or paid one.
possible cases =>
- pending → submitted → paid
- pending → submitted → failed
- pending → submitted → paid → paid
@matthewblewitt
matthewblewitt / jest-mock-dates.md
Last active July 23, 2020 14:36
Jest mock cheet sheet

dates

describe("mock global date", ()=> {
  beforeEach(async () => {
    global.Date.now = jest.fn(() => new Date("2020-01-01T12:00:00Z").getTime());
  });
  afterAll(() => {
    global.Date.now = RealDate;
 });
@matthewblewitt
matthewblewitt / slot.js
Created July 16, 2020 16:34
Vue - Watch for slot content changes
<script>
export default {
data() {
return {
hasSlotContent: false,
}
},
methods: {
checkForSlotContent() {
let checkForContent = (hasContent, node) => {
@matthewblewitt
matthewblewitt / es6-export-import.md
Created July 10, 2020 11:27
ES6 Export Import shorthand

Default export as Default:

export { default } from './something';

Default export as Named:

export { default as foo } from './something';

Named export as Default:

// Axios.prototype cannot be modified
const axiosExtra = {
setBaseURL (baseURL) {
this.defaults.baseURL = baseURL
},
setHeader (name, value, scopes = 'common') {
for (let scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
if (!value) {
delete this.defaults.headers[scope][name];
return
@matthewblewitt
matthewblewitt / generator.js
Created December 7, 2019 11:43
SVG symbols generator
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var dom = require('cheerio')
var args = process.argv.slice(2)
var $ = dom.load(
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0" style="display:none;"></svg>',
{ xmlMode: true }
)
var dir
@matthewblewitt
matthewblewitt / .eslintrc.js
Created December 3, 2019 11:39
Vue CLI + ESLint + Prettier + Fix on save
module.exports = {
root: true,
env: {
node: true
},
extends: [
"plugin:vue/recommended",
"eslint:recommended",
"prettier/vue",
"plugin:prettier/recommended"
@matthewblewitt
matthewblewitt / style.css
Created September 5, 2019 07:30
CSS Outline
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }
@matthewblewitt
matthewblewitt / vue-util.js
Last active August 20, 2019 10:15
Vue util cheat sheet
import { mount, createLocalVue } from "vue-test-utils";
import { actions, mutations } from "~/test/mocks/store-actions-mutations.mock";
import Component from "~/pages/index.vue";
import Vuex from "vuex";
const localVue = createLocalVue();
localVue.use(Vuex);
const store = new Vuex.Store({ state, mutations, actions });
const cmp = mount(Component, {
store,