Skip to content

Instantly share code, notes, and snippets.

View CryceTruly's full-sized avatar
🎯
Focusing

cryce truly CryceTruly

🎯
Focusing
View GitHub Profile
@CryceTruly
CryceTruly / test_core.py
Last active February 14, 2019 13:11
Simple DJANGO rest api test
import json
from rest_framework.test import APIClient
class TestClass():
def setUp():
self.client = APIClient()
self.register_url=reverse('authentication:register')
def test_create_user(self):
"""Tests if a user can create an account"""
valid_register_data = {
'user': {

What does this PR do?

Description of Task to be completed?

How should this be manually tested?

Any background context you want to provide?

What are the relevant pivotal tracker stories?

@CryceTruly
CryceTruly / pipenv.md
Last active February 25, 2019 05:29
pipenv cheetsheet

Pipenv Cheat Sheet

Install pipenv

pip3 install pipenv

Activate

pipenv shell
@CryceTruly
CryceTruly / titles.ts
Last active July 26, 2019 08:07
Setting dynamic page titles in an angular 2+ app.
Step 1 #Provide a title in the route configuration,Usually in the app.module.ts
{ path: '', component: HomeComponent, data: { title: 'welcome' } },
Step 2 #import {ActivatedRoute } from '@angular/router';
Step 3 #Inject the ActivatedRoute interface in the constructor of your component:
constructor(private router:ActivatedRoute) { }
Step 4,#Subscribe to the data observable and pull out your data variables,use them for what you want.
ngOnInit() {
@CryceTruly
CryceTruly / flaskmail.py
Last active July 26, 2019 08:10
A basic flask mail snippet
from flask_mail import Mail, Message
from flask import Flask
app = Flask(__name__)
app.config.update(
DEBUG=True,
#EMAIL SETTINGS
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USERNAME = 'your email',
[
{
"name":"Afghanistan",
"code":"AF",
"continent":"Asia",
"filename":"afghanistan"
},
{
"name":"Åland Islands",
"continent":"Europe",
from django.http import JsonResponse
def error_404(request, exception):
message = ("The endpoint you are trying to access might "
"have been removed, "
"had its name changed, or is temporarily unavailable. "
"Please check the documentation here : "
"/ docs and try again later.")
response = JsonResponse(data={"message": message, 'status_code': 404})
from rest_framework.views import exception_handler
from rest_framework import status
from django.http import Http404
def custom_exception_handler(exc, context):
"""
This function will handle errors that are returned by
the different views.
The `handlers` dictionary will map
import React, { useState } from "react";
import "./App.css";
function App() {
const [form, setForm] = useState([]);
const [submitted, setFormSubmitted] = useState(false);
const someEmpty = form.some(
(item) => item.Platform === "" || item.Username === ""
);
@CryceTruly
CryceTruly / autoheight.js
Created November 1, 2020 19:22
react input component with dynamic height
import React, { useState } from "react";
import "./style.css";
const DynamicHeightInput = () => {
const [textareaHeight, setTextareaHeight] = useState(42);
const [formValue, setFormValue] = useState({});
const onChange = (event) => {
event.preventDefault();
event.persist();