Skip to content

Instantly share code, notes, and snippets.

View amatiasq's full-sized avatar

A. Matías Quezada amatiasq

View GitHub Profile
import { mock, instance, when, verify, anything } from 'ts-mockito';
const mockedFoo: Foo = mock(Foo);
// stub method before execution
when(mockedFoo.getBar(3)).thenReturn('three');
// Getting instance from mock
const foo: Foo = instance(mockedFoo);
@amatiasq
amatiasq / esm.ts
Last active September 23, 2021 11:57
const extensions = {
js: 'application/javascript',
ts: 'application/typescript',
jsx: 'text/jsx',
tsx: 'text/tsx',
} as const;
type Extensions = typeof extensions;
type ValidExtension = keyof Extensions;
type ValidMediaType = Extensions[ValidExtension];
@amatiasq
amatiasq / 1. Leyur.txt
Last active February 24, 2021 09:25
Leyur
CRASH! Pude escucharlo perfectamente. CRASH! Hizo mi corazón cuando Cintia lo tiro a través del bosque.
- Cómo...? - pregunte con el alma en un hilo, al borde del llanto.
- Ya no te soporto mas, oíste bien, eres una puta, vete de aquí, no te quiero cerca mio.
- pero Cin...
Un movimiento veloz y... dos centímetros, eso fue la distancia que separaba la daga de Cintia de mi nariz.
- Ya me has oido, fuera de aquí o te abro en canal.
@amatiasq
amatiasq / EcmaScript 2020.js
Last active February 24, 2021 09:20
EcmaScript
#!/usr/bin/env node
const meUrl = import.meta.url;
const icon = await fetch(new URL('./icon.png', meUrl));
const element = import.meta.scriptElement ?? { remove() {} };
element.remove();
// Fields & privates
@amatiasq
amatiasq / CSVReader.js
Created November 9, 2018 11:10
CSV Parsers
const fs = require('fs');
const { promisify } = require('util');
const fs_open = promisify(fs.open);
const fs_read = promisify(fs.read);
const fs_close = promisify(fs.close);
let debug;
try {
debug = require('debug');
} catch(error) {
@amatiasq
amatiasq / concatRegexes.js
Last active February 24, 2021 08:57
concatRegexes
const createConcatenator = escape => (...regexes) => {
const join = regexes
.map(x => (x instanceof RegExp ? regexToString(x) : escape(x)))
.join("");
const flags = regexes
.map(x => x instanceof RegExp && x.flags)
.filter(Boolean)
.join("");
@amatiasq
amatiasq / clone.js
Last active February 15, 2021 22:18
Creates a copy of a object duplicating every property, even prototyped ones.
var extend = Object.getOwnPropertyNames ?
function ecma5extend(obj) {
var proto = obj;
var protos = [];
var result = {};
var descriptors = {};
while (proto) {
protos.push(proto);
proto = Object.getPrototypeOf(proto);
@amatiasq
amatiasq / grid.less
Last active February 15, 2021 22:18
A mixin to create a N * N css classes grid.
.grid_column(@prefix; @index; @base) {
@fullclass: ~'.grid-@{prefix}col@{index}';
@{fullclass} { left: @base * @index; }
}
.grid_row(@prefix; @index; @base) {
@fullclass: ~'.grid-@{prefix}row@{index}';
@{fullclass} { top: @base * @index; }
}
.grid_width(@prefix; @index; @base) {
@fullclass: ~'.grid-@{prefix}hspan@{index}';
// Defines a module that works in Node and AMD.
// This version can be used as common boilerplate for a library module
// that you only want to expose to Node and AMD loaders. It will not work
// well for defining browser globals.
// If you need a version of this file that works CommonJS-like environments
// that do not support module.exports or if you want to define a module
// with a circular dependency, see commonjsAdapter.js