View array_objects_statistics.js
var arrayObjectStatistics = function(arr) {
var keys=[];
arr.forEach(a => Object.keys(a).forEach(k => keys.push(a[k])))
var stats=[...keys.reduce( (m, v) => m.set(v, (m.get(v) || 0) + 1), new Map() )].sort((a,b) => b[1]-a[1])
stats=stats.map(c => new Object({label: c[0], count: c[1], mean: parseInt(c[1])/arr.length}) )
return stats;
}
View map_reduce.js
var survey=[["Active","Chill Out","Cozy","Dancebale","Dark","Energetic","Feel Good","Funky","Happy","Motivating","Party","Warm","Youthful","Athletic","Dramatic","Joyous","Provocative","Rowdy","Spicy","Stylish","Sweet","Aggressive","Atmospheric","Gloomy","Introspective","Sprightly","Seductive","Sensual","Groovy","Sweet","Hypnotic","Optimistic","Active"],["Driving","Happy","Motivating","Warm","Cosmopolitan","Dramatic","Joyous","Provocative","Stylish","Aggressive","Angry","Gloomy","Introspective","Melancholic","Intimate","Optimistic","Reflective","Romantic","Sophisticated","Thrilling","Celebratory","Exciting","Erotic","Enigmatic","Exotic","Ironic","Irreverent","Apocalyptic","Funereal","Austere","Dreamy","Declamatory","Nostalgic","Passionate","Tragic","Trashy","Heroic","Majestic","Naive","Powerful","Mystical","Cheerful","Rebellious"],["Dark","Feel Good","Happy","Motivating","Youthful","Bravado","Dramatic","Joyous","Provocative","Triumphant","Aggressive","Angry","Introspective","Melancholic","Intimate","Optimistic
View wc_file_list.sh
#!/bin/bash
find $1 -maxdepth 1 -type f -print0 | xargs -0 wc | awk '{print $1 "\t" $4}'
View fasttext_confusion_matrix.py
#!/usr/local/bin/python3
# @author cpuhrsch https://github.com/cpuhrsch
# @author Loreto Parisi loreto@musixmatch.com
import argparse
import numpy as np
from sklearn.metrics import confusion_matrix
def parse_labels(path):
with open(path, 'r') as f:
View promise_waterfall.js
function isPromise(obj) {
return obj && typeof obj.then === 'function';
}
function waterfall(list) {
// malformed argument
list = Array.prototype.slice.call(list);
if (!Array.isArray(list) // not an array
|| typeof list.reduce !== "function" // update your javascript engine
|| list.length < 1 // empty array
View sleep.js
sleep = function(time) {
var stop = new Date().getTime();
while(new Date().getTime() < stop + time) {
;
}
return new Promise((r,_)=> r())
}
View bookmarklet.js
function minify(code) {
// very simple minification (and not overly aggressive on whitespace)
code = code.split(/\r\n|\r|\n/g);
var i=0, len=code.length, noSemiColon = {}, t, lastChar;
$.each('} { ; ,'.split(' '), function(i, x) {
noSemiColon[x] = 1;
});
for (; i<len; i++) {
View react_bookmarklet.js
javascript:(function()%7Bvar%20injc%3Dfunction(src%2Ccbk)%20%7B%20var%20script%20%3D%20document.createElement('script')%3Bscript.src%20%3D%20src%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(script)%3Bscript.onload%3Dfunction()%7Bcbk%3Fcbk()%3A''%7D%7D%3Binjc(%22https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Freact%2F15.1.0%2Freact.min.js%22%2Cfunction()%20%7B%20injc(%22https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Freact%2F15.1.0%2Freact-dom.min.js%22%20)%7D)%7D)()
View jquery_bookmarklet.js
javascript:(function(){script = document.createElement('script');script.src = "https://ajax.goojavascript:(function()%7Bscript%20%3D%20document.createElement('script')%3Bscript.src%20%3D%20%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.6.3%2Fjquery.min.js%22%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(script)%7D)()gleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(script);})();
View react_inject.js
injc=(src,cbk) => { let script = document.createElement('script');script.src = src;document.getElementsByTagName('head')[0].appendChild(script);script.onload=()=>cbk() }
injc("https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js",() => injc("https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js",() => console.log("ready")))