Skip to content

Instantly share code, notes, and snippets.

View mysteriousHerb's full-sized avatar
😛
Learning!

Tian Z mysteriousHerb

😛
Learning!
  • Cambridge
  • Cambridge
View GitHub Profile
@mysteriousHerb
mysteriousHerb / cloudSettings
Last active December 28, 2020 21:41
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-12-28T21:41:20.271Z","extensionVersion":"v3.4.3"}
def merge(lefthalf, righthalf):
i=j=0
sorted_list = []
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
sorted_list.append(lefthalf[i])
i=i+1
else:
sorted_list.append(righthalf[j])
@mysteriousHerb
mysteriousHerb / todo_comp.vue
Last active June 2, 2019 18:22
todo_comp template part
<template>
<div id="todos-vue">
<div>
<label>New task:</label>
<!-- use v-model for 2-way binding, call method when user press enter @keyup.enter-->
<input id="new_todo" v-model="new_todo" placeholder="edit me" @keyup.enter="add_todo()">
<button @click="add_todo()">Add</button>
</div>
<div>
<div v-for="(todo, index) in todos" :key="todo.id">
@mysteriousHerb
mysteriousHerb / todo_comp.vue
Last active June 2, 2019 18:21
todo_comp script part
<script>
export default {
name: "todo_comp",
data: function() {
return {
new_todo: "",
todos: [
{ id: 1, content: "write paper", done: false },
{ id: 2, content: "read paper", done: false },
{ id: 3, content: "review paper", done: false }
@mysteriousHerb
mysteriousHerb / todo.vue
Last active June 2, 2019 19:19
src/views/todo.vue
<template>
<div class="todo">
<todo_comp/>
</div>
</template>
<script>
// @ is an alias to /src
import todo_comp from '@/components/todo_comp.vue'
@mysteriousHerb
mysteriousHerb / config.py
Created June 2, 2019 19:52
backend/config.py
import os
class Config(object):
SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'
SECRET_KEY = os.environ.get("SECRET_KEY") or "super-secret-key"
DEBUG = True
CSRF_ENABLED = True
@mysteriousHerb
mysteriousHerb / app.py
Last active June 2, 2019 20:47
backend/app.py
from flask import Flask, render_template, jsonify, request
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Resource, Api
from flask_cors import CORS
# https://flask-marshmallow.readthedocs.io/en/latest/
from flask_marshmallow import Marshmallow
import os
@mysteriousHerb
mysteriousHerb / test_backend.py
Created June 2, 2019 21:10
backend/test_backend.py
import requests
# using requests library to test backend without using frontend
def query():
response = requests.get('http://localhost:5000/todo_db')
print(response.json())
query()
# add new item
@mysteriousHerb
mysteriousHerb / todo_rest.vue
Last active June 2, 2019 22:08
frontend/src/components/todo-rest.vue
<template>
<div id="todos-vue">
<div>
<label>New task:</label>
<!-- use v-model for 2-way binding, call method when user press enter @keyup.enter-->
<input id="new_todo" v-model="new_todo" placeholder="edit me" @keyup.enter="add_todo()">
<button @click="update_todo(id=-1, content=new_todo, done=false, delete_=false)">Add</button>
</div>
<div>
<div v-for="(todo) in todos" :key="todo.id">
@mysteriousHerb
mysteriousHerb / App.vue
Created June 9, 2019 20:43
frontend/src/App.vue
<template>
<div id="app">
<v-app>
<!-- drawer is the section popup from the left-->
<v-navigation-drawer fixed v-model="drawer" app>
<v-list dense>
<!-- use a v-for to automatically generate -->
<li v-for="route in routes" :key="route.id">
<v-list-tile @click="change_view(route.name)">
<v-list-tile-action>