Skip to content

Instantly share code, notes, and snippets.

🎯
Create! create! create!

Juni Brosas junibrosas

🎯
Create! create! create!
View GitHub Profile
View husky.js
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": "eslint --cache --fix"
},
/**
View service-worker.js
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
View promise.js
let characterResponse = await fetch('http://swapi.co/api/people/2/')
let characterResponseJson = await characterResponse.json()
let films = await Promise.all(
characterResponseJson.films.map(async filmUrl => {
let filmResponse = await fetch(filmUrl)
return filmResponse.json()
})
)
console.log(films)
@junibrosas
junibrosas / .babelrc
Created Sep 4, 2019
Transpile async await
View .babelrc
{
"presets": [
["@babel/preset-env", {
"modules": false,
"useBuiltIns": "entry",
"targets": {
"browsers": [
"> 0.25%",
"not dead"
],
@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 Nov 22, 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/
**********/
You can’t perform that action at this time.