Skip to content

Instantly share code, notes, and snippets.

@Komock
Komock / view-state.ts
Created September 23, 2021 06:32
View state from BehaviorSubject
export class ViewState<T extends object> extends BehaviorSubject<T> {
constructor(initialState: T) {
super(initialState);
}
patch(newState: Partial<T>) {
this.next({
...this.value,
...newState
});
@Komock
Komock / zone-enter.operator.ts
Created May 20, 2020 07:23
RxJS Operator to pipe into zone
export function enterZone(zone: NgZone) {
return <T>(source: Observable<T>) =>
new Observable<T>(observer =>
source.subscribe({
next: (x) => zone.run(() => observer.next(x)),
error: (err) => observer.error(err),
complete: () => observer.complete()
})
);
}
@Komock
Komock / print-html-element.js
Created May 15, 2020 14:05
Print HTML element by selector
function printElem(selector, width, height) {
const newWindow = window.open('', 'PRINT', `height=${height},width=${width}`);
const element = document.querySelector(selector);
newWindow.document.write(`
<html>
<head>
<title>${document.title}</title>
</head>
<body>${element.innerHTML}</body>
</html>`);
@Komock
Komock / settings.json
Created March 8, 2020 06:20
live Sass Compiler plugin config (should be in .vscode folder)
{
"liveSassCompile.settings": {
"generateMap": false,
"includeItems": [
"./scss/style.scss"
],
"formats":[
{
"format": "expanded",
"extensionName": ".css",
@Komock
Komock / ng-convert-component-to-module.js
Created May 17, 2019 06:37
Node script to convert existing component to module
const path = require('path');
const fs = require('fs');
const APP_MODULES_DIR = 'projects/evo-ui-kit/src/lib/modules';
const APP_COMPONENTS_DIR = 'projects/evo-ui-kit/src/lib/components';
const pascalize = (str) => {
return str
.replace(/\s(.)/g, (s) => s.toUpperCase() )
.replace(/-(.)/g, (s) => s.toUpperCase() )
.replace(/\s/g, '')
@Komock
Komock / columns.scss
Created April 18, 2019 11:01
Simple SCSS Columns Grid Mixin
@mixin gridColumnSizes($params) {
$defaults: (
suffix: '',
base: ''
);
$opts: map-merge($defaults, $params);
$base: map-get($opts, 'base');
$suffix: map-get($opts, 'suffix');
$bs: if($base == '', '', $base + '__');
$sf: if($suffix == '', '_', '_' + $suffix + '-');
@Komock
Komock / wp-domain-name-change.sql
Created September 24, 2018 15:50
Change domain name in WP database
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@Komock
Komock / some.ts
Last active September 21, 2018 14:49
some
private handleConfirmationSuccess(methodId: string) {
this.paymentsService.pollPaymentMethodCreated(methodId).pipe(
mergeMap(methodId => this.paymentsService.setDefaultPaymentMethod(methodId)),
mergeMap(methodId => forkJoin(of(methodId), this.paymentsService.fetchPaymentMethods())),
tap((data) => {
const id = data[0];
this.paymentsService.paymentMethods.defaultMethod = this.paymentsService.paymentMethods.getPaymentMethod(id);
this.routerDataStorage.set({ paymentMethodCreated: PaymentGatewayTypes.CARD });
this.router.navigate(['../../../'], {
relativeTo: this.route,
//==== User ====//
createUser(body, scenario = 'preliminary') {
return window.fetch(`${API_DOMAIN}user/create?access-token=${API_TOKEN}&scenario=${scenario}`, {
method: 'POST',
headers: new Headers({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
.then(res => res.json());
}
@Komock
Komock / get-value-by-string-path.js
Created June 14, 2018 09:22
Get value by string path
const some = {a: { bc: { de: 'hello'}}};
const path = 'a.bc.de';
let result = Object.assign({}, some);
path.split('.').forEach( part => {
console.log(result);
result = result[part];
});
console.log(result);