Skip to content

Instantly share code, notes, and snippets.

@DJTB
DJTB / deepDiffObj.js
Created August 6, 2020 05:06 — forked from tennox/deepDiffObj.js
Deep diff between two object, using lodash
import _ from 'lodash';
/**
* Deep diff between two objects - i.e. an object with the new value of new & changed fields.
* Removed fields will be set as undefined on the result.
* Only plain objects will be deeply compared (@see _.isPlainObject)
*
* Inspired by: https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-2565071
* This fork: https://gist.github.com/TeNNoX/5125ab5770ba287012316dd62231b764/
*
@DJTB
DJTB / calcNtaDiscountPercentage.ts
Created April 29, 2020 00:20
Calculate discount or premium to NTA for an LIC
/* Calculate whether a LIC is trading at a Premium or Discount */
function calcNtaDiscountPercentage(
lastAsx200: number,
currentAsx200: number,
lastNta: number,
currentPrice: number
) {
const estimatedNta = (currentAsx200 / lastAsx200) * lastNta;
const result = (estimatedNta - currentPrice) / estimatedNta;
return +(result * 100).toFixed(3);
@DJTB
DJTB / useUserReducer.ts
Created May 6, 2019 10:44 — forked from schettino/useUserReducer.ts
Better Reducers with React and Typescript 3.4
import { useReducer } from 'react'
export function updateName(name: string) {
return <const>{
type: 'UPDATE_NAME',
name
}
}
export function addPoints(points: number) {
@DJTB
DJTB / es6-compose.md
Created January 4, 2019 03:39 — forked from JamieMason/es6-compose.md
ES6 JavaScript compose function

ES6 JavaScript Compose Function

Definition

const compose = (...fns) =>
  fns.reduceRight((prevFn, nextFn) =>
    (...args) => nextFn(prevFn(...args)),
    value => value
 );
@DJTB
DJTB / pesticide.js
Created December 12, 2018 21:28
pesticide snippet
((context) => {
// Create the namespace if it's not created yet.
if(!context.PESTICIDE) context.PESTICIDE = {isDebugging: false};
// Color table (tag name and hexadecimal value).
var COLOR_TABLE = {
'body': '#2980b9',
'article': '#3498db',
'nav': '#0088c3',
@DJTB
DJTB / compoundInterest.js
Last active December 8, 2018 01:47
compound-interest
function calc (P, PMT, r, n, t) {
const rn = (r / 100) / n
const nt = n * t
const pn = 12 / n
const principal = P * Math.pow(1 + rn, nt)
const series = PMT * (pn * (Math.pow(1 + rn, nt) - 1) / rn)
return parseInt(principal + series, 10)
}
module.exports = opts => {
@DJTB
DJTB / _essential-button-baseline.css
Created May 11, 2018 00:09
button/link reset styles
/**
* Focus styles should show up when using the tab key, but not when clicking the link or button.
* You should have :focus-visible polyfill until it gains wider browser support.
* https://github.com/WICG/focus-visible
*/
/**
* Reset button styles
* It takes some work to achieve a “blank slate” look.
*/
@DJTB
DJTB / essential_vocab.md
Last active March 10, 2017 12:39
Essential Vocab for a New Language

Essential Vocab for Language Learning

This is a personalised list originally based on 625 common words

Discarded words such as "newspaper" and "cake" since they're not important to my life and probably won't come up often (or if someone is asking about them, I'm probably not that interested anyway).
Discarded American-centric words (inch, foot, pound). Added important words that were missing (i.e. near, far, next, previous).
Added extra food words.

actor
adjective

@DJTB
DJTB / http_notes.md
Last active March 8, 2017 20:46
HTTP Notes

HTTP Notes

Status Codes

2xx - success
200 - served!
201 - ok, created new resource (includes location header)
202 - ok, but not yet complete/in process (a long(ish) process -> github fork)
204 - yes, but no other relevant content to be returned
206 - yes, but partial response (binary content like images, includes content-range header of which bytes were returned)