Skip to content

Instantly share code, notes, and snippets.

View vitaliy-bobrov's full-sized avatar

Vitalii Bobrov vitaliy-bobrov

View GitHub Profile
const context = new AudioContext();
class Val {
final List<dynamic> value;
final String token;
Val({this.value, this.token});
}
void main() {
String showVal(Val value) {
if ('paintWorklet' in CSS) {
// Safari TP fix.
// Safari only accepts source code as a string instead file path.
if (navigator.userAgent.includes('Safari')
&& !navigator.userAgent.includes('Chrome')) {
(async function() {
const response = await fetch('paint.js');
const blob = await response.blob();
const reader = new FileReader();
const reader = new FileReader();
reader.addEventListener('load', () => {
CSS.paintWorklet.addModule(reader.result);
});
reader.readAsText(blob);
(async function() {
const response = await fetch('paint.js');
const blob = await response.blob();
})();
if ('paintWorklet' in CSS) {
CSS.paintWorklet.addModule('paint.js');
}
if ('paintWorklet' in CSS) {
if (navigator.userAgent.includes('Safari')
&& !navigator.userAgent.includes('Chrome')) {
// Safari TP fix will be here.
} else {
CSS.paintWorklet.addModule('paint.js');
}
}
<script id="code" type="text/worklet">
class MyPaint {
paint(ctx, geom) {
ctx.fillStyle = "red";
ctx.fillRect(0, 0, geom.width, geom.height);
}
}
registerPaint('my-paint', MyPaint);
</script>
levenshtein(a: string, b: string): number {
if (a.length == 0) {
return b.length;
}
if (b.length == 0) {
return a.length;
}
const matrix = [];
sortByDistances(typoPath: string, dictionary: string[]) {
const pathsDistance = {} as { [name: string]: number };
dictionary.sort((a, b) => {
if (!(a in pathsDistance)) {
pathsDistance[a] = this.levenshtein(a, typoPath);
}
if (!(b in pathsDistance)) {
pathsDistance[b] = this.levenshtein(b, typoPath);
}