Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀

Dmitry Shvetsov dmshvetsov

🦀
View GitHub Profile
View solana-fns.ts
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
View do-if-exist-pattern.js
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)
View roman_num.rb
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
View make-derived-calculations-template.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)
View attach-download-multer-wrapper-azure.js
import { resolve } from 'path';
import fs from 'fs';
import { createBlobService } from 'azure-storage';
import config from 'config';
/**
* Service to handle files downloads requests
*
*/
View operators.c
/*
//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.
View site_migration_check.sh
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
@dmshvetsov
dmshvetsov / smalltalk_inspired_if_else_averse_in_ruby.rb
Created September 9, 2020 01:47
How to avoid if/else branch condition in Ruby. By Yehuda Katz https://yehudakatz.com/2009/10/04/emulating-smalltalks-conditionals-in-ruby/. Please don't do it in production code or your gems.
View smalltalk_inspired_if_else_averse_in_ruby.rb
class Object
def if_true
yield
self
end
def if_false
self
end
end
@dmshvetsov
dmshvetsov / roman-to-arabic-converter.js
Last active November 14, 2020 07:49
Example for roman numeral kata
View roman-to-arabic-converter.js
const ARABIC_ROMAN_MAP = [
["M", 1000],
["CM", 900],
["D", 500],
["CD", 400],
["C", 100],
["XC", 90],
["L", 50],
["XL", 40],
["X", 10],
View arabic-roma-map.js
const ARABIC_ROMAN_MAP = [
["M", 1000],
["CM", 900],
["D", 500],
["CD", 400],
["C", 100],
["XC", 90],
["L", 50],
["XL", 40],
["X", 10],