Skip to content

Instantly share code, notes, and snippets.

@beall49
beall49 / GroupAndSumById.java
Last active March 4, 2023 03:10
Group and Sum By Id
private Map<Integer, Integer> getGroupsById() {
List<IdValue> values = Lists.newArrayList(
new IdValue(1, 2),
new IdValue(1, 6),
new IdValue(3, 1),
new IdValue(3, 3),
new IdValue(5, 3),
new IdValue(5, 10)
);
@beall49
beall49 / rename_and_move.py
Last active January 1, 2020 20:50
recursively walk directories and move files to a single output directory
import glob
import os
import shutil
import datetime
import random
import string
FILE_DIR = "P:\\original\\"
OUTPUT_DIR = "P:\\destination\\"
files = []
@beall49
beall49 / ListOfLists.java
Created July 24, 2019 23:44
A list of items that gets a list into a single list :)
/**
* Take a list of items, iterate, and get some list of items then flatten that list of items into a single list.
*/
List<String> indexed = listOfStrings.stream()
.map(li -> li.getSomeListOfItems())
.flatMap(List::stream)
.collect(toList());
/* Module Code */
const reqUtil = require('../utils/request-utils');
const Socket = function(io) {
this.io = io;
this.io.on('connection', s => this.conn(s));
};
Socket.prototype.conn = function(socket) {
console.log(`New Socket connection made ${Date.now()}-${socket.id}`);
/**
* All numbers divisible by 2
*/
const divisibles = (len) => [...Array(len + 1).keys()].filter(k => k % 2 === 0);
/**
* This should spit out a percentage of how close two strings are.
*/
public static Double stringCompare(String a, String b) {
if (a == null || b == null) {
return 0.0;
}
//Same string, no iteration needed.
if (a.equals(b)) {
private static Map<String, List<SomeObject>> groupListToMapById(List<SomeObject> items) {
return items.stream()
.collect(groupingBy(SomeObject::getId, toList()))
.entrySet()
.stream()
.collect(toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(a, b) -> {throw new AssertionError();},
LinkedHashMap::new
const makeSet = (list) => {
return list.reduce((items, item) => {
const id = item.id;
const value = item.value
const found = items.find(i => i.id === id);
if (!found) {
items.push(item);
} else {
found.value += value;
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 () => {
});