Skip to content

Instantly share code, notes, and snippets.

View pokidovea's full-sized avatar
🙃

Eugene Pokidov pokidovea

🙃
View GitHub Profile
@gregkorossy
gregkorossy / semaphore.js
Last active September 15, 2023 08:08
A simple implementation of a semaphore in JS
function Semaphore(max) {
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
let promise = waiting.shift();
promise.resolve();
}
@pokidovea
pokidovea / date_matches_crontab.sql
Last active March 18, 2020 09:17
Stored Postgresql function to check, that given date matches crontab with 7 positions (s, m, h, d, m, dow, year).
CREATE OR REPLACE FUNCTION check_value_in_bounds(v int, min_v int, max_v int) RETURNS void AS $$
-- Checks if v is in bounds, else throws exception
BEGIN
IF v > max_v THEN
RAISE EXCEPTION 'value too high: % > %', v, max_v;
END IF;
IF min_v > v THEN
RAISE EXCEPTION 'value too low: % < %', v, min_v;
END IF;
@pgolding
pgolding / scan.py
Created June 5, 2017 19:40
scan all elements from a dynamodb table using Python (boto3)
from __future__ import print_function # Python 2/3 compatibility
import boto3
import json
import decimal
from boto3.dynamodb.conditions import Key, Attr
# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
@nskeip
nskeip / yandex_email_for_domain_settings.py
Last active February 23, 2024 15:03
Django SMTP settings for yandex_for_domain mail (pdd.yandex.ru)
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
@jterrace
jterrace / gist:1823320
Created February 14, 2012 03:42
Automatically log in user after django-registration activation
from registration.signals import user_activated
from django.contrib.auth import login, authenticate
def login_on_activation(sender, user, request, **kwargs):
"""Logs in the user after activation"""
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
# Registers the function with the django-registration user_activated signal
user_activated.connect(login_on_activation)
@kousha789123
kousha789123 / profile_picture_django_social_auth
Created January 23, 2012 12:39
Extending User class to save profile picture in django-social-auth when registering
# This is models.py for a new user profile that you would like to create.
"""
this gist gets an id from django-social-auth and based on that saves the photo from social networks into your model. This is one of the best ways to extend User model because this way, you don't need to redefine a CustomUser as explained in the doc for django-social-auth. this is a new implementation based on https://gist.github.com/1248728
"""
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import models