Skip to content

Instantly share code, notes, and snippets.

View eugena's full-sized avatar
💭
🤸🏽

Eugena Mikhaylikova eugena

💭
🤸🏽
View GitHub Profile
@eugena
eugena / yandex_icon .svg
Created June 10, 2021 00:49
New Yandex Icon in SVG Format
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@eugena
eugena / fenwick_tree_for_max.py
Created October 9, 2017 09:08
Fenwick Tree for Maximum
class FenwickTreeMax(object):
"""
Fenwick Tree for Max
"""
def __init__(self, nums):
"""
Initialize tree
"""
self.n = len(nums)
self.left = [0] * (self.n + 1)
@eugena
eugena / trie_em.py
Created October 9, 2017 08:53
Trie with End marker
class Trie(object):
"""
Trie with End marker
"""
END = '_end_'
current = dict()
def add(self, word):
"""
Adds a word to Trie
@eugena
eugena / drf_update_of_request_data.py
Last active January 13, 2016 12:29
Django REST framework. Update of request.data
class SomeViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet):
def update(self, request, *args, **kwargs):
if request.data:
request._full_data = request._full_data.copy()
request._full_data['some key'] = 'some new value'
return super(SomeViewSet, self).update(request, *args, **kwargs)
@eugena
eugena / djrill_send_message_with_template.py
Last active December 17, 2015 12:48
Send email via Mandrill using Django and Mandrill template (djrill is required)
from django.core.mail import EmailMessage
msg = EmailMessage(to=['[email protected]', ])
msg.template_name = 'template'
msg.global_merge_vars = {
'var1': 'value1',
'var2': 'value2',
}
@eugena
eugena / gcm_push_notification.py
Created December 17, 2015 12:40
GCM push notification with title
from push_notifications.models import GCMDevice
device = GCMDevice.objects.get(registration_id='...')
device.send_message('This is a message', extra={"title": "This is a title"})
import hashlib
from django.conf import settings
class EmailVerificationTokenGenerator(object):
"""
Strategy object used to generate and check tokens for the email
verification mechanism.
"""
@eugena
eugena / csrf_exempt_authentication.py
Created November 12, 2015 10:46
SessionAuthentication without csrf token check
from rest_framework.authentication import SessionAuthentication
class CsrfExemptSessionAuthentication(SessionAuthentication):
"""
SessionAuthentication without csrf token check
"""
def enforce_csrf(self, request):
"""
Not performing csrf token check
@eugena
eugena / hybrid_field.py
Created November 10, 2015 11:08
Writable hybrid of PrimaryKeyRelated and SerializerMethod Fields
from rest_framework import serializers
class HybridPrimaryKeyRelatedAndSerializerMethodField(serializers.PrimaryKeyRelatedField):
"""
PrimaryKeyRelatedField & SerializerMethodField
"""
def __init__(self, method_name=None, **kwargs):
self.method_name = method_name
super(HybridPrimaryKeyRelatedAndSerializerMethodField, self).__init__(**kwargs)
@eugena
eugena / gocardless.view.py
Created November 10, 2015 10:49
GoCardlessMixin
from django.conf import settings
import gocardless_pro
class GoCardless(object):
"""
GoCardless wrapper
"""
def __init__(self):
self.client = gocardless_pro.Client(