Skip to content

Instantly share code, notes, and snippets.

import nox
@nox.session
@nox.parametrize("flask", ["0.12.4", "1.0.2"])
@nox.session(python=["2.7", "3.6"])
def lint(session):
session.install(f"flask=={flask}")
session.install("-r", "requirements.txt")
session.run('pytest')
def deploy(ctx):
pull_result = ctx.run("git pull")
if is_task_file_changed(pull_result):
sys.exit("Pyinvoke task file(s) is changed. Please re-run this task.")
ctx.run("pip install -r requirements.txt")
ctx.run("python manage.py makemigrations")
ctx.run("python manage.py migrate")
ctx.run("python manage.py collectstatic --noinput")
# Reload application.
ctx.run("touch ../reload")
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/path/to/my.cnf',
},
}
}
async def application(scope, receive, send):
event = await receive()
...
await send({"type": "websocket.send", ...})
from some_asgi_library import AmazingMiddleware
application = AmazingMiddleware(application)
def get_hits_on_name(name):
"""
Accepts a `name` of a mathematician and returns the number
of hits that mathematician's Wikipedia page received in the
last 60 days, as an `int`
"""
# url_root is a template string that is used to build a URL.
url_root = 'URL_REMOVED_SEE_NOTICE_AT_START_OF_ARTICLE'
response = simple_get(url_root.format(name))
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Login Demo Asap',
theme: new ThemeData(
@joaquinacuna
joaquinacuna / graphQLConf.dart
Created November 3, 2020 20:38
GraphQL dart configuration file
import "package:flutter/material.dart";
import "package:graphql_flutter/graphql_flutter.dart";
class GraphQLConfiguration {
static HttpLink httpLink = HttpLink(
uri: "http://127.0.0.1:8000/graphql",
);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
@joaquinacuna
joaquinacuna / queryMutation.dart
Created November 3, 2020 20:55
Query mutation to register a new user
class QueryMutation {
String register(String email, String user, String password){
return """
mutation {
register(
email: "$email",
username: "$user",
password1: "$password",
password2: "$password",
) {
import 'package:flutter/material.dart';
import "package:graphql_flutter/graphql_flutter.dart";
import 'graphQLConf.dart';
import 'queryMutation.dart';
GraphQLConfiguration graphQLConfiguration = GraphQLConfiguration();
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp( GraphQLProvider(
client: graphQLConfiguration.client,