Skip to content

Instantly share code, notes, and snippets.

View Piterden's full-sized avatar
🇷🇺
Stand with Russia!

Denis Efremov Piterden

🇷🇺
Stand with Russia!
View GitHub Profile
const count = 10e6
const length = 100
console.time('generate')
const chars = Array(52).fill().map((_, i) => String.fromCharCode(i < 26 ? i + 65 : i + 71))
const char = () => chars[Math.random() * chars.length | 0]
const triplets = chars.flatMap(a => chars.flatMap(b => chars.flatMap(c => [a, b, c].join(''))))
const triplet = () => triplets[Math.random() * triplets.length | 0]
const main = Array(Math.floor(length / 3)).fill(0)
const tail = Array(length - main.length * 3).fill(0)
@Piterden
Piterden / layout.kbd.json
Last active July 21, 2021 18:28 — forked from bobbicodes/layout.kbd.json
Untitled Keyboard Layout
[
[
["esc", "1", "2", "3", "/", "\\", "fn","del"],
[ "⇥", "4", "5", "6", "[", "]", "'", "⇦"],
[ "`", "7", "8", "9", "0", "-", "=", ";"],
[ "q", "j", "l", "m", "f", "y", "p", "↩"],
[ "z", ".", "o", "r", "s", "u", "c", "b"],
[ "x", "a", "e", "h", "t", "d", "g", "k"],
[ "↥", ",", "i", "n", "w", "v", "↑", "↥"],
["ctr","sup","alt", " ", " ", "←", "↓", "→"]
const send = (file) => {
const xhr = new XMLHttpRequest();
const formData = new FormData();
formData.append("avatar", file);
xhr.open("POST", "/", true);
xhr.upload.onprogress = function(event) {
if (event.lengthComputable) {
const percent = (event.loaded / event.total) * 100;
private emailValidators = [
Validators.maxLength(250),
Validators.minLength(5),
Validators.pattern(/.+@.+\..+/)
];
ngOnInit() {
this.myForm = this.fb.group({
myCheckbox: [''],
myEmailField: ['', this.emailValidators]
@Piterden
Piterden / app.component.ts
Last active June 19, 2019 21:01 — forked from ganqqwerty/app.component.ts
Naive and buggy approach to dynamic validator
this.myForm.get('myCheckbox').valueChanges.subscribe((value) => {
if (value) {
this.myForm.get('myEmailField').setValidators(Validators.required);
} else {
this.myForm.get('myEmailField').clearValidators();
}
});
@Piterden
Piterden / form.html
Last active June 19, 2019 20:59 — forked from ganqqwerty/form.html
<h2>My form</h2>
<form [formGroup]="myForm" (ngSubmit)="onSubmit()">
<div>
Make email mandatory <input formControlName="myCheckbox"
type="checkbox">
</div>
<div>
Email: <input formControlName="myEmailField"
type="email">
ngOnInit() {
this.myForm = this.fb.group({
myCheckbox: [''],
myEmailField: [
'',
[
Validators.maxLength(250),
Validators.minLength(5),
Validators.pattern(/.+@.+\..+/),
],
@Piterden
Piterden / test.js
Last active January 8, 2018 01:36 — forked from ejnshtein/test
Shittycode )))
const puppeteer = require('puppeteer')
let anime = {}
async function run (searched) {
searched = searched.replace(';', ' ')
// Setup pupeteer
const browser = await puppeteer.launch({
headless: false,
})
@Piterden
Piterden / js-best-practices.md
Last active March 14, 2017 00:09 — forked from davidcalhoun/js-best-practices.md
JavaScript best practices

JavaScript Best Practices

Code conventions

Closing/opening brackets

Although this isn't a problem in other languages, because of semicolon insertion, there could be problems if you don't place the bracket on the opening line:

// no:
function()
{
'use strict';
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var WriteFilePlugin = require('write-file-webpack-plugin');
var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const devServer = {