Skip to content

Instantly share code, notes, and snippets.

const blankLinesPattern = /^\s+$/gm; // the only regex that works fine
const blankLinesRegex = new RegExp(blankLinesPattern);
const data = `900,10,1,1,1,1,1,1,1,1,1,1
100,2,1,1,1,2,1,2,1,1,1,1
`;
var match;
while (!!(match = blankLinesPattern.exec(data))) {
import { Subject, Observable, ConnectableObservable, from, interval } from 'rxjs';
import { multicast, refCount } from 'rxjs/operators';
// https://rxjs-dev.firebaseapp.com/guide/subject
// {
// console.log(`UNICAST VS MULTICAST`);
// const subject = new Subject<number>();
@andrewlistopadov
andrewlistopadov / trim_canvas.js
Created October 28, 2019 15:59 — forked from timdown/trim_canvas.js
Returns a copy of a canvas element with surrounding transparent space removed
var trimCanvas = (function() {
function rowBlank(imageData, width, y) {
for (var x = 0; x < width; ++x) {
if (imageData.data[y * width * 4 + x * 4 + 3] !== 0) return false;
}
return true;
}
function columnBlank(imageData, width, x, top, bottom) {
for (var y = top; y < bottom; ++y) {
@andrewlistopadov
andrewlistopadov / observable-resolve-reject-testing.ts
Last active October 8, 2019 14:13
observable-resolve-reject-testing.ts
// resolve after 500msec.
of(null).pipe(delay(500));
// reject after 600msec.
function makeRequest(timeToDelay) {
return of('Request Complete!').pipe(delay(timeToDelay));
}
return of(600)
const arr = [{name: 'Bill', age: 26}, {name: 'Sara', age: 42}, {name: 'Tom', age: 13}];
const namesArray = arr.map(({age, ...keepAttrs}) => keepAttrs); // removes `age`
console.log(namesArray);
function getRejectedPromise() {
const promise = new Promise((resolve, reject) => {
reject('some error');
});
return promise;
}
let counter = 0;
const interval = setInterval(() => {
if (++counter > 10) clearInterval(interval);
@andrewlistopadov
andrewlistopadov / argumentsDestruction.ts
Last active November 1, 2019 07:57
TS function arguments destruction
interface Options {
a?: string;
b?: number;
c?: Array<any>
}
const fullOptions = {a: 'a-full', b: 100, c: ['a-full', 100, null]};
const partialOptionsA = {a: 'a-1'};
const partialOptionsB = {b: 200};
const partialOptionsC = {c: ['a-2', 300, null]};
@andrewlistopadov
andrewlistopadov / alphaNumericRegexp.js
Last active February 12, 2018 07:09
Replace all characters that are not numbers, (sub)superscript or letter
let str = '123QWEqwe#$\\g/cm³'
let result = str.replace(/[^A-Za-z0-9\p{No}]/g, '');
btn - Button
cb - CheckBox
cbl - CheckBoxList
dd - DropDownList
hl - Hyperlink
img - Image
ib - ImageButton
lbl - Label
lnk - Link
lbtn - LinkButton
@andrewlistopadov
andrewlistopadov / moneyFormat.js
Created July 10, 2015 08:30
JS: convert number to money string
'use strict';
/**
* isNumeric(n) returns a bool value
* is "n" number or not
*
* @param {Number} n
* @return {Bool} result
*/
function isNumeric(n) {