Skip to content

Instantly share code, notes, and snippets.

View blackakula's full-sized avatar
🎯
"We're just enthusiastic about what we do" (с)

Serhii Kyrychenko blackakula

🎯
"We're just enthusiastic about what we do" (с)
  • Chantelle
  • Germany, Berlin
  • 10:34 (UTC +02:00)
View GitHub Profile
@blackakula
blackakula / ClassWhoAmI.js
Last active April 18, 2024 15:34
Classes versus co-data
class ClassWhoAmI {
#prefix = 'It is the secret'
suffix = 'person'
static additional = 'bad one'
constructor(parameter) {
this.parameter = parameter
}
getValue() {
@blackakula
blackakula / main.rs
Created March 22, 2022 07:16
1D SPREADSHEET
use std::io;
macro_rules! parse_input {
($x:expr, $t:ident) => ($x.trim().parse::<$t>().unwrap())
}
#[derive(Debug)]
enum Val1 {
Val(i32),
Ref(usize),
@blackakula
blackakula / config-webpack-index.js
Created August 5, 2021 19:53
Webpack build server side rendering
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const paths = require('../paths');
const resolvers = require('./resolvers');
const loaders = require('./loaders');
const plugins = require('./plugins');
@blackakula
blackakula / README.md
Last active March 17, 2021 17:03
My GitHub

GitHub stats

Top Langs

@blackakula
blackakula / maze-escaper.ts
Created October 2, 2019 18:26
Meetup maze
const Maze = ` ############################
# # # # #
# #### # #### # # #### #
# # # # #
####### ########## ##########
# # # # # # # #
# # # # #### # # #### #
# # # #
# # # #### #### #### ####
# # # # # # # #
@blackakula
blackakula / Csv.spec.ts
Last active September 4, 2019 08:32
async iterator
import {} from 'ts-jest';
import * as parse from 'csv-parse';
import {StreamReadCallback, StreamReadable, streamReadable} from './Readable'
import {CsvRow, csvStreamReadApplyCallbacks} from './Readable_Csv'
import { testing } from 'bs-logger';
interface SpecificCSVRow {
first: string
second: string
}
<?php
$GLOBALS['plusMinus'] = [
'-' => function ($a, $b) { return $a - $b; },
'+' => function ($a, $b) { return $a + $b; },
];
$GLOBALS['multiplyDivide'] = [
'*' => function ($a, $b) { return $a * $b; },
'/' => function ($a, $b) { return $a / $b; },
];
export const Validator = (value, props, ...customValidators) => (validators => validators.reduce((errors, validate) => [...errors, ...validate(value, props)], []))([
// Here the list of validators
(value, props) => typeof value !== 'string'
|| props.type !== 'email'
|| /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value.toLowerCase()) ? [] : [{error: Errors.EMAIL}],
(value, props) => typeof value !== 'string'
|| typeof props.maxLength === 'undefined'
|| parseInt(props.maxLength) >= value.length ? [] : [{error: Errors.MAXLENGTH, length: parseInt(props.maxLength)}],
/**
* Other validators here
@blackakula
blackakula / fp-fibonacci-memoized.js
Created April 9, 2018 22:08
Functional programming: Fibonacci function with memoization (n=8)
const resultCombination = cache => result => (getResult = true) => getResult ? result : cache
const cacheResult = ({resultCombination}) => result => n => resultCombination({...result(false), [n]: result()})(result())
const memoize = ({resultCombination, cacheResult}) => cache => f => n => cache.hasOwnProperty(n)
? resultCombination(cache)(cache[n])
: cacheResult({resultCombination})(f(cache)(n))(n)
const fib2 = ({resultCombination, cacheResult, memoize}) => f1Result => f => n => resultCombination(f1Result(false))(f1Result() + memoize({resultCombination, cacheResult})(f1Result(false))(f)(n - 2)())
const fib = ({resultCombination, cacheResult, memoize, fib2}) => cache => n => n === 1 || n === 2
@blackakula
blackakula / browser.js
Created April 4, 2018 00:24
Browser window document width and height (very little piece of code, that saved my life)
const maxElementProperty = (element, ...properties) => Math.max(
0,
...properties.map(property => element ? element[property] : 0)
);
const realSize = (...documentElementProps) => (...bodyProps) => Math.max(
0,
maxElementProperty(document.documentElement, ...documentElementProps),
maxElementProperty(document.body, ...bodyProps)
);