Skip to content

Instantly share code, notes, and snippets.

@okomarov
okomarov / tangled.graphql
Last active November 5, 2023 20:44
Tangled schema
type User {
id: ID!
username: String!
email: String!
profile: Profile
settings: Settings
}
type Profile {
id: ID!
@okomarov
okomarov / waitlist.html
Created November 11, 2019 14:05
viral queue share button actions
<a class="fas fa-envelope" href="mailto:?subject=Trade like a pro&body=This is neat!%0A%0AGet Mega Duper App.%0A%0APlease sign up with my link: {{ url }}%26channel=email"></a>
<a class="fab fa-facebook-f" href="https://www.facebook.com/sharer.php?u={{ url }}%26channel=facebook"
data-share-url="https://www.facebook.com/sharer.php?u={{ url }}%26channel=facebook" onclick="javascript:window.open(this.getAttribute('data-share-url'), '_blank', 'width=800,height=500');return false;"></a>
<a class="fab fa-facebook-messenger" href="fb-messenger://share/?link={{ url }}%26channel=fb_messenger"
data-share-url="fb-messenger://share/?link={{ url }}%26channel=fb_messenger" onclick="javascript:window.open(this.getAttribute('data-share-url'), '_blank', 'width=800,height=500');return false;"></a>
<a class="fab fa-whatsapp" href="whatsapp://send?text=Get+Mega+Duper+App%3A+{{ url }}%26channel=whatsapp"
data-share-url="whatsapp://send?text=Get+Mega+Duper+App%3A+{{ url }}%26channel=whatsapp"
onclick="javascript:window.open
@okomarov
okomarov / index.html
Last active November 11, 2019 13:59
viral queue og tags
<head>
{% set title="Your page title goes here"%}
{% set description="Some description if you wish."%}
<!-- Social sharing tags -->
<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ description }}">
<meta property="og:image" content="{{ url_for('static', filename='img/social-sharing-thumbnail.png', _external=True) }}">
<meta property="og:url" content="{{ url_for('main.index', _external=True) }}">
<meta name="twitter:card" content="summary_large_image">
@okomarov
okomarov / index.html
Last active November 11, 2019 12:11
viral queue flask form in the waitlist
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row justify-content-center pt-2">
{% if referring_uuid %}
<form action="{{ url_for('main.index') + '?user=' + referring_uuid }}" method="post" class="form-inline">
{% else %}
<form action="{{ url_for('main.index') }}" method="post" class="form-inline">
@okomarov
okomarov / forms.py
Last active November 10, 2019 12:15
viral queue email form
class EmailForm(FlaskForm):
email = EmailField('Email', validators=[DataRequired(), Email()])
submit = SubmitField('Get early access')
@okomarov
okomarov / utils.py
Created November 10, 2019 11:25
viral queue email normalization
def normalize_email(email):
'''
Reduces an email address to its canonical form:
- strips white space
- transforms to lowercase
- removes the +tag part in the name
- removes dots if a google domain
'''
email = email.strip().lower()
name, domain = email.rsplit('@', 1)
@okomarov
okomarov / models.py
Created November 10, 2019 10:46
viral queue referrals model
referrals = db.Table(
'referral',
db.Column('referring', db.String(8), db.ForeignKey('waitlist.uuid')),
db.Column('referred', db.String(8), db.ForeignKey('waitlist.uuid')),
db.PrimaryKeyConstraint('referring', 'referred', name='referrals_pk')
)
@okomarov
okomarov / logic.py
Created November 10, 2019 10:33
viral queue verify email and refer logic
def verify_email(token):
payload = utils.decode_jwt_token(token)
user = get_user(payload['user_id'])
if user is None:
return
if not user.email_confirmed:
user.email_confirmed = True
now = datetime.now(timezone.utc)
user.email_confirmed_on = now
@okomarov
okomarov / logic.py
Last active November 15, 2019 15:27
Get waitlist position
def get_waitlist_position(uuid):
waitlist_user = get_waitlist_user(uuid)
score = waitlist_user.score
users_ahead = Waitlist.query.filter(Waitlist.score <= score).count()
return max(score, users_ahead)
@okomarov
okomarov / models.py
Last active November 13, 2019 12:41
Viral queue waitlist and referrals
class Waitlist(BaseModel, db.Model):
__tablename__ = 'waitlist'
initial_score = 65231
decrease_per_referral = 10
uuid = db.Column(db.String(8), primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
user = db.relationship('User', back_populates='waitlist')
score = db.Column(db.Integer)