This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local m = redis.call("ZREVRANGE", ARGV[1], "0", "0", "WITHSCORES"); | |
if m ~= nil and m[2] ~= nil then | |
local max_priority = m[2] | |
local a = redis.call("ZRANGEBYSCORE", ARGV[1], max_priority, max_priority); | |
if a ~= nil and #a > 0 then | |
math.randomseed(ARGV[2]) | |
local ad_id = math.random(#a) | |
return redis.call("HGET", "ad:" .. a[ad_id] .. ":attrs", "ad_response"); | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def foo(): | |
print time.ctime() | |
while True: | |
foo() | |
time.sleep(1) | |
#Mon Oct 29 16:54:07 2018 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time, threading | |
WAIT_SECONDS = 1 | |
def foo(): | |
print(time.ctime()) | |
threading.Timer(WAIT_SECONDS, foo).start() | |
foo() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading, time | |
def foo(): | |
print time.ctime() | |
WAIT_TIME_SECONDS = 2 | |
ticker = threading.Event() | |
while not ticker.wait(WAIT_TIME_SECONDS): | |
foo() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading, time, signal | |
from datetime import timedelta | |
WAIT_TIME_SECONDS = 1 | |
class ProgramKilled(Exception): | |
pass | |
def foo(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from timeloop import Timeloop | |
from datetime import timedelta | |
tl = Timeloop() | |
@tl.job(interval=timedelta(seconds=2)) | |
def sample_job_every_2s(): | |
print "2s job current time : {}".format(time.ctime()) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.permissions import BasePermission | |
from rest_framework.view import APIView | |
class IsStaff(BasePermission): | |
def has_permission(self, request, view): | |
return request.user and request.user.is_staff | |
class TestAPIView(APIView): | |
permission_classes = [IsStaff] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# user for the SDK to authenticate | |
sdk_user_email = "sdk@{}.sf".format(business.id) | |
sdk_user = User.objects.create_user(sdk_user_email, sdk_user_email, str(uuid.uuid4())) | |
business.api_key = Token.objects.create(user=sdk_user).key | |
business.save() | |
BusinessTeamMember.objects.create( | |
business= business, | |
user= sdk_user, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## validated_data contains the request data to the invite api | |
user, _ = helpers.get_or_create_user(email=validated_data['email']) | |
user.is_active = False | |
user.save() | |
## business is the object of the business model that is retrieved using the auth token in the header | |
business_team_member, _ = BusinessTeamMember.objects.get_or_create( | |
user=user, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client_user_email = validated_data['email'] | |
try: | |
client_user = User.objects.get(username=client_user_email) | |
except User.DoesNotExist: | |
raise Exception("this email was not invited") | |
client_user.is_active=True | |
client_user.set_password(validated_data['password1']) | |
client_user.save() |
OlderNewer