Skip to content

Instantly share code, notes, and snippets.

View exwyezed's full-sized avatar
👁️
What you look for is what you find.

Alfon exwyezed

👁️
What you look for is what you find.
View GitHub Profile
@exwyezed
exwyezed / apolloErrorTransformer.js
Last active December 16, 2018 19:53
Transforms Apollo GraphQL errors to human friendly language
export const transformApolloErr = e => {
const err = e;
err.message = err.message.toLowerCase();
const transformedErr = {
message: null,
type: undefined,
data: {},
};
@exwyezed
exwyezed / install-dependencies-monorepo.js
Created December 1, 2018 19:16
We use this to install all dependencies when we have a huge monorepo aka multiple directories with his own package.json
// @flow
const { readdirSync, statSync } = require('fs');
const { join } = require('path');
const { spawn } = require('child_process');
const getDirs = p =>
readdirSync(p).filter(f => statSync(join(p, f)).isDirectory());
// Get a list of all non-build directories in the root folder
const rootDirs = getDirs(join(__dirname, '..')).filter(
@exwyezed
exwyezed / apollo-refreshToken-link.js
Last active September 5, 2023 22:29
Apollo refresh auth token link. It tries to refresh the user access token on the fly when API throws out an UNAUTHENTICATED error. If multiple requests fail at the same time, it queues them to re-try them later if we are able to get a new access token, otherwise we log out the user and redirect him to the login page.
@exwyezed
exwyezed / coinbase-timezones.html
Last active May 29, 2024 05:35
Coinbase.com TZ list
<select name="user[time_zone]" id="user_time_zone">
<option value="American Samoa">(GMT-11:00) American Samoa</option>
<option value="International Date Line West">(GMT-11:00) International Date Line West</option>
<option value="Midway Island">(GMT-11:00) Midway Island</option>
<option value="Hawaii">(GMT-10:00) Hawaii</option>
<option value="Alaska">(GMT-09:00) Alaska</option>
<option value="Pacific Time (US &amp; Canada)">(GMT-08:00) Pacific Time (US &amp; Canada)</option>
<option value="Tijuana">(GMT-08:00) Tijuana</option>
<option value="Arizona">(GMT-07:00) Arizona</option>
<option value="Chihuahua">(GMT-07:00) Chihuahua</option>
@exwyezed
exwyezed / .bashrc
Last active January 25, 2019 17:15
Lighting Network Full Node aliases
alias lndstatus='sudo journalctl -f -u lnd'
alias bitcoindstatus='sudo tail -f /home/bitcoin/.bitcoin/testnet3/debug.log'
alias unlock='lncli unlock'
alias newaddress='lncli --network=testnet newaddress np2wkh'
alias txns='lncli --network=testnet listchaintxns'
alias getinfo='lncli --network=testnet getinfo'
alias walletbalance='lncli --network=testnet walletbalance'
alias peers='lncli --network=testnet listpeers'
alias channels='lncli --network=testnet listchannels'
alias channelbalance='lncli --network=testnet channelbalance'
if git diff --name-only HEAD^...HEAD | grep "^src/${PROJECT}"; then
echo "Changes here, run the build"
npm run test
docker build --tag elasticio/${PROJECT}:${REVISION}
docker push elasticio/${PROJECT}:${REVISION}
else
echo "No changes detected"
exit 0
fi
@exwyezed
exwyezed / scheduler.js
Created March 12, 2019 08:44
JS Interval Scheduler
const uuid = require('uuid');
const _idn = (id, name) => `${name}-${id}`;
class IntervalScheduler {
constructor({ log }) {
this._log = log.create('intervalScheduler');
this._jobs = {};
}
/**
* List users in descending order of 'createdAt' timestamp.
* @param {number} skip - Number of users to be skipped.
* @param {number} limit - Limit number of users to be returned.
* @returns {Promise<User[]>}
*/
list({ skip = 0, limit = 50 } = {}) {
return this.find()
.sort({ createdAt: -1 })
.skip(+skip)
@exwyezed
exwyezed / example.js
Created April 7, 2019 17:45
JavaScript Abstract Factory Pattern
class AudioDevice {
constructor () {
this.isPlaying = false;
this.currentTrack = null;
}
play (track) {
this.currentTrack = track;
this.isPlaying = true;
this.handlePlayCurrentAudioTrack();
@exwyezed
exwyezed / saas-plan-based-volume-limits.md
Created May 6, 2019 23:36
SaaS plan based volume limits example

Plan based volume limits

Checking plan features is pretty neatly handled by a fairly generic way of asserting if a thing is either "on" or "off".

Checking volumes is a bit different. Why is it different? It is different because we need to include the state of specific resources we are offering our customers, not just flags on the account record.

This means you have to actively poll your database and count stuff on each request. Yes, you can cache a bit and being off by one might not be the end of the world.

In the pricing page example above you can see Checkly offers 5 API checks for one plan and 15 for the other. This is how we assert this volume limit in our backend API