Skip to content

Instantly share code, notes, and snippets.

View ryan2clw's full-sized avatar

Ryan Dines ryan2clw

  • Tampa, FL
View GitHub Profile
@ryan2clw
ryan2clw / models.py
Created August 17, 2019 12:33
Model for card data
""" Generates SQL tables for Cards and Rows """
from django.db import models
class Card(models.Model):
""" A bingo card with 5 rows. """
created_on = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "Card: " + str(self.id) + ", " + str(self.created_on)
@ryan2clw
ryan2clw / views.py
Created August 17, 2019 12:56
Endpoints for creating and requesting cards
""" These are endpoints that get or create cards and rows """
from rest_framework import generics
from play.models import Card
from play.serializers import CardSerializer
class CardList(generics.ListCreateAPIView):
""" Get or create cards """
queryset = Card.objects.all()
serializer_class = CardSerializer
@ryan2clw
ryan2clw / index.html
Created August 17, 2019 13:32
The entry point of the python bingo app
<head>
<!-- keep the old stuff -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<head>
<!-- keep the old stuff -->
<footer class="text-center pt-3">
<p class="d-flex flex-row justify-content-center">
<a href="https://medium.com/@ryan.dines" target="_top">Brought to you with
<span class="fa fa-heart crimson"></span>
by Ryan Dines
@ryan2clw
ryan2clw / App.css
Created August 18, 2019 19:14
Bingo css
.ticket-number {
margin: 1px;
color: black;
background: #defffd;
}
.called {
transition: all .5s ease-in-out;
background: #076461;
color:white;
}
@ryan2clw
ryan2clw / models.py
Created August 19, 2019 01:23
Added balls to model
# keep Card and Row models from before
class Ball(models.Model):
"""
The ball in a ball-blower. Represents a random number 1-75.
"""
num_value = models.CharField(max_length=3)
updated_at = models.DateTimeField(auto_now=True)
class MatchSmiley(models.Model):
""" Derived from card data, each column is a number on a specific card"""
@ryan2clw
ryan2clw / models.py
Created August 19, 2019 16:05
Models for bingo
"""
We have 4 models that interact with each other to form the game play.
The card and row tables will form the data for the bingo cards.
The match_smiley table is populated from the card/row tables, where each column is a certain number on the card,
so the row would be the group of numbers that make a smiley-face.
We'll decrement the 'left' property of match_smiley as balls are called that match.
"""
from django.db import models
# keep Card and Row models from before
@ryan2clw
ryan2clw / 0007_auto_some_date.py
Created August 19, 2019 16:24
data migration
# Generated by Django 2.2.4 on 2019-08-19 15:30
from django.db import migrations
def seed_database(apps, _):
""" Seed the ball numbers into the database """
balls = apps.get_model('play', 'Ball')
balls.objects.all().delete()
for i in range(1, 76):
data = {
@ryan2clw
ryan2clw / urls.py
Created August 20, 2019 12:59
Play bingo urls
""" urls for playing bingo """
from django.urls import path
from play.views import CardList, BallList, reset_balls
urlpatterns = [
path('cards/', CardList.as_view(), name='cards'),
path('balls/', BallList.as_view(), name='balls'),
path('reset_balls/', reset_balls, name='reset_balls')
]
@ryan2clw
ryan2clw / BingoPage.tsx
Last active August 23, 2019 17:40
Start of bingo page
import * as React from 'react'
import styled from 'styled-components';
import { connect } from 'react-redux';
// tslint:disable-next-line: no-submodule-imports
import 'bootstrap/dist/css/bootstrap.css';
import { Flex } from 'rebass';
import { Container, Row } from 'reactstrap';
import { IApplicationState, IConnectedReduxProps } from '../store/configureStore';
import { danger, clear } from '../store/messages';
@ryan2clw
ryan2clw / tslint.json
Last active August 23, 2019 17:43
tslint config
{
"defaultSeverity": "error",
"extends": [
"tslint-react"
],
"jsRules": {
},
"rules": {
"member-access": false,
"ordered-imports": false,