Skip to content

Instantly share code, notes, and snippets.

function composeProviders(providers) {
return providers.reduce((AccumulatedProviders, [Provider, props = {}]) => {
return ({ children }) => (
<AccumulatedProviders>
<Provider {...props}>{children}</Provider>
</AccumulatedProviders>
);
}, ({ children }) => <>{children}</>);
}
@mbchoa
mbchoa / get_dupes.sql
Created July 15, 2023 01:24
Generates table of rows with duplicate values based on column
select t.*
from table t
join
(
select column_with_dupes
from table
group by column_with_dupes
having count(column_with_dupes) > 1
) using (column_with_dupes)
@mbchoa
mbchoa / combinationSum.js
Last active July 10, 2023 23:33
Combination Sum: Finds combination of numbers within a given collection where the sum of the set equals the input target
function findNumberCombinations(numbers, target) {
const result = [];
function backtrack(index, currentCombination, currentSum) {
if (currentSum === target) {
result.push([...currentCombination]);
return;
}
if (currentSum > target || index >= numbers.length) {
@mbchoa
mbchoa / blog3.md
Created December 19, 2022 00:52 — forked from khushal87/blog3.md
Linking a custom domain from Google domains to Vercel app

Linking a custom domain to a deployed application is confusing and at times you don't get a route on how to link the domain with the website. 😫

In this article, I will be explaining how to link a Custom domain brought in Google Domains service to an application hosted on Vercel.

Perks of using vercel is that it allows adding domain without any verification unlike Heroku/Netlify, which means you don't have to add your billing details to add a domain to your application. Moreover, it is fast, efficient, and easy to use.😁

What is Vercel?

​Vercel is a deployment and collaboration platform for frontend developers. ​Vercel enables developers to host websites and web services that deploy instantly and scale automatically – all without any configuration. Source - Official Docs

@mbchoa
mbchoa / jsonToCsv.ts
Created December 16, 2022 04:48
json to csv
export const jsonToCsv = (json, filename: string) => {
const replacer = (key, value) => (value === null ? "" : value);
const header = Object.keys(json[0]);
return [
header.join(","),
...json.map((row) =>
header
.map((fieldName) => JSON.stringify(row[fieldName], replacer))
.join(",")
),
@mbchoa
mbchoa / postgres-cheatsheet.md
Created August 6, 2021 19:10 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@mbchoa
mbchoa / useTimer.js
Created April 18, 2021 05:29
React Hook for millisecond-precision stopwatch timer.
import { useState, useRef } from 'react';
const useTimer = (initialState = 0) => {
const [elapsedTime, setElapsedTime] = useState(initialState);
const [isRunning, setIsRunning] = useState(false);
const countRef = useRef(null);
const handleStart = () => {
const startTime = Date.now() - elapsedTime;
countRef.current = setInterval(() => {
@mbchoa
mbchoa / find-process-by-port.sh
Last active April 18, 2021 01:45
Linux: Find process by port
netstat -plten | grep LISTEN | grep <PORT>
kill -9 <PID>
@mbchoa
mbchoa / fill.js
Last active April 4, 2021 19:32
Creates an array of specified size containing copies of element provided.
function fill(el, numRepeat) {
return [...Array(numRepeat)].map(() => el).join('');
}
@mbchoa
mbchoa / 8queens.js
Last active July 26, 2020 00:27
Recursive backtracking algorithm for solving the "8 Queens" problem
const UNASSIGNED = -1;
const ASSIGNED = 1;
class Board {
constructor(size, options) {
this.board = [];
this.size = size;
this.options = options;
for (let row = 0; row < size; row++) {