Skip to content

Instantly share code, notes, and snippets.

View aarongeorge's full-sized avatar
🤖

ADG aarongeorge

🤖
View GitHub Profile
@aarongeorge
aarongeorge / primeNumbers.js
Last active April 30, 2020 11:24
Interview question to find all prime numbers between 0 and 100
// The definition of a prime number is a positive integer that has exactly two positive divisors (This means the divisors could only ever be 1 and the number itself)
// Given that's the case, 0 can't be a prime as you can't divide 0 by 0. Just as 1 can't be prime as 1 divided by 1 is using the same divisor.
// This means any time we want to loop to find a prime, we can ignore 0 and 1 and start at 2
// So given the definition of a prime we can write a function like this to check if a number is prime
const isPrime = n => {
for (let i = 2; i < n; i++)
if (!(n % i)) return !!0
return n > 1
}
@aarongeorge
aarongeorge / createAudioContext.js
Last active April 6, 2020 01:43
A function that will create an audio context that bypasses the iOS sample rate mismatch bug
/**
* A function that will create an audio context that fixes
* the iOS sample rate mismatch bug
*
* Author: Aaron George https://github.com/aarongeorge
*/
// Create Audio Context
const createAudioContext = (desiredSampleRate = 44100) => {
@aarongeorge
aarongeorge / invisible-code-generator.js
Last active April 6, 2020 00:54
A code generator that takes Javascript and compiles it to ASCII Control Characters that are not visible, based on Martin Kleppe's "Invisible Code" talk
/**
* Invisible Code Generator
*
* Description:
* A code generator that takes Javascript and compiles it to
* ASCII Control Characters that are not visible
*
* Usage:
* Copy and paste the code into your browsers console
* Then paste the code you wish to convert to "Invisible Code"
@aarongeorge
aarongeorge / modifyDate.ts
Last active April 6, 2020 00:42
Modify JavaScript Date - Add and/or Subtract Years, Months, Weeks, Days, Hours, Minutes, Seconds and Milliseconds
const modifyDate = (date: Date, options: {[key in 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds']?: number} = {}) => {
const modifiedDate = new Date(date)
if (options.years) modifiedDate.setFullYear(modifiedDate.getFullYear() + options.years)
if (options.months) modifiedDate.setMonth(modifiedDate.getMonth() + options.months)
if (options.weeks) modifiedDate.setDate(modifiedDate.getDate() + options.weeks * 7)
if (options.days) modifiedDate.setDate(modifiedDate.getDate() + options.days)
if (options.hours) modifiedDate.setHours(modifiedDate.getHours() + options.hours)
if (options.minutes) modifiedDate.setMinutes(modifiedDate.getMinutes() + options.minutes)
if (options.seconds) modifiedDate.setSeconds(modifiedDate.getSeconds() + options.seconds)
@aarongeorge
aarongeorge / JWTPayloadExample.js
Last active November 2, 2019 08:13
Example of a JWT Payload with all Registered Claims
const timeNow = new Date()
const payload = {
iss: 'http://backend.com', // Issuer - Identifier of who provided this JWT
sub: 'uniqueIdOfUser', // Subject - Who is supposed to be using this JWT (The value should mean something for `aud`)
aud: ['http://frontend.com', 'http://backend.com'], // Audience - Who should be consuming this JWT
exp: new Date(new Date(timeNow).setDate(timeNow.getDate() + 7).getTime(), // Expiration Time - When this JWT should no longer be accepted by the `aud`
nbf: timeNow.getTime(), // Not Before - When this JWT should start being accepted by the `aud`
iat: timeNow.getTime(), // Issued At - When this JWT was issued
jti: 'uniqueIdForThisJWT' // JWT ID - Unique ID that the `aud` can use to blacklist/whitelist the JWT even if `exp` and `nbf` requirements are met
@aarongeorge
aarongeorge / RangeGrouping.js
Created August 28, 2019 01:59
Given an array of ranges, group overlapping ranges in an array and return an array of the groups
const ranges = [
{
'start': 6,
'end': 8
},
{
'start': 3,
'end': 6
},
{
@aarongeorge
aarongeorge / .eslintrc.js
Created April 17, 2019 12:53
My eslint configuration file
module.exports = {
'env': {
'browser': true,
'es6': true,
'node': true
},
'parserOptions': {
'allowImportExportEverywhere': false,
'babelOptions': {
'configFile': './babel.config.js'
--- Input ---
Game: CS
DPI: 400
Resolution: 3440x1440
Sensitivity: 4
360 Distance: 10.2273 inches
--- Calculated ---
{
"rules": {
"at-rule-blacklist": [],
"at-rule-empty-line-before": [
"always",
{
"except": [
"after-same-name",
"first-nested"
],
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>HTML5 Blank Page</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Styles -->