Skip to content

Instantly share code, notes, and snippets.

@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)+')'; }
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;
.batteryResultsList > ul:before {
content: '';
display: block;
position: relative;
height: 10px;
width: 10px;
border-radius: 10px;
left: -1rem;
top: 0.85rem;
}
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;
@marcmartino
marcmartino / sm2.ts
Last active November 4, 2018 21:13
typescript implementation of the supermemo 2 algorithm
interface CardAnswer {
[key: string]: (boolean | number | date)
hesitationDetected: boolean;
correct: boolean;
timeSpent: number;
date: date;
ef?: number;
interval?: number;
}
@marcmartino
marcmartino / sm4.ts
Created November 5, 2018 01:30
attempt at sm4, likely inconsistent but sm5 is significantly different so no dwelling
const answers: CardAnswer[] = [
{
"hesitationDetected": true,
"correct": true,
"timeSpent": 5000,
"date": new Date("2018-11-01T15:13:00.000Z")
},
{
"hesitationDetected": false,
"correct": false,
@marcmartino
marcmartino / wordlists.create.sql
Last active December 30, 2018 01:39
word lists schema
CREATE TABLE `WordLists` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` varchar(300),
PRIMARY KEY (`id`)
);
CREATE TABLE `WordGroups` (
`id` int NOT NULL AUTO_INCREMENT,
`wordListId` int NOT NULL,
@marcmartino
marcmartino / getOrderedWordsList.sql
Created January 23, 2019 14:38
scripts for getting the next list items
SELECT
Asses.id,
Groups.orderNum,
Defs.phrase, Defs.definition AS translation,
Items.phrase, Items.translation
FROM WordGroups AS Groups
INNER JOIN WordListAssignments AS Asses
ON Groups.id = Asses.wordGroupId
AND Groups.wordListId = 1
INNER JOIN WordListItems AS Items
@marcmartino
marcmartino / CardQueues.d.ts
Last active January 30, 2019 03:39
CardQueues Snippets
type Card = {
id: number,
phrase: string,
translation: string,
};
type CardQueue = Card[] | "Completed";
type CardQueues = [CardQueue, CardQueue];
type UpdatedQueues = {
updatedAt: Date,
queues: CardQueues,
type Tuple<T, U> = [T, U];
type Predicate<T> = (value: T) => boolean;
type Callback<T, U> = (value: T) => U;
type Route<T, U> = <V>(
predicate: Predicate<T>,
callback: Callback<T, V>
) => RouteResponse<T, U | V>;
interface RouteResponse<T, U> {