Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Alfon alfonmga

I may be slow to respond.
Block or report user

Report or block alfonmga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:567205c671cfbe8071523ce362874dac
Name: Flash
Serial: eNrzzU/OLi0odswsqnHLSSzOqDGoca7JKCkpsNLXLy8v1ytJTczVLUotKNFLzs8FAJHYETc=
if anyone wants to thank ETH: 0x527c2aB55b744D6167dc981576318af96ed26676
Thank you!
View rxjs-with-react.js
// src/Component/Protected/Protected.js
import React, { Component } from 'react';
import { Subject, from } from 'rxjs';
import { filter, flatMap, debounceTime } from 'rxjs/operators';
import Auth0 from '../../Auth/Auth';
class Protected extends Component {
input$ = new Subject();
state = { message: '', user: null };
alfonmga / formWithFormik.js
Created May 12, 2019
Example enhanced form with Formik
View formWithFormik.js
import React from 'react';
import { withFormik } from 'formik';
const MyForm = props => {
const {
alfonmga /
Created May 6, 2019
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

alfonmga / example.js
Created Apr 7, 2019
JavaScript Abstract Factory Pattern
View example.js
class AudioDevice {
constructor () {
this.isPlaying = false;
this.currentTrack = null;
play (track) {
this.currentTrack = track;
this.isPlaying = true;
View mongoose-list-method.js
* 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 })
alfonmga / scheduler.js
Created Mar 12, 2019
JS Interval Scheduler
View scheduler.js
const uuid = require('uuid');
const _idn = (id, name) => `${name}-${id}`;
class IntervalScheduler {
constructor({ log }) {
this._log = log.create('intervalScheduler');
this._jobs = {};
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}
echo "No changes detected"
exit 0
alfonmga / .bashrc
Last active Jan 25, 2019
Lighting Network Full Node aliases
View .bashrc
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'
alfonmga / coinbase-timezones.html
Last active Sep 10, 2019 TZ list
View coinbase-timezones.html
<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>
You can’t perform that action at this time.