Skip to content

Instantly share code, notes, and snippets.

const isNotPM2 = (process.env.PM2_HOME === undefined);
if (isNotPM2) {
const fs = require('fs');
const appDir = config.getAppDir();
const pidPath = `${appDir}/pid-backup/node.pid`;
const newPid = process.pid;
const writer = () => {
fs.writeFile(pidPath, newPid, async () => {
});
private void logHandler(String template, Object... parameters) {
String text = EMPTY;
try {
text = String.format(template, parameters);
}
catch (Exception e) {
log.error("logHandler ==> ", e);
}
log.info(text);
}
function getUserName() {
const theme = Liferay.ThemeDisplay;
const payload = {userId: theme.getUserId()};
userName = EMPTY_CHAR;
Liferay.Service(USER_ID_URL, payload)
.done((response) => {
userName = response.screenName;
})
.fail(() => {
userName = EMPTY_CHAR;
const buildingObject = (building) => {
return {
building_number_suggest: [building.alpha, building.number],
building_number_suggest_show: building.alpha,
};
};
const buildingNumbers = require('./building_numbers');
const bulk = buildingNumbers.map(building => buildingObject(building));
const fs = require('fs');
/** building.json
{
"results" = [ {
"attributes": {
"BUILDING": "B041",
.....
}
},
{
"attributes": {
@beall49
beall49 / groupByDate.js
Last active October 18, 2018 05:31
Group buckets by date
/**
* @function groupBucketsByDate
* @desc This takes an array of objects and a date key to group off of.
* It then will group all of the objects by that date key and will a distinct list
* of dates and an array of counts for each date
* @param {Object[]} buckets - An array of date buckets/objects
* @param {string} key - The key to group the items off of
* @param {Object} buckets[].bucket - A single date bucket in the array
* @param {number} bucket.doc_count - The count of items for this particular bucket
* @example const groups = groupBucketsByDate(buckets, 'key_as_string');
class Player {
constructor() {
this.maxHealth = 20;
this.roomLength = 7;
this.hitWall = false;
}
playTurn(warrior) {
warrior.think(`wall: ${this.hitWall}`);
this.warrior = warrior;
class Player {
constructor() {
this.maxHealth = 20;
}
playTurn(warrior) {
this.warrior = warrior;
this.health = warrior.health();
this.takeAction();
}
class Player {
constructor() {
this.maxHealth = 20;
}
playTurn(warrior) {
this.warrior = warrior;
this.health = warrior.health();
this.takeAction();
}
const fizzBuzz = (start, end) => {
const range = [...Array(end).keys()].slice(start, end);
range.forEach(indx => {
if (indx % 15 === 0) {
console.log(`fizzbuzz ${indx}`);
} else if (indx % 5 === 0) {
console.log(`buzz ${indx}`);
} else if (indx % 3 === 0) {
console.log(`fizz ${indx}`);
} else {