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 / range_to_array.md
Last active August 29, 2015 14:10
Turning ranges into arrays.

Say you have a range of integers - 0 thru 100, and you wish to create an Array containing elements [0, 1, 2, … 100], what's the simplest way to do it?

For me the easiest has to be:

var results = []
for (var i = 0, l = 101; i < l; i++) { results.push(i) }

Another approach is to do this:

@davesag
davesag / thingy.yml
Last active August 29, 2015 14:19
Defining a map of arbitrary translation keys in Swagger 2.0
swagger: '2.0'
info:
version: "0.0.1"
title: Localised Thingy demonstration
definitions:
translation:
required:
- default
@davesag
davesag / countries.yml
Created May 4, 2015 01:06
Countries, currencies, dial codes, and subnational divisions
- al:
name: 'Albania'
dial_code: '+355'
currency:
name: Lek
iso: ALL
fractional_unit: Qindarkë
number_to_basic: 100
symbol: 'L'
subnational_divisions:
@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

@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 / 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 / 1.development-norms.md
Last active August 22, 2024 17:58
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 / 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 / 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 / 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'