Skip to content

Instantly share code, notes, and snippets.

🎯
Create! create! create!

Juni Brosas junibrosas

🎯
Create! create! create!
Block or report user

Report or block junibrosas

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
@junibrosas
junibrosas / lookup.js
Last active Jul 16, 2019
MongoDB Aggregation
View lookup.js
export const populateUserActions = (userCuid, period = { from: new Date(), to: null }) => {
const aggregation = [
{ $match: { 'cuid': userCuid }},
{ $lookup: CompanyLookup },
{ $lookup: FundraisingLookup },
{ $lookup: MissionLookup },
{ $lookup: CreatedExperienceLookup },
{ $lookup: SubscribedExperienceLookup },
{ $project: {
...simpleUserProjection,
@junibrosas
junibrosas / crud.js
Created May 13, 2019
Mongoose CRUD sample codes
View crud.js
// Find one and remove entity afterwards
Charity.findOne({ cuid: userCuid });
.exec()
.then(entity => {
if (!entity) res.status(404).end();
else {
entity.remove()
.then(() => res.status(204).end());
}
});
@junibrosas
junibrosas / moment.js
Last active Jul 11, 2019
Anything momentJS
View moment.js
// 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 Apr 22, 2019 — forked from StarpTech/redis-cache-service.js
Simple Redis Cache Client for Node.js
View redis-cache-service.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 Apr 22, 2019
Next.js with polyfills
View next.config.js
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 Apr 17, 2019 — forked from glemiere/server.js
Simple file written in ES6 to serve a ExpressJS/NextJS Server.
View server.js
/**********
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 Mar 26, 2019
Proper typings of react-redux connected components
View react-redux-typings.ts
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 Feb 5, 2019
These are snippet compilation about scenarios using RxJS
View timeout-http.js
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 Feb 5, 2019
Gibberish Snippets
View node-question.js
// 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 Jan 9, 2019
Sample AngularJS Component
View contactBar.component.js
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
You can’t perform that action at this time.