Skip to content

Instantly share code, notes, and snippets.

View maksimr's full-sized avatar
🎯
Focusing

Maksim Ryzhikov maksimr

🎯
Focusing
View GitHub Profile
async function fetchZip(url, outDir) {
const os = require('os');
const path = require('path');
const fs = require('fs');
const AdmZip = require("adm-zip");
const pipeline = require('stream/promises').pipeline;
const zipName = path.basename(url);
const zipFilePath = path.join(os.tmpdir(), zipName);
const response = await fetch(url);
async function main() {
const fs = require('fs/promises');
const os = require('os');
const path = require('path');
const promisify = require('util').promisify;
const babelParentDir = path.resolve(__dirname, '..', 'packages');
const babelParserDir = path.join(babelParentDir, 'babel-parser')
const babelPackageName = '@packages/babel-parser';
const babelOutDir = 'lib';
const fs = require('node:fs/promises');
const assert = require('node:assert/strict');
const windowNewlineRegexp = /\r/g;
function replaceWindowsLineEndings(str) {
return str.replace(windowNewlineRegexp, '');
}
function getSnapshotPath(filename) {
@maksimr
maksimr / nix-on-macos-catalina.md
Created January 24, 2024 18:35 — forked from chriselsner/nix-on-macos-catalina.md
Nix on macOS Catalina

Nix on macOS Catalina

I'm writing this gist for my own records but it might help someone else too.

Installing Nix

Support for Catalina has improved a lot since the update was first rolled out.

Note: See the NixOS manual for discussion of the --darwin-use-unencrypted-nix-store-volume option.

@maksimr
maksimr / index.ts
Last active January 5, 2024 09:12
ansicolor typescript
function ansicolor(str: string, colour:
| 0 // all attributes off
| 1 // bold on
| 4 // underline on
| 5 // blink on
| 21 // bold off
| 24 // underline off
| 25 // blink off
| 30 // bloack foreground
| 31 // red foreground
@maksimr
maksimr / index.ts
Last active December 29, 2023 18:32
tracer
import { Tracer } from './tracer';
import express, { Request, Response } from 'express';
import { ErrorHandler, Handler, wrap } from 'async-middleware';
import { spanProcessor } from './span-processor';
import { SpanOptions } from '@opentelemetry/api';
async function main() {
const tracer = new Tracer({ name: 'example-tracer-node' });
const app = express();
@maksimr
maksimr / index.ts
Last active December 11, 2023 20:14
jsonb index
import pg from 'pg';
async function main() {
const client = new pg.Client({
host: '127.0.0.1',
port: 5432,
user: 'username',
password: 'password',
database: 'test'
});
@maksimr
maksimr / index.ts
Last active November 22, 2023 07:04
batch throttle
type Deferred<T> = {
resolve: (value: T) => void;
reject: (reason?: any) => void;
promise: Promise<T>;
}
// Call function when timeout is reached
// by splitin array of arguments into batches
// and calling function with each batch
// Allow setup maxParallel to limit number of parallel calls
@maksimr
maksimr / index.ts
Last active November 19, 2023 20:33
streamin data from postgresql database to s3
import { CreateBucketCommand, DeleteBucketCommand, DeleteObjectCommand, ListBucketsCommand, ListObjectsCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import pg from 'pg';
import QueryStream from 'pg-query-stream'
import { JsonStreamStringify } from 'json-stream-stringify';
/**
* This is an example of streaming data from a postgresql database to S3
* with low memory usage
*/
async function main() {
@maksimr
maksimr / index.ts
Last active November 20, 2023 18:11
node tracer
import { context, trace } from "@opentelemetry/api";
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { promisify } from "util";
async function main() {
const contextManager = new AsyncLocalStorageContextManager();
const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));