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 RegisterWithCredentialsForm.tsx
const RegisterWithCredentialsForm: FC<{
disableGoogleRegistration: () => void
enableGoogleRegistration: () => void
}> = ({ disableGoogleRegistration, enableGoogleRegistration }) => {
const [errMsg, setErrMsg] = React.useState("")
const [isRecaptchaRendered, setIsRecaptchaRendered] = React.useState(false)
const { i18n, t } = useTranslation()
const [registerUser] = useRegisterWithCredentialsMutation()
const recaptchaRef = React.useRef<Reaptcha>(null)
const { closeSnackbar } = useSnackbar()
View async-lodash.ts
const _async = require('async');
const _ = require('lodash');
public doSomething = async(num) : Promise<any> => {
return num*num + 1;
public async getResults() {
let results = new Array<any>();
let tasks = [];
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
You can’t perform that action at this time.