Skip to content

Instantly share code, notes, and snippets.

function randomSelection<T>(numToSelect: number, list: T[]): T[] {
return take(numToSelect, randomizeList(range(0, list.length)))
.map((i) => list[i]);
}
function randomizeList<T>(xs: T[], randomized: T[] = []): T[] {
if (xs.length) {
const {arr, val} = slice(Math.floor(Math.random() * xs.length), xs);
return randomizeList(arr, randomized.concat([val]));
}
return randomized;
.batteryResultsList > ul:before {
content: '';
display: block;
position: relative;
height: 10px;
width: 10px;
border-radius: 10px;
left: -1rem;
top: 0.85rem;
}
import { removeAccents } from './languageTools';
import { indexOf } from 'lodash';
type LangShortCode = ('en-AU' | 'en-CA' | 'en-GH' | 'en-GB' | 'en-IN' | 'en-IE' | 'en-KE' | 'en-NZ' | 'en-NG' | 'en-PH' | 'en-ZA' | 'en-TZ' | 'en-US' | 'es-AR' | 'es-BO' | 'es-CL' | 'es-CO' | 'es-CR' | 'es-EC' | 'es-SV' | 'es-ES' | 'es-US' | 'es-GT' | 'es-HN' | 'es-MX' | 'es-NI' | 'es-PA' | 'es-PY' | 'es-PE' | 'es-PR' | 'es-DO' | 'es-UY' | 'es-VE');
const listen = (lang: LangShortCode = 'en-US') => (grammars: string[] = []) => (condition: (SpeechRecognitionEvent) => boolean = () => true): Promise<SpeechRecognitionEvent> =>
new Promise((resolve, reject) => {
var recognition = new webkitSpeechRecognition();
recognition.lang = lang;
@marcmartino
marcmartino / examples.js
Created August 10, 2017 00:07
Lonsdorf interpreters examples
var Const = function(x) { return new _Const(x); };
var _Const = function(val) { this.val = val; };
_Const.prototype.inspect = function(){ return 'Const('+inspect(this.val)+')'; }
var Add = function(x, y) { return new _Add(x, y); };
var _Add = function(x, y) {
this.x = x;
this.y = y;
};
_Add.prototype.inspect = function(){ return 'Add('+inspect(this.x)+', '+inspect(this.y)+')'; }
maximum [x*y | x <- [100..999] , y <- [100..999], x*y == reverseInt (x*y)]
//jshint esnext:true
/*
Multiples of 3 and 5 - Problem 1
If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
//jshint esnext:true
/*
Multiples of 3 and 5
Problem 1
If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
// 1..100
// 3 5
const seq = min => max => {
let list = [];
for (let index = min; index <= max; index++) {
list.push(index);
}
return list;
}
@marcmartino
marcmartino / colorCalc.js
Created June 30, 2017 07:49
dynamic color blending
//jshint esnext:true
// curveColors should have a length longer than or equal to 1
// the colors are split evenly- with a curveColors length of 3
// with said curveColors, a score of 75 would respond to halfway between index 1 and 2
const curveColors = [{r: 49, g: 198, b: 84},
{r: 46, g: 48, b: 193},
{r: 193, g: 138, b: 44},
{r: 193, g: 44, b: 44}]
// score should be between 0-100
const score = 50
var funcNames = {
addition: {
func: function (paramsArr = []) {
return paramsArr.reduce((tot, num) => tot + num, 0)
},
textRep: '+'
},
subtraction: {
func: function ([head, ...tail] = []) {
return tail.reduce((tot, num) => tot - num, head)