Skip to content

Instantly share code, notes, and snippets.

@Komock
Komock / integerToPrice.js
Created October 2, 2016 18:31
Format Integer to Price with Space (usefull for rubles)
// Price Format
function formatNum(num){
var num = num + '',
arr = num.split(''),
arrCopy = arr.slice(0),
j = 0;
for(var i = arr.length -1 ; i >= 0; i--){
if ( j % 3 === 0 && j !== 0 ) {
arrCopy.splice( i + 1, 0, ' ' );
}
@Komock
Komock / observer.js
Last active September 11, 2019 20:36
Simple ES6 Observer Class
class Observer {
subscribe(subscriber) {
this.subscribers.push(subscriber);
}
publish(event, data) {
let query = this.subscribers.filter(subscriber => subscriber.event === event);
if (query.length) query.forEach(subscriber => subscriber.action(data));
}
constructor() {
this.subscribers = [];
@Komock
Komock / overflow-scrolling.css
Created November 2, 2017 07:06
Off scroll stop on mobile devices
body {
-webkit-overflow-scrolling: touch;
}
@Komock
Komock / function.php
Created April 11, 2018 13:44
Remove Sidebars from Genesis Child Theme
// Remove default genesis sidebars
remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
remove_action( 'genesis_after_content_sidebar_wrap', 'genesis_get_sidebar_alt');
@Komock
Komock / fetch-with-wp-nonce.js
Created May 18, 2018 07:14
Submit form with wp-nonce token using fetch
const formEl = document.querySelector('.form-profile-upd');
formEl.addEventListener('submit', e => {
e.preventDefault();
const data = new FormData(formEl);
const id = window.WP_DATA.USER_ID;
console.log(data.get('birthday'));
fetch(`${WP_DATA.ROOT_URL}wp/v2/users/` + id, {
method: 'POST',
credentials: 'same-origin',
body: {
@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);
//==== 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 / 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,
@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 / 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 + '-');