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
@Piterden
Piterden / back_forward.js
Last active August 29, 2015 14:25 — forked from sstephenson/back_forward.js
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@Piterden
Piterden / .htaccess
Created April 26, 2016 20:36 — forked from splittingred/.htaccess
Example of how to use new REST server class in MODX 2.3+
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ rest/index.php?_rest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ rest/index.php [QSA,NC,L]
</IfModule>
'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 = {
@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()
{
@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,
})
ngOnInit() {
this.myForm = this.fb.group({
myCheckbox: [''],
myEmailField: [
'',
[
Validators.maxLength(250),
Validators.minLength(5),
Validators.pattern(/.+@.+\..+/),
],
@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">
@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();
}
});
private emailValidators = [
Validators.maxLength(250),
Validators.minLength(5),
Validators.pattern(/.+@.+\..+/)
];
ngOnInit() {
this.myForm = this.fb.group({
myCheckbox: [''],
myEmailField: ['', this.emailValidators]
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;