Skip to content

Instantly share code, notes, and snippets.

@leppaott
leppaott / rand.clj
Created August 27, 2018 18:14
Generate random names in format of {consonant vowel{1,2}}+
(defn rand-name []
(let [v [\a \e \i \o \u \y]
c [\h \j \k \l \m \n \p \r \s \t \v]
get-v #(v (rand-int (count v)))
get-c #(c (rand-int (count c)))]
(loop [s ""]
(let [len (count s) c_char (get-c) v_char (get-v)
double-v? (= 1 (rand-int 5))]
(if (or (>= len 10) (and (>= len 4) (= 1 (rand-int 2))))
(capitalize s)
const dropLeadingWeeks = (weeks) => {
let i = weeks.length;
for (;i != 0; i--) {
const week = weeks[i - 1];
if (week.totalPoints != 0) break;
}
return weeks.slice(0, i);
};
@leppaott
leppaott / resolve-data-changes.js
Created January 20, 2018 04:56
Merging state changes functionally
/**
* @param {string} propName New property name for target
* @param {Object} target Target object
* @param {Object} changes Modified properties of target
* @param {Object} restOfProps
* @return {Promise} resolve({propName: {target}, ...restOfProps})
*/
function _mergePropChanges(propName, target, changes, ...restOfProps) {
return Promise.resolve(Object.assign({
[propName]: Object.assign(target, changes)