Skip to content

Instantly share code, notes, and snippets.

View ceoro9's full-sized avatar
:octocat:
wth'ma I doin'

Roman ceoro9

:octocat:
wth'ma I doin'
  • Minsk, Belarus
View GitHub Profile
@ceoro9
ceoro9 / .jshintrc
Created October 8, 2017 17:04
JavaScript JSHint configuration
{
"esnext": true,
"forin": true,
"es5": false,
"curly": true,
"eqeqeq": false,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
@ceoro9
ceoro9 / minValueSubSection.cpp
Created October 28, 2017 11:07
minimum value on sub-section
#include <iostream>
#define INF 2147483647
using namespace std;
const int N = 8;
int a[N] = {4,5,-4,3,-4,-20,4,-5};
int main() {
int ans = -INF,
@ceoro9
ceoro9 / persistence.xml
Created December 13, 2017 15:04
Local mysql persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="bookChange" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class></class>
<properties>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.user" value="ceoro9"/>
@ceoro9
ceoro9 / persistence.xml
Created December 13, 2017 15:07
RAM derby db for fast check
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="bookChange" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class></class>
<properties>
@ceoro9
ceoro9 / custom_user.py
Created February 2, 2018 21:52
Custom User model with additional fields
# models.py (app registration)
from django.contrib.auth.models import AbstractUser
from django.db import models
class CoffeehouseUser(AbstractUser):
age = models.IntegerField(blank=True,null=True)
telephone = models.CharField(max_length=15,blank=True,null=True)
#...
# admin.py (app registration)
@ceoro9
ceoro9 / user_creation_form.py
Created February 3, 2018 08:57
Create custom form for signup using UserCreationForm
class myUserCreationForm(UserCreationForm):
#additional fields
class Meta:
model = User
fields = ('username', 'password1', 'password2')
def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
#set classes for css
#!/usr/bin/python3.6
import redis
import threading
class Listener(threading.Thread):
def __init__(self, r, channels):
super(Listener, self).__init__()
self.redis = r
self.pubsub = self.redis.pubsub()
self.pubsub.subscribe(channels)
@ceoro9
ceoro9 / check_pass.py
Created February 10, 2018 12:37
Fetch all password validators and check password
def get_default_password_validators():
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
def get_password_validators(validator_conf):
"""
import all password validators modules
and raise exception if impossible to import
:param validator_conf:
:return:
"""
@ceoro9
ceoro9 / load.py
Created February 18, 2018 20:53
Example of pre-defined data before migrarion.
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-01-22 17:31
"""Load data using py and sqlq
...
"""
from __future__ import unicode_literals
from django.db import migrations
@ceoro9
ceoro9 / extra.py
Created March 5, 2018 21:49
Pass extra data to serialize model
class PostSerializer(serializers.ModelSerializer):
field = serializers.SerializerMethodField()
def get_field(self, obj):
return self.obj.context['example]
serialize = PostSerializer(obj, context={'example': 'example'})