Skip to content

Instantly share code, notes, and snippets.

View paveltretyakovru's full-sized avatar
🐯
Om 🔱

Pavel Tretyakov paveltretyakovru

🐯
Om 🔱
  • St.-Petersburg (Russia)
View GitHub Profile
@paveltretyakovru
paveltretyakovru / update-angular-form-array.ts
Last active March 3, 2019 19:10
Dinamic updating Angular FormArray fields on FormGroup
getService(): void {
const id = parseInt(this._route.snapshot.params['id']);
if (id && id > 0) {
this.indLoading = true;
this._restService.getById('/api/serviceapi/, id).subscribe(
resp => {
// get form array reference
const staffs = this.serviceFrm.get('Staffs') as FormArray;
// empty form array
while (staffs.length) {
@paveltretyakovru
paveltretyakovru / trust-innert-html.ts
Created March 13, 2019 22:46
Allow html properties when using angular [innerHtml] property on the tempate
import { BrowserModule, DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'my-app',
template: `
<div [innerHtml]="html"></div>
`,
})
export class App {
constructor(private sanitizer: DomSanitizer) {
@paveltretyakovru
paveltretyakovru / detach-dynamic-component.ts
Created March 13, 2019 22:50
Creating Angular dynamic component with detaching data
export class ValidationMessageDirective implements AfterViewInit, OnDestroy {
private validationMessageComponent: ComponentRef<ValidationMessageComponent> = null;
ngAfterViewInit(): void {
let factory = this.componentFactoryResolver.resolveComponentFactory(this.vmComp);
this.ngOnDestroy();
this.validationMessageComponent = this.viewContainer.createComponent(factory, null, this.viewContainer.injector);
this.validationMessageComponent.changeDetectorRef.detectChanges();
}
@paveltretyakovru
paveltretyakovru / jquery-check-to-scroll-and-scroll-to-element.js
Created July 9, 2019 07:36
Проверить существует ли прокрутка сайта, если да, то прокрутить страницу до элемента
if ($(document).height() > $(window).height()) {
$([document.documentElement, document.body]).animate({
scrollTop: $("#certificate-info h2").offset().top
}, 2000);
}
@paveltretyakovru
paveltretyakovru / .vimrc
Last active September 30, 2022 13:05
vimrc configuration file
" Tabulation highlights syntax
set tabstop=2
set shiftwidth=2
set smarttab
set expandtab " Copy current line tabs to new line
set smartindent " ...like a expandtab but it adding {} tabs
" ========================= Short keys settings" ==============================
" NERDTree
map <silent> <C-b> :NERDTreeToggle<CR> " NERDTree toggle
@paveltretyakovru
paveltretyakovru / add-root-user.sql
Created October 6, 2019 16:16
Create user with root privilegies
# mysql -u root -p
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'some_very_complex_password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
@paveltretyakovru
paveltretyakovru / make-nvm-sude.sh
Created April 8, 2020 21:34
Script to fix "sudo npm install ..." - "npm is not comand" when node installed with using NVM
n=$(which node); \
n=${n%/bin/node}; \
chmod -R 755 $n/bin/*; \
sudo cp -r $n/{bin,lib,share} /usr/local
@paveltretyakovru
paveltretyakovru / get-ips.js
Created April 14, 2020 14:07
Script to print current network interfaces and their ip addressess
'use strict';
var os = require('os');
var ifaces = os.networkInterfaces();
module.exports = () => {
const result = [];
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0;
@paveltretyakovru
paveltretyakovru / chocolatey-packages.bat
Created May 7, 2020 14:40
Fullstack developer windows bat script to install chocolatey packages
choco install --yes robo3t
@paveltretyakovru
paveltretyakovru / config-overrides.js
Last active June 26, 2021 16:36
To move CRA application to other directory than src (for example to src/frontend folder)
const path = require('path');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
module.exports = {
paths: function (paths, env) {
paths.appIndexJs = path.resolve(__dirname, 'src/frontend/index.js');
paths.appSrc = path.resolve(__dirname, 'src/frontend');
return paths;
},