Skip to content

Instantly share code, notes, and snippets.

View dmshvetsov's full-sized avatar
🪄

Dmitry Shvetsov dmshvetsov

🪄
View GitHub Profile
@dmshvetsov
dmshvetsov / collection-utils.ts
Created October 11, 2023 16:18
all sort every day utils for TypeScript
function groupBy<T extends Record<string, string | number>, K extends keyof T>(list: T[], groupByKey: K): Record<T[K], T[]> {
return list.reduce((acc, item) => {
const groupValue = item[groupByKey]
if (!acc[groupValue]) {
acc[groupValue] = [item]
} else {
acc[groupValue].push(item)
}
return acc
}, {} as Record<T[K], T[]>)
module 0xA::pyth_oracle_n_coin_transfer_a {
struct State {
// a place where depositor, asset and amount is stored
}
public entry fun colatarize_asset<Asset>(depositor: &signer, amount: u64) {
let resource_account = get_resource_account();
coint::transfe<Asset>(
depositor,
resource_account,
@dmshvetsov
dmshvetsov / my_lodash_fn.ts
Last active August 4, 2023 07:00
type safe implementation lodash like functions (WIP)
type DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;
type DotNestedKey<T> = (
T extends object
? {
[K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<
DotNestedKey<T[K]>
>}`;
}[Exclude<keyof T, symbol>]
: ''
) extends infer D
import dotenv from "dotenv";
dotenv.config();
import assert from "assert";
import * as web3 from "@solana/web3.js";
import * as fs from "fs";
/**
* Constants
*/
@dmshvetsov
dmshvetsov / do-if-exist-pattern.js
Created April 26, 2021 07:04
Do if values exist pattern
function doIfExist(obj, predicateValuesPaths, fn) {
const values = predicateValuesPaths.map((keyPath) => get(obj, keyPath))
if (all(values, truthy)) {
return fn(...values)
}
return
}
@dmshvetsov
dmshvetsov / roman_num.rb
Created December 28, 2020 07:37
Integer to Roman Number string conversion (kata, exercise)
class Roman
NUMS = [
[10, 'X'],
[9, 'IX'],
[5, 'V'],
[4, 'IV'],
[1, 'I']
].freeze
def self.from(val)
@dmshvetsov
dmshvetsov / make-derived-calculations-template.js
Last active December 21, 2020 06:17
WIP; Consider using with Quokka.js
const K = 1000
const M = 1000 * K
const KB = 1000
const MB = 1000 * KB
const GB = 1000 * MB
const TB = 1000 * GB
const PB = 1000 * TB
function Calc () {
this.value = 100 * K
@dmshvetsov
dmshvetsov / attach-download-multer-wrapper-azure.js
Last active December 11, 2020 23:26
Rewrite of multer-azure-storage package with additional helper function (used in Express app)
import { resolve } from 'path';
import fs from 'fs';
import { createBlobService } from 'azure-storage';
import config from 'config';
/**
* Service to handle files downloads requests
*
*/
/*
//so far we've worked with some basic operators
Positive and negative operators (unary)
+
-
Arithmetic (binary)
+
-
/
*
@dmshvetsov
dmshvetsov / site_migration_check.sh
Last active September 22, 2020 02:05
Check if you miss any page when migrated a site from one domain to another, or from one tech to another. In this example dmitryshvetsov.com and localhost:8000 is used.
curl https://dmitryshvetsov.com/sitemap.xml | \
grep -e loc | \
sed 's:<loc>\(.*\)<\/loc>$:\1:g' | \
sed -e 's/^[[:space:]]*//' | \
sed 's/https:\/\/dmitryshvetsov\.com/http:\/\/localhost:8000/' | \
while read -r line; do open $line; done