Skip to content

Instantly share code, notes, and snippets.

View prudnikov's full-sized avatar

Vladimir Prudnikov prudnikov

View GitHub Profile
@prudnikov
prudnikov / control-validity-class.directive.ts
Created December 31, 2019 01:03
This directive will automatically add `is-valid` or `is-invalid` class to the form controls depending on its validity status #angular
import { Directive, ElementRef, HostBinding, OnDestroy, OnInit } from '@angular/core';
import { AbstractControl, NgControl } from "@angular/forms";
import { Subscription } from "rxjs";
@Directive({
selector: '[formControl], [formControlName]',
})
export class ControlValidityClassDirective implements OnInit, OnDestroy {
@HostBinding('class.is-valid')
isValid = true;
@prudnikov
prudnikov / atomic_viewsets.py
Created December 17, 2019 09:55
Django Rest Framework Atomic ViewSet and Mixin.
from django.db import transaction
from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet
__all__ = ['AtomicCreateModelMixin', 'AtomicUpdateModelMixin', 'AtomicDestroyModelMixin',
'AtomicModelViewSetMixin', 'AtomicModelViewSet']
class AtomicCreateModelMixin(mixins.CreateModelMixin):
@prudnikov
prudnikov / test.py
Created August 9, 2013 15:32
Compare performance of `pickle`, `json` and MessagePack
import msgpack
import time
import json
import pickle
l = [1,2,3]
l_packed = msgpack.packb(l)
l_json = json.dumps(l)
l_pickle = pickle.dumps(l)
#import <Foundation/Foundation.h>
@interface NSString (Additions)
- (NSString *)stringByReplacingSubstringsAtRanges:(NSArray *) rangeValues
withStrings:(NSArray *)strings;
@end