Skip to content

Instantly share code, notes, and snippets.

View maciekChmura's full-sized avatar

Maciek Chmura maciekChmura

  • Poland
View GitHub Profile
@maciekChmura
maciekChmura / recorder.tsx
Created March 16, 2023 09:05
React AudioRecorder - speech to text with Whisper API
import { useState, useRef } from "react";
import { reportError, getErrorMessage } from "~/utils/error";
import axios from "axios";
import { env } from "~/env.mjs";
type RecordingStatus = "inactive" | "recording" | "paused";
const mimeType = "audio/mp3";
const fileName = "recording.mp3";

Full text search with supabase

In general I'm following this quick start from supabase: https://supabase.com/docs/guides/database/full-text-search

  1. I'm using Lexical (https://lexical.dev/) for my text editor and savign data as JSON, so I can't use the data from Lexical for searching. Saved text looks like this: image

  2. I created additional column for storing the raw strings from Lexical with additional values from other inputs in my form (location, company name, offer title, etc..)

@maciekChmura
maciekChmura / parse_to_phone_num.js
Last active January 10, 2019 08:06
parse string to a phone'like number
// parse string to a phone'like number
// xxx-xx
// xxx-xxx
// xxx-xx-xx
// xxx-xxx-xx ...etc
const parseInput = (userInput) => {
const stringOfNumbers = userInput
.split('')
.filter(element => element !== ' ')
@maciekChmura
maciekChmura / closure_and_persistent_data.js
Created November 9, 2018 12:48
closure and persistent data in function calls
function outer(){
let counter = 0;
function incrementCounter(){
counter++;
console.log(`counter: ${counter}`);
}
// this console.log print only once value 0
// it is called only once in outer()
// thats why counter is 0 here
// console.log(`counter: ${counter}`);
@maciekChmura
maciekChmura / block.js
Last active October 2, 2018 07:47
block JavaScript for 5 sek #JavaScript
// const dateNow = Date.now();
// while (Date.now() < dateNow + 5000) {
// }
// console.log("ok");
// function longFn() {
// let i = 0;
// const t = setInterval(function () {
// i++;
@maciekChmura
maciekChmura / callMe.js
Last active September 19, 2018 19:04
call function without parenthesis #JavaScript
function printName(name) {
console.log(`hello ${name}`);
}
printName`Maciek`
@maciekChmura
maciekChmura / randomize.js
Created September 18, 2018 07:42
randomize array #JavaScript array sort random
let array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const randomize = (data) => {
return data.sort(() => 0.5 - Math.random())
}
console.log(randomize(array));
// array of numbers to array of objects
const array = [1, 2, 3, 4, 5, 6, 7].map(id => ({ id }));
console.log(array);
​​
/*
​​​[ { id: 1 },​​​​​
​​​​​ { id: 2 },​​​​​
​​​​​ { id: 3 },​​​​​
@maciekChmura
maciekChmura / RORO.js
Last active August 17, 2018 06:14
RORO pattern #JavaScript
// https://medium.freecodecamp.org/elegant-patterns-in-modern-javascript-roro-be01e7669cbd
// Receive an object, return an object (RORO)
let options = {
role: 'admin from options',
withContactInfo: '666',
includeInactive: 'not'
};
function findUsersByRole({
@maciekChmura
maciekChmura / conditionally_spread_object.js
Created April 3, 2018 10:57
conditionally spread properties in an object #JavaScript
let condition = true;
let otherCondition = false;
const obj = {
...(condition && { a: 1 }),
...(otherCondition ? { b: 2 } : { c: 3 })
};
console.log(obj);