Skip to content

Instantly share code, notes, and snippets.

View junibrosas's full-sized avatar
🎯
Create! create! create!

Juni Brosas junibrosas

🎯
Create! create! create!
View GitHub Profile
@junibrosas
junibrosas / moment.js
Last active November 22, 2019 08:21
Anything momentJS
// a few seconds ago
moment.fn.fromNowOrNow = function (a) {
if (Math.abs(moment().diff(this)) < 25000) { // 25 seconds before or after now
return 'just now';
}
return this.fromNow(a);
}
// check expiry
const isExpired = moment().isAfter(activity.endDate);
@junibrosas
junibrosas / redis-cache-service.js
Created April 22, 2019 11:01 — forked from StarpTech/redis-cache-service.js
Simple Redis Cache Client for Node.js
'use strict';
const assert = require('assert');
/**
* The redis client is https://github.com/luin/ioredis
*/
/*
const redisClient = new Redis({
@junibrosas
junibrosas / next.config.js
Created April 22, 2019 05:19
Next.js with polyfills
module.exports = {
webpack: function (cfg) {
const originalEntry = cfg.entry
cfg.entry = async () => {
const entries = await originalEntry()
if (
entries['main.js'] &&
!entries['main.js'].includes('./client/polyfills.js')
) {
@junibrosas
junibrosas / server.js
Created April 17, 2019 06:16 — forked from glemiere/server.js
Simple file written in ES6 to serve a ExpressJS/NextJS Server.
/**********
server.ts
---------------
Simple file written in ES6 to serve a ExpressJS/NextJS Server.
Uses SSL, Compression, redirection and service worker routing. See server config file at :
https://github.com/glemiere/nextjs-starter/tree/master/config
---------------
Requires Let's Encrypt SSL Certificate :
https://letsencrypt.org/
**********/
@junibrosas
junibrosas / react-redux-typings.ts
Last active March 26, 2019 10:54
Proper typings of react-redux connected components
import * as React from 'react'
import * as Redux from 'redux'
import { MyReduxState } from './my-root-reducer.ts'
export interface OwnProps {
propFromParent: number
}
interface StateProps {
@junibrosas
junibrosas / timeout-http.js
Created February 5, 2019 05:57
These are snippet compilation about scenarios using RxJS
import { throwError as observableThrowError, from as observableFrom, Observable, TimeoutError, of } from 'rxjs';
import { mergeMap, catchError, timeout, retryWhen, concatMap } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { EntityService } from '../entity/entity.service';
import { UserService } from '../../promoter/legacy/_common/services/user-service/user.service';
import rmaProperties from '../../../rmaProperties';
@junibrosas
junibrosas / node-question.js
Last active February 5, 2019 05:47
Gibberish Snippets
// match regex yes
rl.question('Are you sure you want to download reference pictures? (y(es))', async (answer) => {
if (answer.match(/^y(es)?$/i)) {
await downloadNewRefPics(newRefPicsList);
}
rl.close();
});
@junibrosas
junibrosas / contactBar.component.js
Last active January 9, 2019 09:40
Sample AngularJS Component
import { ContactBarController } from './contactBar.controller';
angular.module('RateMyAgent.Common').component('rmaContactBar', {
templateUrl: '/templates/_common/contact-bar/contactBar.html',
bindings: {
agent: '<',
buttonLocation: '<'
},
controllerAs: '$ctrl',
controller: ContactBarController
@junibrosas
junibrosas / angularjs-bare-component.spec.js
Last active February 5, 2019 05:49
AngularJS unit testing snippet compilation
// This is only a code snippet and should only provide a guide of testing scenarios.
describe('rmaLeasingLocationAwards', () => {
let $q;
let $componentController;
let $rootScope;
let controller;
beforeEach(() => {
angular.mock.module('RateMyAgent.Profiles.Locations.Leasing');
@junibrosas
junibrosas / email.directive.ts
Created March 5, 2018 09:34
Angular 5 Registration Form using FormsModule
import {
ReactiveFormsModule,
NG_VALIDATORS,
FormsModule,
FormGroup,
FormControl,
ValidatorFn,
Validator
} from '@angular/forms';
import { Directive } from '@angular/core';