Skip to content

Instantly share code, notes, and snippets.

View rostegg's full-sized avatar
💜
Developing software with KISS principle in mind

Rostyslav Nikolaienko rostegg

💜
Developing software with KISS principle in mind
View GitHub Profile

Create two Azure Functions:

Public IP

After receiving GET request, return to the user his public ip, not using any third-party service (it can be received from request headers, google how)

Response type, structure, etc at your own discretion

Image metadata extractor

@rostegg
rostegg / dot-net-roadmap.md
Created October 12, 2022 13:12
Roadmap for .NET C#/ASP.NET (basics)
@rostegg
rostegg / benchamrking.js
Last active September 28, 2021 14:56
Simple benchmarking
const benchmark = (func, input, iterations) => {
const start = performance.now()
for (let i = 0; i < iterations; i++) {
func(...input)
}
const finish = performance.now()
const time = finish - start
return {
time,
aproxOperation: (time/iterations)
@rostegg
rostegg / group-with-skip.js
Created September 2, 2021 12:07
Group elemnts of array, skiping last N elements in group
function groupSkip(arr, shift, skip = 1) {
const res = []
let limit = 0
while (limit+shift <= arr.length) {
res.push(arr.slice(limit, shift + limit - skip))
limit += shift
}
return res
}
@rostegg
rostegg / image-data-from-url.js
Created September 2, 2021 11:31
Get ImageData from canvas, loading picture via url
const getImageDataFromUrl = (url, callback) => {
const canvas = document.createElement("canvas")
const context = canvas.getContext("2d")
const image = new Image()
image.onload = async () => {
const { width, height } = image
const { data: imageData } = context.getImageData(0, 0, width, height)
callback(imageData)
@rostegg
rostegg / async-iterator.js
Created August 17, 2021 12:03
Custom async iterator
let range = {
from: 1,
to: 5,
[Symbol.asyncIterator]() {
return {
current: this.from,
last: this.to,
async next() {
@rostegg
rostegg / async-disposer.js
Last active January 29, 2022 22:03
Async disposer pattern example (simple way to controll freeing a resource)
const withResource = async (fn) => {
const instance = await getInstance()
try {
return await fn(instance)
} finally {
await instance.close()
}
}
const task = await witchResource(async (instance) => {
@rostegg
rostegg / subbaray.js
Last active August 2, 2021 18:39
Return subbaray from array of target indexes
/*
Example:
const arr = [1,2,3,4,5,7,8]
arr.subarrayFromIndexes([0,77,3,5,15])
*/
Array.prototype.subarrayFromIndexes = function (indexes) {
if (!Array.isArray(this))
throw "indexes must be array"
return indexes.reduce((acc, current) => {
@rostegg
rostegg / curry-multi-args.js
Created July 5, 2021 18:14
Curry function with unknown length of params
/*
const toCurryFn = (...args) => {...}
const curried = curry(toCurryFn);
...
*/
function curry(fn) {
const argumentsArray = [];
function subCurry(...args) {
/*
Just experiments and some thoughts.
Better use for/foreach over arrays and check if target arr already contains objects, something like:
const target = [...one]
for (current of two) {
const duplicated = target.find(item => item.id === current.id);
!duplicated && target.push(current);