Skip to content

Instantly share code, notes, and snippets.

View davesag's full-sized avatar
:octocat:
Coding

Dave Sag davesag

:octocat:
Coding
View GitHub Profile
@davesag
davesag / Fox.js
Created April 24, 2021 11:10
A React wrapper for the MetaMask Fox logo
/**
* uses the @metamast/logo package to provide the core code.
* sometimes it's a bit sticky.
* The underlying code does a bunch of raw DOM manipulation so makes React a bit funny.
* see https://github.com/MetaMask/logo
*
* use <Fox followMouse slowDrift />
*/
import { useRef, useEffect, useMemo } from 'react'
@davesag
davesag / iMobilePrivacyPolicy.md
Created August 3, 2019 07:31
irMobile Privacy Policy

Privacy Policy for the irMobile app.

Your data is yours.

The app allows you to enter your personal Independent Reserve API Secret and Key and this data is stored locally in your device.

Your key and secret are used exclusively to access your account information via the Independent Reserve API.

That data is never used for anything else.

@davesag
davesag / ir-sockets-demo.html
Last active July 15, 2019 05:56
Realtime Buy and Sell orders on Independent Reserve
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Independent Reserve WebSockets Demo</title>
<script>
const SORTS = {
buy: (a, b) => b - a,
sell: (a, b) => a - b
}
@davesag
davesag / ir-api-example.js
Last active June 20, 2019 06:56
Work out how much the coins you have in Independent Reserve are worth (in $AUD)
// see https://github.com/davesag/ir-api
const ir = require('ir-api')
const WordTable = require('word-table')
// see https://www.independentreserve.com/api
// To generate an API Key, go to the Settings page, click "API Keys" and then click "generate".
// Select the level of access to grant the key and reenter your password to confirm the creation of the key.
// Ensure that you select the lowest level of access required for your usage, the recommended level being Read-only.
const apiKey = 'put-your-api-key-here'
const apiSecret = 'put-your-api-secret-here'
@davesag
davesag / isValid.js
Created May 14, 2019 05:31
Luhn Algorithm for Luhn validation of credit card number
const isValid = card => {
const value = card ? card.replace(/\D/g, "") : ''
if (!value) return false
let nCheck = 0
let bEven = false
for (let n = value.length - 1; n >= 0; n--) {
const cDigit = value.charAt(n)
let nDigit = parseInt(cDigit, 10)
@davesag
davesag / toc.js
Created June 8, 2018 04:01
A simple script to generate table of contents links for GitHub flavoured markdown docs
/**
* A simple script to generate table of contents links for GitHub flavoured markdown docs
*/
const makeAnchor = val => val.trim().toLowerCase().replace(/[^\w\- ]+/g, '').replace(/\s/g, '-').replace(/\-+$/, '')
// paths that end with / need a trailing -
const wrap = val => val.endsWith('/')
? `[\`${val}\`](#${makeAnchor(val)}-)`
: `[\`${val}\`](#${makeAnchor(val)})`
@davesag
davesag / 1.development-norms.md
Last active August 9, 2022 10:28
Development Norms

A common set of development norms

Adhering to a common set of developer norms is a vital factor when a team of people is trying to produce high quality, timely, business critical software.

I'm regularly asked to work on codebases that do not conform to any known measure of coding standards.

Issues include, but are not limited to:

  • no linting
  • no, or few, or inadequate levels of automated testing
@davesag
davesag / CONTRIBUTING.md
Created November 21, 2017 12:06
My standard opinionated CONTRIBUTING file. This goes in every project.

How to contribute to this project

Development Environment

All development is assumed to be done on a Mac running a modern version of OS X but ought to be pretty much the same no matter what unixy environment you use.

Development Process

All development is to follow the standard git-flow process, modified to allow for code-reviews.

@davesag
davesag / testing_js_promises.md
Created July 27, 2016 00:40
Testing Javascript Promises

Here we have a simple class to be tested that returns a Promise based on the results of an external ResponseProcessor that takes time to execute.

For simplicty we'll assume that the processResponse method won't ever fail.

import {processResponse} from '../utils/response_processor';

const ping = () => {
  return new Promise((resolve, _reject) => {
    const response = processResponse(data);
    resolve(response);
@davesag
davesag / transitioning-to-git-flow.md
Created March 7, 2016 05:20
Transitioning to Git Flow — a primer.

Transitioning to git-flow.

Set up GitHub

  1. create a develop branch
  2. in settings => branches choose develop as the default branch and click update
  3. also in settings => branches choose to protect the master branch.

Udate your clone of your fork