Skip to content

Instantly share code, notes, and snippets.

View onmax's full-sized avatar
💭
🌍

Max onmax

💭
🌍
View GitHub Profile
@onmax
onmax / processByBatches.ts
Created January 26, 2024 04:14
Effective approach to processing items in batches asynchronously in JavaScript. This function processByBatches allows parallel processing of items, with a customizable batch size. There's room for enhancements, like incorporating Promise.allSettled or adding more options. Feedback and improvements are welcome!
interface ProcessByBatchesOptions {
/**
* The number of items to process in parallel.
* @default 10
*/
batchSize?: number
}
async function processByBatches<ItemType, ResultType>(
items: ItemType[],
import data from "./YOUR_JSON.json" assert { type: "json" };
const apiEndpoint = 'https://{SUPABASE_REF}.supabase.co/rest/v1/rpc/upsert_location_with_gmaps_api';
const apiKey = 'API_KEY';
const authorizationBearer = 'YOU AUTH';
const makeRequest = async (data: any[]) => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('apikey', apiKey);
headers.append('Authorization', `Bearer ${authorizationBearer}`);
@onmax
onmax / get_establishment_by_uuid.plpgsql
Last active June 27, 2023 17:32
Postgres functions that power the Crypto Map: map.nimiq.com
CREATE OR REPLACE FUNCTION public.get_establishment_by_uuid(uuid UUID)
RETURNS JSONB AS
$$
DECLARE
result JSONB;
BEGIN
SELECT
json_build_object(
'uuid', e.uuid,
'name', e.name,
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "@uniswap/swap-router-contracts/contracts/interfaces/IV3SwapRouter.sol";
import "./interfaces/IERC20Meta.sol";
import "./interfaces/IWrappedChainToken.sol";
import "./BaseCombinedGsnHandler.sol";
abstract contract BaseERC20MetaHandler is BaseCombinedGsnHandler {
@onmax
onmax / nth-rule-unocss.js
Created April 19, 2022 17:21
A custom UnoCSS rule to be able to select items like `nth-2:text-blue` or `nth-9:rounded-9`
import { defineConfig, toEscapedSelector: e } from 'unocss'
// See it in action:
// https://unocss.antfu.me/?html=DwVwNgBAdgLgFgWgEwC4YFMAeMECMwjrTwIDMKuA5ngUZQE4CWAJhAywgMYD2YAzmQgAHMAENO6BIwwBbARNjp6ERH07106KACgIetqKEJMCACwA%2BXRGBhG5gJKyIARmAB6W5b027j9DIgkd08rHwcnUmC7bXdwcyA&config=JYWwDg9gTgLgBAbzgEwKYDNgDtUGEJaYDmANHDBAKIDOAxgIZirIDKqANqrRVAFxyo4AXzjooEEHADkAVywRa1alIBQK1AA9IsFBnoz28NJhz5CwIgAoEKuHCgHU1fgG1bduC4D0APSwwACwAdAFpLIOQAagBKIN5LADoAKmiAEi8yemoATyxaOEsXMmQyKABdMgQoegB3Nk5uaDJaAmoYB25cFhYyIlQcap4haLgAXgA%2BRDh3DzgWrDb7RzG4WvpgeEs%2BgfoeBLB6KGpUABUIAGt%2Byyho6JmPKFQYGSgsOAADVIRUa9r6rh40REkySvH8ARCtACwHYyEsX2QwymXwcnBcAAYyi4AExlERCd73IQVdxlFTDIA&options=N4IgzgLgTglgxhEAuaBXApgXyA
export default defineConfig({
rules: [
[/^nth\-(\d+)\:(.*)$/, async ([, d, r], {rawSelector, constructCSS, generator}) => {
const rule = await (generator.parseToken(r))
return `${e(rawSelector)} > *:nth-child(${d}) { ${rule[0][2]} }`
@onmax
onmax / flatten.js
Created April 9, 2022 13:52
Flatten arry in JS
// https://stackoverflow.com/a/15030117/8312883
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
@onmax
onmax / tailwind-only-tooltip.html
Created March 18, 2022 21:18
Tooltip with only Tailwind
<!-- See https://play.tailwindcss.com/PGizn94M2s -->
<div class="min-h-screen bg-gray-50 py-6 flex flex-col justify-center relative overflow-hidden sm:py-12">
<div class="absolute inset-0 bg-[url(/img/grid.svg)] bg-center [mask-image:linear-gradient(180deg,white,rgba(255,255,255,0))]"></div>
<div class="relative px-6 pt-10 pb-8 bg-white shadow-xl ring-1 ring-gray-900/5 sm:max-w-5xl sm:mx-auto sm:rounded-lg sm:px-10">
<div class="max-w-4xl mx-auto">
<div class="divide-y divide-gray-300/50">
<div class="py-8 text-base leading-7 text-gray-600">
<p>
An amazing Tooltip
<span class="group hover:underline cursor-pointer inline-block relative">
@onmax
onmax / event-list.js
Last active February 8, 2022 19:42
List all active events in a page
// More info at:
// https://www.perimeterx.com/tech-blog/2019/list-every-event-that-exists-in-the-browser/
// Just run it in developer console:
function _isEvent(prop) {
if (0 !== prop.indexOf("on")) {
return false;
}
return true;
}
@onmax
onmax / README.md
Created November 25, 2021 12:50
Alastria Remix

Connect quickly to Alastria network and run SC functions

  1. Go to remix (Without https!)
  2. Go to "Deploy & run transactions" (third icon on the left bar)
  3. Select the "Web3 Provider" and use this node: http://63.33.206.111/rpc
  4. Go to the plugin manager (fourth icon) and add "DGIT"
  5. A new git icon on the left bar has appeared, click it
  6. Open Github tab and look for the clone
  7. Paste this repository: https://github.com/alastria/alastriaID-truffle-contracts (you can select the branch)
  8. If you go to File explorer you will find the contracts there.
@onmax
onmax / README.md
Created November 15, 2021 12:54
Quick example how to work with RxJS as a Pipe of messages

Quick example how to work with RxJS as a Pipe of messages

See it in work