This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* you'll need to install dotenv */ | |
import * as dotenv from 'dotenv'; | |
import fs from 'fs'; | |
/* where package.json lives */ | |
const root = process.cwd(); | |
const EMPTY = ''; | |
const ZERO = 0; | |
/* Load environment variables from the .env file located at the root directory */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
import shutil | |
import datetime | |
import random | |
import string | |
FILE_DIR = "P:\\original\\" | |
OUTPUT_DIR = "P:\\destination\\" | |
files = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* All numbers divisible by 2 | |
*/ | |
const divisibles = (len) => [...Array(len + 1).keys()].filter(k => k % 2 === 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
NewerOlder