Skip to content

Instantly share code, notes, and snippets.

View AkimaLunar's full-sized avatar

Aaron Carmin AkimaLunar

  • Vancouver Island, BC
  • 02:54 (UTC -07:00)
View GitHub Profile
@AkimaLunar
AkimaLunar / CurrencyCodes.ts
Last active November 9, 2020 19:43
Currency codes in TypeScipt
/**
* Generated from Current currency & funds code list by SNV.
* @see https://www.currency-iso.org/en/home/tables/table-a1.html
*/
type CurrencyCode =
| "AFN"
| "EUR"
| "ALL"
| "DZD"
@AkimaLunar
AkimaLunar / arrayGenerator.js
Last active November 29, 2021 22:48
Large array generator
const fs = require('fs')
const createArray = ({ length }) => Array.from({ length }, (_, i) => i + 1); // [1, 2, 3, ...]
const createLargeArray = (length = 100) => (
Array.from(Array(length)).map(() => Math.random() * 10)
)
const string = `module.exports = [${[...createLargeArray(), 122]}]`
fs.writeFile('largeArray.js', string, (error => {
@AkimaLunar
AkimaLunar / Colors.js
Created October 27, 2018 17:39
Color helpers
export const HEX_RANGE = /#?([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/
export const RGB_RANGE = /rgba?\(\b([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\b,\s?\b([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\b,\s?\b([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\b,?\s?([01]|0\.\d*)?\)/
export const HSL_RANGE = /hsla?\((\b[0-9]|[1-8][0-9]|9[0-9]|[12][0-9]{2}|3[0-5][0-9]|360\b),\s?(\b[0-9]|[1-8][0-9]|9[0-9]|100\b)%,\s?(\b[0-9]|[1-8][0-9]|9[0-9]|100\b)%,?\s?([01]|0\.\d*)?\)/
export const isHEX = color => color && color.match(HEX_RANGE) // ["#ff66ff", "ff", "66", "ff"] | null
export const isRGB = color => color && color.match(RGB_RANGE) // ["rgba(255, 10, 110, 0.75)", "255", "10", "110", "0.75"] | null
export const isHSL = color => color && color.match(HSL_RANGE) // ["hsla(160,10%,10%)", "160", "10", "10", "0.75"] | null
/**
* Converts a RGBa or HSLa into HEX
@AkimaLunar
AkimaLunar / compose.js
Created March 9, 2018 19:44
Compose takes in functions as arguments and returns a single function
const compose = (...fns) => // 1. the spread operator torns function arguments into an array fns
(arg) => // 2. a function is then returned that expects one argument arg
fns.reduce( // 3. Reducing the fins with arg as the initial value
(composed, f) => f(composed), // 4. Each function is called with the result of the previous functions
arg // 3.arg is the initial value
)
@AkimaLunar
AkimaLunar / server-worker.js
Created March 9, 2018 18:20
Service worker registration
// main.js
if (!('serviceWorker' in navigator)) {
console.log('sw not supported');
return;
}
navigator.serviceWorker.register('/path/to/service-worker.js') // returns a Promise
.then(function(registration) {
console.log('SW registered! Scope is: ', registration.scope);
});
@AkimaLunar
AkimaLunar / Dockerfile
Created September 24, 2017 01:59
Node.js 8 and NPM 5 on Ubuntu 16.04 Xenial Dockerfile
# Use an official Ubuntu Xenial as a parent image
FROM ubuntu:16.04
# Install Node.js 8 and npm 5
RUN apt-get update
RUN apt-get -qq update
RUN apt-get install -y build-essential
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get install -y nodejs
@AkimaLunar
AkimaLunar / react-redux-drills.md
Created August 17, 2017 23:41
React Redux drills
@AkimaLunar
AkimaLunar / action-reducer-and-store-drills.md
Last active August 14, 2017 23:41
Action, reducer and store drills
@AkimaLunar
AkimaLunar / react-component-communication-drills.md
Last active July 29, 2017 01:13
React component communication drills