How to use set_id method in autotest

Best Python code snippet using autotest_python

20200608_153224_create_all_tables.py

Source:20200608_153224_create_all_tables.py Github

copy

Full Screen

1"""create all tables2Revision ID: be0d4210024a3Revises:4C5reate Date: 2020-06-08 15:32:24.3539806"""7from alembic import op8import sqlalchemy as sa9from datetime import datetime10from app.models import db, User, Set, Card11# revision identifiers, used by Alembic.12revision = 'be0d4210024a'13down_revision = None14branch_labels = None15depends_on = None16def upgrade():17 # ### commands auto generated by Alembic - please adjust! ###18 categories_table = op.create_table('categories',19 sa.Column('id', sa.Integer(),20 nullable=False),21 sa.Column('name', sa.String(22 length=50), nullable=False),23 sa.PrimaryKeyConstraint('id'),24 sa.UniqueConstraint('name')25 )26 users_table = op.create_table('users',27 sa.Column('id', sa.Integer(),28 nullable=False),29 sa.Column('email', sa.String(30 length=50), nullable=False),31 sa.Column('nickname', sa.String(32 length=50), nullable=False),33 sa.PrimaryKeyConstraint('id'),34 sa.UniqueConstraint('email')35 )36 sets_table = op.create_table('sets',37 sa.Column('id', sa.Integer(), nullable=False),38 sa.Column('title', sa.String(39 length=51), nullable=False),40 sa.Column('description', sa.Text(),41 nullable=True),42 sa.Column('category_id',43 sa.Integer(), nullable=False),44 sa.Column('user_id', sa.Integer(),45 nullable=False),46 sa.Column('created_at',47 sa.DateTime(), nullable=True),48 sa.ForeignKeyConstraint(49 ['category_id'], ['categories.id'], ),50 sa.ForeignKeyConstraint(51 ['user_id'], ['users.id'], ),52 sa.PrimaryKeyConstraint('id')53 )54 cards_table = op.create_table('cards',55 sa.Column('id', sa.Integer(),56 nullable=False),57 sa.Column('term', sa.String(58 length=100), nullable=False),59 sa.Column('definition', sa.Text(),60 nullable=False),61 sa.Column('set_id', sa.Integer(),62 nullable=False),63 sa.ForeignKeyConstraint(64 ['set_id'], ['sets.id'], ),65 sa.PrimaryKeyConstraint('id')66 )67 favorites_table = op.create_table('favorites',68 sa.Column('id', sa.Integer(),69 nullable=False),70 sa.Column(71 'set_id', sa.Integer(), nullable=False),72 sa.Column(73 'user_id', sa.Integer(), nullable=False),74 sa.ForeignKeyConstraint(75 ['set_id'], ['sets.id'], ),76 sa.ForeignKeyConstraint(77 ['user_id'], ['users.id'], ),78 sa.PrimaryKeyConstraint('id')79 )80 votes_table = op.create_table('votes',81 sa.Column('id', sa.Integer(),82 nullable=False),83 sa.Column('set_id', sa.Integer(),84 nullable=False),85 sa.Column('user_id', sa.Integer(),86 nullable=False),87 sa.Column('is_upvote', sa.Boolean(),88 nullable=True),89 sa.ForeignKeyConstraint(90 ['set_id'], ['sets.id'], ),91 sa.ForeignKeyConstraint(92 ['user_id'], ['users.id'], ),93 sa.PrimaryKeyConstraint('id')94 )95 # Add seeder for users table96 op.bulk_insert(users_table, [97 {98 "nickname": 'Codelet App',99 "email": "codelet.app@gmail.com"100 },101 {102 "nickname": 'Demo User',103 "email": "demo@demo.com"104 },105 {106 "nickname": 'Brandon Tsui',107 "email": "brandon@brandon.com"108 },109 {110 "nickname": 'Lisa Kang',111 "email": "lisa@lisa.com"112 },113 {114 "nickname": 'Chris Talley',115 "email": "chris@chris.com"116 },117 {118 "nickname": 'Lizzie Friedman',119 "email": "lizzie@lizzie.com.com"120 }121 ])122 # Add seeders for categories table123 op.bulk_insert(categories_table, [124 {'name': 'Data Structures'}, # 1125 {'name': 'Algorithms'}, # 2126 {'name': 'Javascript'}, # 3127 {'name': 'Python'}, # 4128 {'name': 'Databases'}, # 5129 {'name': 'Frontend'}, # 6130 {'name': 'Backend'}, # 7131 {'name': 'Other'},132 ])133 # Add seeders for sets table134 op.bulk_insert(sets_table, [135 {136 'title': 'Trees', # 1 Chris137 'description': 'Study tree data structures!',138 'category_id': 1,139 'user_id': 1,140 'created_at': datetime.now()141 },142 {143 'title': 'Graphs', # 2 Lizzie144 'description': 'Learn some graph data structures.',145 'category_id': 1,146 'user_id': 1,147 'created_at': datetime.now()148 },149 {150 'title': 'Linked Lists', # 3 Lisa151 'description': 'Study linked lists data structures',152 'category_id': 1,153 'user_id': 1,154 'created_at': datetime.now()155 },156 {157 'title': 'Algorithm Concepts', # 4 Chris158 'description': 'Study some algorithm concepts.',159 'category_id': 2,160 'user_id': 1,161 'created_at': datetime.now()162 },163 {164 'title': 'Sorting Algorithms', # 5 Brandon √165 'description': 'Learn about different sorting mechanisms.',166 'category_id': 2,167 'user_id': 1,168 'created_at': datetime.now()169 },170 {171 'title': 'Javascript Datatypes', # 6 Lizzie172 'description': 'Study various Javascript datatypes!',173 'category_id': 3,174 'user_id': 1,175 'created_at': datetime.now()176 },177 {178 'title': 'Javascript Syntax', # 7 Brandon179 'description': 'Brush up on some Javascript syntax.',180 'category_id': 3,181 'user_id': 1,182 'created_at': datetime.now()183 },184 {185 'title': 'Python Datatypes', # 8 Chris186 'description': 'Need a refresher on python datatypes? Start here!',187 'category_id': 4,188 'user_id': 1,189 'created_at': datetime.now()190 },191 {192 'title': 'Python Syntax', # 9 Lisa193 'description': 'No semi-colons here! Learn some python syntax!',194 'category_id': 4,195 'user_id': 1,196 'created_at': datetime.now()197 },198 {199 'title': 'SQL', # 10 Lisa200 'description': 'Review some SQL topics!',201 'category_id': 5,202 'user_id': 1,203 'created_at': datetime.now()204 },205 {206 'title': 'Sequelize', # 11 Lizzie207 'description': 'Learn about Sequelize!',208 'category_id': 5,209 'user_id': 1,210 'created_at': datetime.now()211 },212 {213 'title': 'SQLAlchemy', # 12 Lisa214 'description': 'Learn about SQLAlchemy!',215 'category_id': 5,216 'user_id': 1,217 'created_at': datetime.now()218 },219 {220 'title': 'React', # 13 Lisa221 'description': 'A spicy new javascript framework',222 'category_id': '6',223 'user_id': 1,224 'created_at': datetime.now()225 },226 {227 'title': 'Vanilla JS', # 14 Brandon228 'description': 'Good ole\' unadulterated javascript. ',229 'category_id': '6',230 'user_id': 1,231 'created_at': datetime.now()232 },233 {234 'title': 'HTML/CSS', # 15 Lizzie235 'description': 'Learn about the backbones of the world wide web!',236 'category_id': '6',237 'user_id': 1,238 'created_at': datetime.now()239 },240 {241 'title': 'Flask', # 16Brandon242 'description': 'Dive into Flask!',243 'category_id': '7',244 'user_id': 1,245 'created_at': datetime.now()246 },247 {248 'title': 'Node', # 17 Chris249 'description': 'Learn about Node.js!',250 'category_id': '6',251 'user_id': 1,252 'created_at': datetime.now()253 },254 {255 'title': 'Redux', # 18 lizzie256 'description': 'Learn all about the wonders of Redux and how it will rock your world',257 'category_id': '7',258 'user_id': 1,259 'created_at': datetime.now()260 },261 {262 'title': 'Web Storage', # 19 lizzie263 'description': 'cookies for life',264 'category_id': '6',265 'user_id': 1,266 'created_at': datetime.now()267 },268 {269 'title': 'Promises', # 20 lizzie270 'description': 'never make a promise you cant keep...',271 'category_id': '3',272 'user_id': 1,273 'created_at': datetime.now()274 },275 {276 'title': 'Unit Testing', # 21 lizzie277 'description': 'mocha + chai = better than any python testing framework',278 'category_id': '3',279 'user_id': 1,280 'created_at': datetime.now()281 },282 ])283 op.bulk_insert(cards_table, [284 {285 'term': 'Graphs represent _____ relationships between objects',286 'definition': 'pairwise',287 'set_id': 2288 },289 {290 'term': 'a graph is a _____ more than a collection',291 'definition': 'model',292 'set_id': 2293 },294 {295 'term': 'the four basic graph types are',296 'definition': '''1. undirected and unweighted,297 2. undirected and weighted,298 3. directed and unweighted,299 directed and weighted300 ''',301 'set_id': 2302 },303 {304 'term': 'What is adjacency',305 'definition': 'the basic connectedness property of vertices',306 'set_id': 2307 },308 {309 'term': 'WHat kind of graphs have a symmetric matrix',310 'definition': 'Undirected graphs',311 'set_id': 2312 },313 {314 'term': 'When is an index null in a directed list',315 'definition': 'When the index does not point to anything',316 'set_id': 2317 },318 {319 'term': 'Self Loop',320 'definition': 'An edge that links a vertex to itself',321 'set_id': 2322 },323 {324 'term': 'Simple Graph',325 'definition': 'A graph with no self loops',326 'set_id': 2327 },328 {329 'term': 'Directed Graphs',330 'definition': 'Paths must follow the directions of the edges',331 'set_id': 2332 },333 {334 'term': 'Simple Path',335 'definition': 'A path that does not cross the same edge twice',336 'set_id': 2337 },338 {339 'term': 'What is a cycle in a graph',340 'definition': 'It is a simple path that starts and ends at the same vertex',341 'set_id': 2342 },343 {344 'term': 'Acyclic Graph',345 'definition': 'A graph with no cycles',346 'set_id': 2347 },348 {349 'term': 'What is a variable',350 'definition': 'Container for a piece of data',351 'set_id': 6352 },353 {354 'term': 'Are variables case sensitive',355 'definition': 'Yes',356 'set_id': 6357 },358 {359 'term': 'What will an undeclared variable return',360 'definition': 'Undefined',361 'set_id': 6,362 },363 {364 'term': 'Two types of variable scope',365 'definition': 'Local and global',366 'set_id': 6,367 },368 {369 'term': 'Properties of local scope',370 'definition': 'Within a function, only available within a function',371 'set_id': 6,372 },373 {374 'term': 'Properties of Global Scope',375 'definition': 'Outside a function, available to any code outside or within that function',376 'set_id': 6,377 },378 {379 'term': 'What is variable hoisting',380 'definition': 'Variables are hoisted to the top of the function/statement',381 'set_id': 6382 },383 {384 'term': 'Prototype Based',385 'definition': 'Each object has a prototype that inherits properties and abilities from',386 'set_id': 6387 },388 {389 'term': 'Dynamic Typing',390 'definition': 'Dynamic if the type of variable is interpreted at runtime',391 'set_id': 6392 },393 {394 'term': 'First Class Function',395 'definition': 'Treats functions as first class citizens and can do things with functions everything you can do with other elements',396 'set_id': 6397 },398 {399 'term': 'Multi Paradigm Language',400 'definition': 'Supports more than one programming paradigm - devs can work with a variety of styles within js',401 'set_id': 6402 },403 {404 'term': 'DOM',405 'definition': 'Document Object Model',406 'set_id': 6407 },408 {409 'term': 'Two ways to add js to your site',410 'definition': 'Internally and externally',411 'set_id': 6412 },413 {414 'term': 'Is JS case sensitive?',415 'definition': 'yes',416 'set_id': 6,417 },418 {419 'term': 'Define a boolean',420 'definition': 'true or false',421 'set_id': 6,422 },423 {424 'term': 'Define array',425 'definition': 'Used to store multiple values in a single value',426 'set_id': 6,427 },428 {429 'term': 'Down Method',430 'definition': 'Undo what was done by the up method',431 'set_id': 11,432 },433 {434 'term': 'Limit Query',435 'definition': 'Limit the number of returned results',436 'set_id': 11437 },438 {439 'term': 'Order to query results',440 'definition': 'Order',441 'set_id': 11442 },443 {444 'term': 'Validation',445 'definition': 'Security layer that validates information before you put it in your database',446 'set_id': 11,447 },448 {449 'term': 'Not empty validation',450 'definition': 'Makes sure it isnt empty',451 'set_id': 11,452 },453 {454 'term': 'Atomic Unit',455 'definition': 'Indivisible unit',456 'set_id': 11,457 },458 {459 'term': 'What is the sequelize command used to create a database?',460 'definition': 'db:create',461 'set_id': 11462 },463 {464 'term': 'What is an associate function?',465 'definition': 'Where you define the association between two models',466 'set_id': 11467 },468 {469 'term': 'What is cascade delete?',470 'definition': 'A handy shortcut for deleting the associate records of a row your deleting',471 'set_id': 11472 },473 {474 'term': 'What does HTML stand for',475 'definition': 'hyper text markup language',476 'set_id': 15477 },478 {479 'term': '<br>',480 'definition': 'Defines a line break',481 'set_id': 15482 },483 {484 'term': 'Diff between padding and margin',485 'definition': 'Padding is on the inside and margin is on the outside',486 'set_id': 15487 },488 {489 'term': 'Absolute file path',490 'definition': 'The full url to the internet file',491 'set_id': 15492 },493 {494 'term': 'Relative File Path',495 'definition': 'Points to a file in the images folder located at the root of the current web',496 'set_id': 15497 },498 {499 'term': 'What is 10vw',500 'definition': '10% of the view port with',501 'set_id': 15502 },503 {504 'term': 'Server-sent events',505 'definition': 'Allow a web page to get updates from a server',506 'set_id': 15507 },508 {509 'term': 'What are CSS (cascading style sheets)?',510 'definition': 'It is a language for defining style for web documents',511 'set_id': 15512 },513 {514 'term': 'What is the correct HTML element for the largest heading?',515 'definition': 'An h1',516 'set_id': 15517 },518 {519 'term': 'What tag do you use to make a bulleted list?',520 'definition': 'A ul tag',521 'set_id': 15522 },523 {524 'term': 'What is the correct HTML for making a text input field?',525 'definition': '<input type = "text">',526 'set_id': 15527 },528 {529 'term': 'SQL expression language',530 'definition': 'Allows SQL statements to be written using python expressions',531 'set_id': 12532 },533 {534 'term': 'Schema/Types',535 'definition': 'Uses python objects to represent tables, columns and datatypes',536 'set_id': 12537 },538 {539 'term': 'Psychopg2',540 'definition': 'Adaptor for PostGres DB',541 'set_id': 12542 },543 {544 'term': 'What is table.columns.keys',545 'definition': 'Is similar to an associative array of all the columns of a table',546 'set_id': 12547 },548 {549 'term': 'What does a string become when you run a table in the db?',550 'definition': 'A varchar',551 'set_id': 12552 },553 {554 'term': 'How do you apply a data constrain to a table?',555 'definition': 'Using the CHECK SQL command',556 'set_id': 12557 },558 {559 'term': 'What to things SQL Alchemy is composed of?',560 'definition': '1. The engine, 2. The inspect function',561 'set_id': 12562 },563 {564 'term': 'What does importing the engine do?',565 'definition': 'Creates an engine based on the connection string',566 'set_id': 12567 },568 {569 'term': 'What are some dialects of SQLalchemy?',570 'definition': 'sqlite, mysql, postgresql, oracle, mssql',571 'set_id': 12572 },573 {574 'term': 'Are primary keys auto-incrementing?',575 'definition': 'yes',576 'set_id': 12577 },578 {579 'term': 'What is the template for connecting to the database?',580 'definition': 'dialect+driver://username:password@host:port/database',581 'set_id': 12582 },583 {584 'term': 'Name two objects that are available in browser runtimes but not in NodeJS.',585 'definition': 'Common answers include `window`, `document`, and `location`.',586 'set_id': 17587 },588 {589 'term': 'What name can be used in browser runtimes to reference the "global object"?',590 'definition': '`window`',591 'set_id': 17592 },593 {594 'term': 'Why might one choose to use async fs opposed to synchronous fs?',595 'definition': '''596 Operations on our file system can take some time597 because data from our hard drive must be read or598 written. Performing these operations asynchronously599 prevents the single thread of our JavaScript program600 from being blocked during these operations.601 ''',602 'set_id': 17603 },604 {605 'term': 'What is the name of the node module that allows us to perform operations on our local file system?',606 'definition': '`fs`',607 'set_id': 17608 },609 {610 'term': 'What is require used for?',611 'definition': '''612 1) Allows the built in Node modules to be used in a JS file.(http, FS)613 2) Load 3rd party Libraries created by others (Express, Sequalize).614 3) Other files we've made can be "required" into our current file.''',615 'set_id': 17616 },617 {618 'term': 'How do you require the built in FS module?',619 'definition': '''620 In a node.js file, require FS with: "const fs = require("fs")""621 Simple Example:622 "const fs = require("fs");623 fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) {624 if (err) throw err;625 console.log('Saved!');626 });"''',627 'set_id': 17628 },629 {630 'term': 'What is the name of the node module that allows us to take user input?',631 'definition': '`readline`',632 'set_id': 17633 },634 {635 'term': 'What site should be used as a documentation reference for JavaScript in browser runtimes?',636 'definition': '''MDN, Mozilla Developer Network637 (https://developer.mozilla.org/en-US/docs/Web/JavaScript)''',638 'set_id': 17639 },640 {641 'term': 'What site should be used as a documentation reference for JavaScript in Node runtimes?',642 'definition': 'NodeJS.org (https://nodejs.org/api/)',643 'set_id': 17644 },645 {646 'term': 'Define `callback`',647 'definition': '''A function passed to another function648 which we assume will be invoked at some point.''',649 'set_id': 17650 },651 {652 'term': 'Define `algorithms`',653 'definition': '''A process or set of rules to be followed in calculations or other problem-solving operations.''',654 'set_id': 4655 },656 {657 'term': 'How does space and time complexity relate to algorithms?',658 'definition': '''Both are essential when choosing or designing an algorithm.659 Space complexity deals with the memory space required for the algorithm. Time complexity deals660 with the amount of time it takes for the full algorithm to complete. Space and time complexity661 should be considered for all data sizes and especially larger data sets. ''',662 'set_id': 4663 },664 {665 'term': 'What is the process of memoization?',666 'definition': '''667 A technique to optimize the time complexity668 of an algorithm by storing the results of expensive function669 calls and returning the cached result when the same inputs670 occur again.671 ''',672 'set_id': 4673 },674 {675 'term': 'What is the process of tabulation?',676 'definition': '''677 A technique to optimize time complexity of678 an algorithm by filling out a table with elements.679 ''',680 'set_id': 4681 },682 {683 'term': 'What are the 7 most common complexity classes?',684 'definition': '''O(1) - constant685 O(log(n)) - logarithmic686 O(n) - linear687 O(n * log(n)) - loglinear, linearithmic, quasilinear688 O(n^c) - O(n^2)... - polynomial689 O(c^n) - O(2^n)... - exponential690 O(n!) - factorial''',691 'set_id': 4692 },693 {694 'term': 'How does bubble sort work?',695 'definition': '''696 It manipulates the data structure by697 swapping the position of two elements.698 Time Complexity: O(n^2) - polynomial699 Space Complexity: O(1) - constant700 Bubblle sort is very inefficient, and701 does not have many practical uses.702 ''',703 'set_id': 4704 },705 {706 'term': 'How does selection sort work?',707 'definition': '''708 It requires us to locate the709 smallest value in the array.710 Time Complexity: O(n^2) - polynomial711 Space Complexity: O(1)712 Due to its time complexity, selection713 sort is not a very practical algorithm.714 ''',715 'set_id': 4716 },717 {718 'term': 'How does insertion sort work?',719 'definition': '''720 It is a simple sorting algorithm721 that is similar to how we sort playing cards in our hands.722 Time Complexity: O(n^2) - polynomial723 Space Complexity: O(1)724 Insertion sort works well with streaming data,725 because it can sort data as it comes in.726 ''',727 'set_id': 4728 },729 {730 'term': 'How does merge sort work?',731 'definition': '''732 It is a classic example of a "Divide and Conquer"733 algorithm. In other words, we keep breaking the array into734 smaller and smaller sub arrays.735 Time complexity: O(n log(n)) - logarithm736 Space Complexity: O(n) - linear737 Merge sort is one of the fastest algorithms we can use738 on an unknown dataset. However, the space being linear739 can cause issues with larger datasets.740 ''',741 'set_id': 4742 },743 {744 'term': 'Insertion Sort',745 'definition': 'Sorts a list by placing each element in the position it should be in and gradually adding more elements one by one., A sort in which each item in a set is inserted into its proper position in the sorted set according to a specified criterion.',746 'set_id': 5747 },748 {749 'term': 'Selection Sort',750 'definition': '''751 Sorts a list by searching for the 1st element, then the 2nd, and so on until all the elements are in place., A sort in which the items in a set are examined to find an item that fits specified criteria. This item is appended to the sorted set and removed from further consideration, and the process is repeated until all items are in the sorted set.''',752 'set_id': 5753 },754 {755 'term': 'Bubble Sort',756 'definition': '''757 A sort in which the first two items to be sorted are examined and exchanged if necessary to place them in the specified order; the second item is then compared with the third (exchanging them if required), the third is compared with the fourth, and the process is repeated until all pairs have been examined and all items are in the proper sequence.''',758 'set_id': 5759 },760 {761 'term': 'Quicksort',762 'definition': 'A sort in which a list is first partitioned into lower and upper sublists for which all keys are, respectively, less than some pivot key or greater than the pivot key. See also the definitions for "bubble sort", "selection sort" and "insertion sort".',763 'set_id': 5764 },765 {766 'term': 'Mergesort',767 'definition': '''768 Splits the list into sub-lists and then reconstructs the original list.''',769 'set_id': 5770 },771 {772 'term': 'Heap Sort',773 'definition': '''774 This algorithm is based on the heap data structure, and is a more efficient version of selection sort. It determines the largest element. Then, it places that element at the end (or beginning) of the list, and then repeats the process with the rest of the list Recall that in a heap, the top element of the heap is always "next" in order (either the next highest or next lowest, in the case of numbers). If you were to take all of your input values and store them in a heap, and remove one element at a time, the elements will be removed in sorted order. Depending on the data list being sorted, this could have performance consequences. Heap sort is considered an "instable" sort because it doesn't preserve the original order of equal elements.''',775 'set_id': 5776 },777 {778 'term': 'Stable Sort',779 'definition': '''780 Any sort method that does not change the order of equal-rank elements.781 ''',782 'set_id': 5783 },784 {785 'term': 'Comparison sort',786 'definition': 'A sort that ranks items by comparing them to each other. As opposed to a sort that uses some other method, like the radix sort that analyzes the bits of each number.',787 'set_id': 5788 },789 {790 'term': 'Insertion sort time complexity',791 'definition': 'O(n^2) worst case, O(n) best case',792 'set_id': 5793 },794 {795 'term': 'Heap sort time complexity',796 'definition': 'O(n log n) in all cases',797 'set_id': 5798 },799 {800 'term': 'Quicksort time complexity',801 'definition': 'O(n^2) in the very unlikely worst case, O(n log n) in other cases',802 'set_id': 5803 },804 {805 'term': 'Selection sort time complexity',806 'definition': 'O(n ^ 2) in all cases',807 'set_id': 5808 },809 {810 'term': 'Bubble sort time complexity',811 'definition': 'O(n^2) worst case, O(n) best case',812 'set_id': 5813 },814 {815 'term': 'Merge sort time complexity',816 'definition': 'O(n log n) in all cases',817 'set_id': 5818 },819 {820 'term': 'True',821 'definition': 'A constant representing the true value of the boolean type.',822 'set_id': 8823 },824 {825 'term': 'False',826 'definition': 'A constant representing the false value of the boolean type.',827 'set_id': 8828 },829 {830 'term': 'None',831 'definition': 'A constant frequently used to represent the absence of a value, as when default arguments are not passed to a function.',832 'set_id': 8833 },834 {835 'term': 'strings',836 'definition': 'A string literal, or string, holds any combination of letters and numbers you would like it to hold. Any number it holds, however, is not treated like a numerical value but is preserved as if it were a word.',837 'set_id': 8838 },839 {840 'term': 'integers',841 'definition': 'An integer in Python, also known as a \'numeric literal\', is simply a name used for a numeric value. For this reason, these values are commonly called integers even if they are assigned the value of a real number in the form of an integer and a decimal value.',842 'set_id': 8843 },844 {845 'term': 'floating point number',846 'definition': '''A real number (that is, a number that can contain a fractional part).847 To convert a number into floating point:848 >> a = 1849 >> b = float(a)850 1.0''',851 'set_id': 8852 },853 {854 'term': 'lists',855 'definition': '''A list is a series of values. In Python, these values are assigned by placing them within square braces and separating them by commas like this:856 < name of list > = [ < value > , < value > , < value > ]857 girls=['sugar', 'spice', 'everything nice']858 To access a part of a list, one uses the same kind of phrase as one used for a string literal:859 < name of list > [< index number > ]860 ''',861 'set_id': 8862 },863 {864 'term': 'tuple',865 'definition': '''It can be thought of as read-only lists. One can index, slice and concatenate, but one cannot append or alter the values of the tuple after it has been initialized.866 directions=('north', 'south', 'east', 'west')867 ''',868 'set_id': 8869 },870 {871 'term': 'dictionary',872 'definition': '''873 Python term for an associative array. An array is, like a list, a series of values in two dimensions. An associative array gives one a way of accessing the values by a key, a term associated with the value instead of an item's index number.874 These are similar to hashes in Ruby.875 my_dictionary={"author": "Andrew Melville",876 "title": "Moby Dick",877 "year": "1851",878 "copies": 5000000879 }880 One accesses a dictionary member by its key:881 >> > a=my_dictionary["author"]882 >> > print a883 Andrew Melville884 ''',885 'set_id': 8886 },887 {888 'term': 'complex number',889 'definition': '''890 They have a real and imaginary part, which are each a floating point number.891 >> a=1892 >> b=complex(a)893 (1+0j)''',894 'set_id': 8895 },896 {897 'term': 'long number',898 'definition': '''899 They have unlimited precision.900 >> a=1901 >> b=long(a)902 1L903 Long numbers also take up a lot of processing power.''',904 'set_id': 8905 },906 {907 'term': 'What is the difference between an element and an attribute?',908 'definition': '''An element in HTML represents some kind of structure or semantics and909 generally consists of a start tag, content, and an end tag.910 An attribute defines a property for an element, consists of an attribute/value pair, and appears within the element's start tag. An element's start tag may contain any number of space separated attribute/value pairs.''',911 'set_id': 14912 },913 {914 'term': 'What are at least two different ways to select a div with the ID of"container"in vanilla JavaScript?',915 'definition': 'Document​.get​Element​ById() Document​.query​Selector()',916 'set_id': 14917 },918 {919 'term': 'What is the difference between an ID and a class?',920 'definition': '''In the CSS, a class selector is a name preceded by a full stop(".") and an ID selector is a name preceded by a hash character("#").921 ID can be used to identify one element, whereas a class can be used to identify more than one.''',922 'set_id': 14923 },924 {925 'term': 'Describe specificity in CSS and give examples.',926 'definition': '''is the means by which browsers decide which CSS property values are the most relevant to an element.927 If there are two or more conflicting CSS rules that point to the same element, the browser follows some rules to determine which one is most specific and therefore wins out.928 Inline styles - An inline style is attached directly to the element to be styled. Example: < h1 style="color: #ffffff;" > .929 # navbar.930 IDs - An ID is a unique identifier for the page elements, such as931 Classes, attributes and pseudo-classes - This category includes .classes, [attributes] and pseudo-classes such as:hover, :focus etc.932 Elements and pseudo-elements - This category includes element names and pseudo-elements, such as h1, div, :before and :after.''',933 'set_id': 14934 },935 {936 'term': 'What is event delegation and when would you use it?',937 'definition': '''strategy we can use to optimize the web apps when responding to user events.938 add the event listener to the parent, when the evet target is clicked, which will trigger the parent event listener, and find the event which is triggered.939 event.target identifies the HTML elements on which the event occurred. and we also know what element we want to listen for.940 event bubbling/propagation: it means when the user makes a click it ripples up all the way up to the top of the DOM and triggers clicks events on all the parent elements of the event you clicked.941 **Because of event bubbling you can place an event listener on a single parent HTML element that lives above a HTML child, and that event listener will get executed whenever an event occurs on any of its child nodes — even if these node children are added to the page after the initial load!942 Whenever a user makes a click it ripples up all the way up to the top of the DOM and triggers clicks events on all the parent elements of the element you clicked.943 Why:944 Without event delegation you would have to rebind the click event listener to each new input loaded to the page. Coding this is complicated and burdensome.''',945 'set_id': 14946 },947 {948 'term': 'What does e.preventDefault()do?What is event bubbling?',949 'definition': '''The method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur.950 - Clicking on a "Submit" button, prevent it from submitting a form951 - Clicking on a link, prevent the link from following the URL952 event bubbling/propagation: it means when the user makes a click it ripples up all the way up to the top of the DOM and triggers clicks events on all the parent elements of the event you clicked.953 **Because of event bubbling you can place an event listener on a single parent HTML element that lives above a HTML child, and that event listener will get executed whenever an event occurs on any of its child nodes — even if these node children are added to the page after the initial load!''',954 'set_id': 14955 },956 {957 'term': 'AJAX',958 'definition': 'A technique for creating seamless interactive websites via asynchronous data exchange between client and server. Ajax facilitates communication with the server via partial page updates instead of the traditional full-page refresh.',959 'set_id': 14960 },961 {962 'term': 'AMD',963 'definition': '''964 A standard defining how to load JavaScript libraries or modules asynchronously965 and stands for Asynchronous Module Definition. It is an alternative to CommonJS(CJS) specification.966 The API specifies a mechanism for defining modules such that the module and its dependencies can be asynchronously loaded. This is particularly well suited for the browser environment where synchronous loading of modules incurs performance, usability, debugging, and cross-domain access problems.''',967 'set_id': 14968 },969 {970 'term': 'What is the DOM?',971 'definition': '''972 DOM(for Document Object Model) is a platform - and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page. This is an overview of DOM-related materials here at W3C and around the web.''',973 'set_id': 14974 },975 {976 'term': 'Flask is a',977 'definition': 'micro framework for Python web development',978 'set_id': 16979 },980 {981 'term': 'Flask is a micro framework because',982 'definition': 'it implements only core functionality (including routing) but leaves more advanced functionality (including authentication and database ORMs) to extensions',983 'set_id': 16984 },985 {986 'term': 'app = Flask(__name__)',987 'definition': '''988 creates an instance of the Flask object using our module's name as a parameter''',989 'set_id': 16990 },991 {992 'term': '@app.route("/")',993 'definition': '''994 means that the function directly below it should be called whenever a user visits the main root page of our web application995 ''',996 'set_id': 16997 },998 {999 'term': 'How do you collect data from a URL parameter using Flask?',1000 'definition': '''You can specify the variable in the app.route and then use that variable as a paramater in the routing function. Here is an example of the pretzel:1001 ```py1002 @ app.route('/foods/<food>')1003 def grocery(food):1004 x=food1005 ```''',1006 'set_id': 161007 },1008 {1009 'term': 'How do you collect data from the query string using Flask?',1010 'definition': '''1011 With a query string the data can be found in the request.args dictionary:1012 ```py1013 @ app.route('/foods')1014 def grocery():1015 x=request.args.get('type')1016 ```''',1017 'set_id': 161018 },1019 {1020 'term': 'How do you collect data from the body of the request using Flask?',1021 'definition': '''You can get the data form a post request in the body using the request.form dictionary1022 ```py1023 @ app.route('/foods')1024 def grocery():1025 x=request.form.get('type')1026 ```''',1027 'set_id': 161028 },1029 {1030 'term': 'What is the session object in Flask?',1031 'definition': 'It is built off of using cookies. It allows the server to set many different things in the in the session for the client to remember wihout having to create many different cookies and just have one session. It is also encoded so that someone can\'t change session data on the client before sending it to the server.',1032 'set_id': 161033 },1034 {1035 'term': 'What exactly does Flask\'s \`jsonify()\` do?',1036 'definition': 'It will take JSON serializeable data in python and convert it to a JSON string.',1037 'set_id': 161038 },1039 {1040 'term': 'What is the difference between authorization and authentication?',1041 'definition': 'Authentication refers to the process of verifying who you are whereas authorization is the process of verifying that you have access to something. For example, you can authenticate someones login and then make sure they have access to their profile by authorization.',1042 'set_id': 161043 },1044 {1045 'term': 'What is a tree?',1046 'definition': '''1047 A graph that does not contain any cycles.1048 A cycle is is defined as a path through edges that1049 begins and ends at the same node. A tree will always1050 have a root node1051 ''',1052 'set_id': 11053 },1054 {1055 'term': 'What is a binary tree?',1056 'definition': '''1057 A tree where each node has at most1058 two children.1059 ''',1060 'set_id': 11061 },1062 {1063 'term': 'What is a leaf node?',1064 'definition': 'A node that doesn\'t have children.',1065 'set_id': 11066 },1067 {1068 'term': 'What is a root node?',1069 'definition': '''1070 The ultimate parent, the single node of a tree that1071 can access every other node through edges; by definition1072 the root will not have a parent.1073 ''',1074 'set_id': 11075 },1076 {1077 'term': 'What is an internal node?',1078 'definition': 'A node that has children.',1079 'set_id': 11080 },1081 {1082 'term': 'How does a breadth-first search traverse a tree?',1083 'definition': '''1084 Trees are traversed level-by-level, where you visit1085 every node on a level before going to a lower level. This1086 search is referred to as breadth-first search (BFS),1087 as the search tree is broadened as much as possible1088 on each depth before going to the next depth.1089 ''',1090 'set_id': 11091 },1092 {1093 'term': 'How does a depth-first search traverse a tree?',1094 'definition': '''1095 Trees are traversed as deep as possible on each child1096 before going to the next sibling, thus the name `DFS`.1097 ''',1098 'set_id': 11099 },1100 {1101 'term': 'At most, how many children can each node have in a ternary tree? N-ary tree?',1102 'definition': 'They have at most 3 children. N-ary trees have at most n children.',1103 'set_id': 11104 },1105 {1106 'term': 'How do binary search trees differ from binary trees?',1107 'definition': '''1108 It is a search tree with the additional added criteria:1109 - Given any node of the BST, the values in the left subtree must all be1110 strictly less than the given node's value.1111 - Given the same node of the BST, the values in the right subtree must all1112 be greater than or equal to the given node's value.1113 ''',1114 'set_id': 11115 },1116 {1117 'term': 'Explain what makes a binary tree full, complete, or perfect.',1118 'definition': '''1119 Full Binary Tree - each node has exactly 0 or 2 children.1120 Complete Binary Tree - all levels except the last one are full with nodes.1121 Perfect Binary Tree - all levels (including the last one) are full of nodes.1122 ''',1123 'set_id': 11124 },1125 {1126 'term': 'What are the different ways to write a string literal in JS?',1127 'definition': '`string`, "string", \'string\'',1128 'set_id': 71129 },1130 {1131 'term': 'What are the diffent ways to write a variable in JS?',1132 'definition': '''1133 const variable =...;1134 let variable =...;1135 var variable =...;1136 ''',1137 'set_id': 71138 },1139 {1140 'term': 'What are the different ways to write a function in JS?',1141 'definition': '''1142 function foo(params) {return}1143 const foo = function(params) {return}1144 const foo = (params) => return1145 ''',1146 'set_id': 71147 },1148 {1149 'term': 'How would you invoke the function foo in JS?',1150 'definition': 'foo(args);',1151 'set_id': 71152 },1153 {1154 'term': 'How do you write an object literal in JS?',1155 'definition': '''const obj = {1156 "property1":value1,1157 "property2":value2,1158 "key": value31159 };1160 ''',1161 'set_id': 71162 },1163 {1164 'term': 'How do you write an array literal in JS?',1165 'definition': 'const arr = [v1, v2, ..., vn]; ',1166 'set_id': 71167 },1168 {1169 'term': 'What are the different error types in JS?',1170 'definition': '''1171 EvalError1172 InternalError1173 RangeError1174 ReferenceError1175 SyntaxError1176 TypeError1177 URIError1178 ''',1179 'set_id': 71180 },1181 {1182 'term': 'How would you select a DOM element with an id of "bar" in JS?',1183 'definition': 'const barEle = document.getElementById("bar");',1184 'set_id': 71185 },1186 {1187 'term': 'How can you insert values into an array from an array without directly inserting each value?',1188 'definition': '''1189 const arr1 = [3, 4, 5];1190 const arr2 = [1, 2, ...vals];1191 console.log(arr2) // => [1, 2, 3, 4, 5]1192 ''',1193 'set_id': 71194 },1195 {1196 'term': 'What values are considered falsey in JS?',1197 'definition': '0, 0n, null, undefined, false, NaN, ""',1198 'set_id': 71199 },1200 {1201 'term': 'Singly Linked List Node',1202 'definition': '''Represents a single item in a linked list. Contains a value and a1203 reference to the next node.''',1204 'set_id': 31205 },1206 {1207 'term': 'Head',1208 'definition': '''Part of a linked list that points to the first node1209 if that list isn't empty.''',1210 'set_id': 31211 },1212 {1213 'term': 'Empty List',1214 'definition': '''Will have no nodes so can be checked by checking1215 the node count. Note that Head and Tail should also be null as1216 there are no nodes to point to.''',1217 'set_id': 31218 },1219 {1220 'term': 'Cheap Linked List Operations',1221 'definition': '''It is common to AddToHead, AddToTail, RemoveFromHead1222 (all O(1)) and Enumerate (which can be used to Find) which is O(n).1223 Note that RemoveFromTail is O(1) if used on a doubly linked list.''',1224 'set_id': 31225 },1226 {1227 'term': 'Expensive Linked List Operations',1228 'definition': '''It is often possible to perform more expensive operations O(n)1229 on a linked list such as RemoveItem(value), RemoveFromTail and1230 Contains(value). Note that RemoveFromTail is O(1) if used on a1231 doubly linked list.''',1232 'set_id': 31233 },1234 {1235 'term': 'List.AddToHead algorithm',1236 'definition': '''With the new node, assigns 'Next' to point to the current1237 head of the list if it exists, otherwise set it to null. Assign1238 the list head to reference the new node. If the list is empty,1239 assign the tail to new node. Increment the node count. O(1)''',1240 'set_id': 31241 },1242 {1243 'term': 'List.RemoveFromHead algorithm',1244 'definition': '''If the list isn't empty, assign the head pointer to its1245 node->next pointer (so it points to the next node or null).1246 Decrement the count, if it is 0 set the tail to null. O(1)''',1247 'set_id': 31248 },1249 {1250 'term': 'List.Enumerate algorithm',1251 'definition': '''Create a temporary 'Current' node reference, set it to the1252 head of the list; while ( Current != null) { Current = Current->Next; }.1253 This walks over every node that exists in the list.''',1254 'set_id': 31255 },1256 {1257 'term': 'List.RemoveItem(value)',1258 'definition': '''Enumerate the list, keeping a reference to the previous node;1259 if the value of the current node matches the value we'd like1260 to remove then update the previous node->next to current->next.''',1261 'set_id': 31262 },1263 {1264 'term': 'Orphan Node',1265 'definition': '''Used to describe a node that has been removed from a collection1266 and so has no references.''',1267 'set_id': 31268 },1269 {1270 'term': 'When to use a linked list',1271 'definition': '''They are useful for stacks and queues due to their ability1272 to resize cheaply (depending on whether memory has to be allocated...1273 recycling nodes would be more efficient). Lists are also quite malleable,1274 allowing the easy insertion of items without having to shift existing data,1275 this could be handy for things like merge or quick sort. "Dynamic".''',1276 'set_id': 31277 },1278 {1279 'term': 'When not to use a linked list',1280 'definition': '''If an algorithm requires lots of lookups then an array (indexes)1281 or dictionary (keys) are likely to be much more efficient. If you1282 don't want the collection to grow or to allocate further memory1283 (e.g. per-node), then it might be worth considering an array or1284 something else with a fixed size, especially if data doesn't need1285 to be sorted, added or removed.''',1286 'set_id': 31287 },1288 {1289 'term': 'What signifies the end of a linked list?',1290 'definition': 'null',1291 'set_id': 31292 },1293 {1294 'term': 'Whitespace',1295 'definition': '''Used to structure code. This also means right space, and if1296 this is off, an indentation error will be displayed.''',1297 'set_id': 91298 },1299 {1300 'term': 'Single-line Comments',1301 'definition': 'Use # to comment.',1302 'set_id': 91303 },1304 {1305 'term': 'Multi-line Comments',1306 'definition': 'Use triple quotation marks """',1307 'set_id': 91308 },1309 {1310 'term': 'Exponentiation',1311 'definition': 'Use **. (2**3 = 8)',1312 'set_id': 91313 },1314 {1315 'term': 'Len()',1316 'definition': '''A type of string method used to measure the length or number1317 of characters in a string.''',1318 'set_id': 91319 },1320 {1321 'term': 'Lower()',1322 'definition': 'Gets rid of all the capitalization in a string.',1323 'set_id': 91324 },1325 {1326 'term': 'Upper()',1327 'definition': 'Makes a string completely uppercase.',1328 'set_id': 91329 },1330 {1331 'term': 'str()',1332 'definition': 'Turns non-string into strings.',1333 'set_id': 91334 },1335 {1336 'term': 'Print',1337 'definition': 'Command that displays code onto the console.',1338 'set_id': 91339 },1340 {1341 'term': '=',1342 'definition': 'Used to define variables',1343 'set_id': 91344 },1345 {1346 'term': 'fruit[:3]',1347 'definition': '''Starts at beginning of string "fruit", gives the first three1348 characters, up to but not including the index of 3.''',1349 'set_id': 91350 },1351 {1352 'term': 'max()',1353 'definition': 'This returns the greatest element in a list.',1354 'set_id': 91355 },1356 {1357 'term': 'min()',1358 'definition': 'This returns the smallest element in a list.',1359 'set_id': 91360 },1361 {1362 'term': 'append()',1363 'definition': 'This adds a new value to the end of a list.',1364 'set_id': 91365 },1366 {1367 'term': 'Sum',1368 'definition': 'Returns the sum of the numeric values in a given column',1369 'set_id': 101370 },1371 {1372 'term': 'Max',1373 'definition': 'Returns the largest value in a given column',1374 'set_id': 101375 },1376 {1377 'term': 'Min',1378 'definition': 'Returns the smallest value in a given column.',1379 'set_id': 101380 },1381 {1382 'term': 'Avg',1383 'definition': 'Returns the average value of a given column',1384 'set_id': 101385 },1386 {1387 'term': 'Count',1388 'definition': 'Returns the total number of values in a given column',1389 'set_id': 101390 },1391 {1392 'term': 'Count (*)',1393 'definition': 'Returns the number of rows in a table',1394 'set_id': 101395 },1396 {1397 'term': 'Column',1398 'definition': '''Database tables are made of different columns (fields)1399 corresponding to the attributes of the object described by1400 the table.''',1401 'set_id': 101402 },1403 {1404 'term': 'CREATE TABLE',1405 'definition': 'Used to create a new table',1406 'set_id': 101407 },1408 {1409 'term': 'Insert',1410 'definition': 'Command used to add a new record to a table within a database',1411 'set_id': 101412 },1413 {1414 'term': 'ORDER BY',1415 'definition': '''Clause used to sort the data in ascending or descending order,1416 based on one or more columns''',1417 'set_id': 101418 },1419 {1420 'term': 'PRIMARY KEY',1421 'definition': '''Constraint that uniquely identifies each record in a database1422 table; must contain unique values; should be included in most1423 tables''',1424 'set_id': 101425 },1426 {1427 'term': 'Query',1428 'definition': '''The main way to make a request for information from a database;1429 consist of questions presented to the database in a predefined format.''',1430 'set_id': 101431 },1432 {1433 'term': 'How does React connect with Browser DOM elements?',1434 'definition': '''It uses objects called "React elements" to represent the HTML1435 elements of the DOM. Developers can also create custom elements called1436 "Components" to represent the larger parts of the UI.''',1437 'set_id': 131438 },1439 {1440 'term': 'JSX',1441 'definition': '''This is an HTML-like syntax extension for JavaScript written1442 to be used with React. This is specifically how React adds XML1443 syntax to JavaScript which is compiled to JavaScript at runtime.''',1444 'set_id': 131445 },1446 {1447 'term': 'JSX element',1448 'definition': '''A basic unit of JSX found in a JavaScript file which is treated1449 as, and has the functionality of, a JavaScript expression.1450 It can also have attributes, just like HTML elements.''',1451 'set_id': 131452 },1453 {1454 'term': 'A component changes its state by calling the function',1455 'definition': 'this.setState( { someKey: newValue} )',1456 'set_id': 131457 },1458 {1459 'term': 'The compiler transforms every JSX element into this method',1460 'definition': 'React.createElement()',1461 'set_id': 131462 },1463 {1464 'term': 'Components',1465 'definition': 'React applications are made out of these.',1466 'set_id': 131467 },1468 {1469 'term': 'Two ways for a component to get dynamic information:',1470 'definition': 'props and state',1471 'set_id': 131472 },1473 {1474 'term': 'How do you pass a prop?',1475 'definition': 'By giving an attribute to a component instance',1476 'set_id': 131477 },1478 {1479 'term': 'State',1480 'definition': 'Data in our application that can change',1481 'set_id': 131482 },1483 {1484 'term': 'Props',1485 'definition': 'Information that gets passed from one component to another',1486 'set_id': 131487 },1488 {1489 'term': 'Is redux predictable?',1490 'definition': 'Yes. Interacting with the data in the store repeatedly will produce the same effect',1491 'set_id': 181492 },1493 {1494 'term': '3 main principles of redux',1495 'definition': '''1496 1. A single source of truth1497 2. State is read only1498 3. Changes are made with pure functions1499 ''',1500 'set_id': 181501 },1502 {1503 'term': 'Explain "a single source of truth"',1504 'definition': 'The state for the entire redux app is stored in a single pojo',1505 'set_id': 181506 },1507 {1508 'term': 'Explain "State is read only"',1509 'definition': 'State object cannot directly be modified; it can only be modified bt dispatching actions',1510 'set_id': 181511 },1512 {1513 'term': 'Explain "Changes are made using pure functions"',1514 'definition': 'pure functions are the reducers, which receive and update the old state and the action',1515 'set_id': 181516 },1517 {1518 'term': 'Briefly explain state',1519 'definition': 'The state of a program refers to akk the info stored by that program at a specific point in time, generally data',1520 'set_id': 181521 },1522 {1523 'term': 'Briefly explain what a store is',1524 'definition': 'A single POJO with a few other methods, including getState, dispatch(action) and subscribe(listener)',1525 'set_id': 181526 },1527 {1528 'term': 'Action',1529 'definition': 'A POJO that has a type property, and contains info that can be used to update the store, ie dispatched',1530 'set_id': 181531 },1532 {1533 'term': 'Pure Function',1534 'definition': 'Its behavior does not rely on anythng other than taking in arguments and returning a value',1535 'set_id': 181536 },1537 {1538 'term': 'Reducer',1539 'definition': 'Function that is called every time an action is dispatched. It receives an action plus the current state as the arguments, returns the updated state',1540 'set_id': 181541 },1542 {1543 'term': 'Are reducers required to be pure functions?',1544 'definition': 'Yes.They must be pure functions of the dispatched action and the current state.',1545 'set_id': 181546 },1547 {1548 'term': 'Middleware',1549 'definition': 'This is an optional component of redux that allows custom responses to dispatched actions',1550 'set_id': 181551 },1552 {1553 'term': 'Thunks',1554 'definition': 'An alternative to middleware, they essentially act as a function that calls another function',1555 'set_id': 181556 },1557 {1558 'term': 'WHat is Flux?',1559 'definition': 'A front end app architecture from FB that provides unidirectional flow; a pattern you use to structure the app',1560 'set_id': 181561 },1562 {1563 'term': 'What are the 3 main things a redux store is responsible for?',1564 'definition': '''1565 1. Using a reducer to update an app's state1566 2. Using subscription to broadcast an app's state1567 3. Actions - using them to tell it how and when it needs to change the global1568 state of the application1569 ''',1570 'set_id': 181571 },1572 {1573 'term': 'What are the 3 main store methods?',1574 'definition': '''1575 1. getState() = returns the current state of a store1576 2. dispatch(action) = passes an action into the reducer that tells it what info it must update1577 3. subscribe(callback) = registers cbs to go off whenever the store updates. It returns a function that when1578 invoked, it unsubscribes the cb from the store1579 ''',1580 'set_id': 181581 },1582 {1583 'term': 'What 3 steps does a reducer perform?',1584 'definition': '''1585 1. It receives the current state plus an action1586 2. It then updates the state based on the action.type1587 3. finally, it returns the next state1588 ''',1589 'set_id': 181590 },1591 {1592 'term': 'Briefly desccribe cookies',1593 'definition': '''1594 A really small file stored on the user's computer, a cookie holds a small amount of data.1595 Its included in HTTP requests - the server sends the data to the browser1596 where it gets stored, and its sent back to the server with the next request1597 ''',1598 'set_id': 191599 },1600 {1601 'term': 'What are a few things a cookie can store?',1602 'definition': '''1603 To store stateful information about a user:1604 examples:1605 a. browser history1606 b. form input information they filled out1607 c. storing a session cookie / user login/validation1608 d. persistant cookies can have an expiration date1609 ''',1610 'set_id': 191611 },1612 {1613 'term': 'Web Storage API',1614 'definition': ' Local Storage & Session Storage',1615 'set_id': 191616 },1617 {1618 'term': 'Session Storage',1619 'definition': '''1620 1. Stores data for only one session or until the browser or a tab is closed.1621 2. NEVER transfers data to the server1622 3. The storage limit is significantly larger than a cookie (5mb)1623 ''',1624 'set_id': 191625 },1626 {1627 'term': 'Local Storage',1628 'definition': '''1629 1. Stores the data with no expiry date1630 2. Deleted when the browser cache is cleared1631 3. Has a max storage limit in the browser1632 ''',1633 'set_id': 191634 },1635 {1636 'term': 'What is JSON',1637 'definition': 'A format - it is just a string of text',1638 'set_id': 191639 },1640 {1641 'term': 'Two important built in javascript JSON object methods',1642 'definition': '''1643 1. JSON.stringify(value) = turns the passed value into a string1644 2. JSON.parse(str) = turns a JSON formatted string into a javascript object1645 ''',1646 'set_id': 191647 },1648 {1649 'term': 'Which method will serialize a JS value into a JSON string?',1650 'definition': 'JSON.stringify()',1651 'set_id': 191652 },1653 {1654 'term': 'Define serialize',1655 'definition': 'To serialize means to convert data into a format that can be sent to another computer',1656 'set_id': 191657 },1658 {1659 'term': 'Define deserialize',1660 'definition': 'Converting a message from another computer into useable data ',1661 'set_id': 191662 },1663 {1664 'term': 'Promise',1665 'definition': 'A promise that at some future point, your code will get a value from an operation so you dont get an error',1666 'set_id': 201667 },1668 {1669 'term': 'Three Existing States of a Promise',1670 'definition': 'Pending, Fulfilled, Rejected',1671 'set_id': 201672 },1673 {1674 'term': 'Pending Promise',1675 'definition': 'The promise object hasnt been resolved. Once it does, it becomes either fullfilled or rejected',1676 'set_id': 201677 },1678 {1679 'term': 'Fullfilled Promise',1680 'definition': 'Whatever was pending had succeeded - the success handler is called and now the promise cant transition to another state or change its value',1681 'set_id': 201682 },1683 {1684 'term': 'Rejected Promise',1685 'definition': 'The operation the pending promise was sup to do failed, and now your error handler is called. The promise cant transition state, nor error reason ',1686 'set_id': 201687 },1688 {1689 'term': 'Success Handler ',1690 'definition': 'A function with one param, which is the value the fullfilled promise has',1691 'set_id': 201692 },1693 {1694 'term': 'Error Handler',1695 'definition': 'A function with one param, which is the reason that the promise failed',1696 'set_id': 201697 },1698 {1699 'term': 'What can you use to replace .then',1700 'definition': 'Using async-await',1701 'set_id': 201702 },1703 {1704 'term': 'What happens when you declare a function as async',1705 'definition': 'Causes the function to return an implicit promise containing the result',1706 'set_id': 201707 },1708 {1709 'term': 'What does "await" do?',1710 'definition': 'Used to wait for a promise to be fullfilled and can ONLY be used inside an async function',1711 'set_id': 201712 },1713 {1714 'term': 'Does async/await code look synchronous?',1715 'definition': 'Yes! You also dont have to chain .then everywhere and look super messy. Async await is the BOMB',1716 'set_id': 201717 },1718 {1719 'term': 'What kind of error handling does async.await use?',1720 'definition': 'Try / Catch blocks',1721 'set_id': 201722 },1723 {1724 'term': 'What are two basic reasons for testing?',1725 'definition': '''To make sure your code works, for increased flexibility and to reduce fear of code/boost confidence1726 to make it easier to collaberate, and act as documentation for the codebase.1727 ''',1728 'set_id': 211729 },1730 {1731 'term': 'Mocha ',1732 'definition': 'A javascript testing framework that runs tests AND shows them in a nice, user friendly way',1733 'set_id': 211734 },1735 {1736 'term': '3 levels of the testing pyramid ',1737 'definition': '1. Unit Tests 2. Integration Tests 3. End to End Tests (E2E)',1738 'set_id': 211739 },1740 {1741 'term': 'Bottom 1 - Unit Tests ',1742 'definition': 'Smallest unit of testing, used to test little bit of isolated code & should ONLY focus on ONE thing',1743 'set_id': 211744 },1745 {1746 'term': 'Middle 2 - Integeration Tests ',1747 'definition': 'Tests the interaction between the pieces you tested in isolation, making sure they work together',1748 'set_id': 211749 },1750 {1751 'term': 'Top Tier - End to End Tests ',1752 'definition': 'Highest level of testing, this is when you are testing the entire app',1753 'set_id': 211754 },1755 {1756 'term': 'TDD ',1757 'definition': 'Dictates that tests, not application code should be written first',1758 'set_id': 211759 },1760 {1761 'term': 'Why use TDD?',1762 'definition': 'Code written to pass pre-written specs are guaranteed to be testable and it makes it easier for other people to add new code while making sure they are not breaking anything',1763 'set_id': 211764 },1765 {1766 'term': '4 Brief reasons TDD is the way to go (i disagree but no one asked for my opinion sadly) ',1767 'definition': '''1. Writing tests before writing code means you can make sure the code you are writing works as you are writing it1768 2. Only required code is written - you will not have any extra unnecessary functionality or code1769 3. TDD helps focus on modularity aka breaking down the application in small, testable chunks1770 4. You have a better understanding of the functionality of the code you are going to write, before you do1771 ''',1772 'set_id': 211773 },1774 {1775 'term': '3 steps of TDD workflow ',1776 'definition': 'red - green - refactor = all in a continuous loop ',1777 'set_id': 211778 },1779 {1780 'term': 'TDD - red ',1781 'definition': 'Write tests that are going to fail',1782 'set_id': 211783 },1784 {1785 'term': 'TDD-green ',1786 'definition': 'Minimum amount of code needed to get the tests to pass',1787 'set_id': 211788 },1789 {1790 'term': 'TDD - refactor ',1791 'definition': 'Refactoring the code you wrote that passed the tests, and then you loop back to red.',1792 'set_id': 211793 },1794 ])1795 op.bulk_insert(votes_table, [1796 {1797 'set_id': 18, # redux1798 'user_id': 1,1799 'is_upvote': False1800 },1801 {1802 'set_id': 18, # redux1803 'user_id': 2,1804 'is_upvote': False1805 },1806 {1807 'set_id': 18, # redux1808 'user_id': 3,1809 'is_upvote': False1810 },1811 {1812 'set_id': 18, # redux1813 'user_id': 4,1814 'is_upvote': False1815 },1816 {1817 'set_id': 5, # redux1818 'user_id': 4,1819 'is_upvote': True1820 },1821 {1822 'set_id': 5, # redux1823 'user_id': 3,1824 'is_upvote': True1825 },1826 {1827 'set_id': 5, # redux1828 'user_id': 2,1829 'is_upvote': True1830 },1831 {1832 'set_id': 5, # redux1833 'user_id': 1,1834 'is_upvote': True1835 },1836 {1837 'set_id': 1, # redux1838 'user_id': 2,1839 'is_upvote': True1840 },1841 ])1842# ### end Alembic commands ###1843def downgrade():1844 # ### commands auto generated by Alembic - please adjust! ###1845 op.drop_table('votes')1846 op.drop_table('favorites')1847 op.drop_table('cards')1848 op.drop_table('sets')1849 op.drop_table('users')1850 op.drop_table('categories')...

Full Screen

Full Screen

queries.py

Source:queries.py Github

copy

Full Screen

1from flashcard import Set, Card2from models import db, Set_SQL, Card_SQL, Side_SQL, Cell_SQL, User3from sqlalchemy import desc4### READ5def query_cells(card_id): # returns a dictionary of cells {side_id: [info, card_id]} for a given card_id6 records = db.session.query(Cell_SQL).filter_by(card_id=card_id).all()7 cells = {}8 for record in records:9 cells[record.side_id] = [record.info, record.card_id]10 return cells11def query_cards(id): # returns an array of Card objects for a given set_id12 records = db.session.query(Card_SQL).filter_by(set_id=id).all()13 cards = []14 for record in records:15 card = Card(record.card_ID, record.card_order, query_cells(record.card_ID), record.set_id)16 cards.append(card)17 return cards18def query_sides(set_id): # returns a dictionary of {id_name: [order, name, set_id]} for a given set_id19 records = db.session.query(Side_SQL).filter_by(set_id=set_id).all()20 sides = {}21 for record in records:22 sides[record.side_id] = [record.side_order, record.name, record.set_id]23 return sides24def query_sets(records): # returns an array of all sets where each set is an array of form [set_id, name, description, user_id, public]25 sets = []26 for record in records:27 set = [record.set_id, record.name, record.description, record.user_id, record.public]28 sets.append(set)29 return sets30def query_sets_public(user): # returns all publicly visible sets31 records = db.session.query(Set_SQL).filter_by(public=True).order_by(desc(Set_SQL.set_id)).all()32 all_records = query_sets(records)33 return all_records34def query_sets_private(user): # returns all privately visible sets for a given user35 records = db.session.query(Set_SQL).filter_by(user_id=user.id).order_by(desc(Set_SQL.set_id)).all()36 return query_sets(records)37def build_sets(records): # builds an array of Set objects for all sets in db using query methods38 sets = []39 for record in records:40 set = Set(record[0], record[1], record[2], query_sides(record[0]), query_cards(record[0]), record[3], record[4])41 sets.append(set)42 return sets43def build_sets_public(user): # builds an array of Set objects for all public sets44 return build_sets(query_sets_public(user))45def build_sets_private(user): # builds an array of Set objects for all private sets of a given user46 return build_sets(query_sets_private(user))47def get_set(set_id): # builds a Set object for a given set_id48 try:49 record = db.session.query(Set_SQL).filter_by(set_id=set_id).one()50 user = db.session.query(User).filter_by(id=record.user_id).one()51 set = Set(record.set_id, record.name, record.description, query_sides(record.set_id), query_cards(record.set_id), record.user_id, record.public)52 return set53 except:54 return None55### WRITE56def process_form(form, user): # creates a set owned by the given user using the given form data57 # create set58 public = True if form.getlist('public') else False59 ins = Set_SQL(name=form['name'], description=form['description'], user=user, public=public)60 db.session.add(ins)61 db.session.commit()62 set_id = ins.set_id63 # create sides64 sides = []65 side_fields = dict(filter(lambda elem: 'cell[0]' in elem[0], form.items()))66 for field in side_fields:67 if field == 'cell[0][0]':68 ins_side = Side_SQL(set_id=set_id, name=form[field])69 db.session.add(ins_side)70 db.session.commit()71 side_id = ins_side.side_id72 else:73 side = {'set_id': set_id, 'name': form[field]}74 sides.append(side)75 if sides:76 side_result = db.engine.execute(Side_SQL.__table__.insert(), sides)77 # create cards78 cards = []79 card_fields = dict(filter(lambda elem: 'cell' in elem[0] and '][0]' in elem[0] and 'cell[0]' not in elem[0], form.items()))80 for field in card_fields:81 if field == 'cell[1][0]':82 ins_card = Card_SQL(set_id=set_id)83 db.session.add(ins_card)84 db.session.commit()85 card_id = ins_card.card_ID86 else:87 card = {'set_id': set_id}88 cards.append(card)89 if cards:90 card_result = db.engine.execute(Card_SQL.__table__.insert(), cards)91 # create cells92 cells = []93 cell_fields = dict(filter(lambda elem: 'cell' in elem[0] and 'cell[0]' not in elem[0], form.items())) # non-"side name" cells94 for field in cell_fields:95 card_index = int(field[5:6])-196 side_index = int(field[-2:-1])97 cell = {'card_id': card_index+card_id, 'side_id': side_id+side_index, 'info': form[field]}98 cells.append(cell)99 cells_result = db.engine.execute(Cell_SQL.__table__.insert(), cells)100def edit_form(form, set_id): # modifies a given set based on form data101 # update set info102 record = db.session.query(Set_SQL).filter_by(set_id=set_id).one()103 public = True if form.getlist('public') else False104 record.name = form['name']105 record.description = form['description']106 record.public = public107 db.session.commit()108 set_id = record.set_id109 # update sides110 sides = db.session.query(Side_SQL).filter_by(set_id=set_id).all()111 side_fields = dict(filter(lambda elem: 'cell[0]' in elem[0], form.items()))112 num_sides = min(len(sides), len(side_fields))113 for i in range(num_sides): # update existing sides114 side = sides[i]115 side.name = form['cell[0][' + str(i) + ']']116 db.session.commit()117 if len(side_fields) < len(sides): # delete removed sides118 for i in range(len(side_fields), len(sides)):119 db.session.query(Cell_SQL).filter_by(side_id=sides[i].side_id).delete()120 db.session.query(Side_SQL).filter_by(side_id=sides[i].side_id).delete()121 db.session.commit()122 new_sides = []123 if len(side_fields) > len(sides): # new sides124 for i in range(len(sides), len(side_fields)):125 side = {'set_id': set_id, 'name': form['cell[0][' + str(i) + ']']}126 new_sides.append(side)127 db.engine.execute(Side_SQL.__table__.insert(), new_sides)128 # update cards129 cards = db.session.query(Card_SQL).filter_by(set_id=set_id).all()130 card_fields = dict(filter(lambda elem: 'cell' in elem[0] and '][0]' in elem[0] and 'cell[0]' not in elem[0], form.items()))131 if len(card_fields) < len(cards): # delete removed cards132 for i in range(len(card_fields), len(cards)):133 db.session.query(Cell_SQL).filter_by(card_id=cards[i].card_ID).delete()134 db.session.query(Card_SQL).filter_by(card_ID=cards[i].card_ID).delete()135 db.session.commit()136 # existing cards don't need to be updated137 new_cards = []138 if len(card_fields) > len(cards): # new cards139 for i in range(len(cards), len(card_fields)):140 card = {'set_id': set_id}141 new_cards.append(card)142 print(new_cards)143 db.engine.execute(Card_SQL.__table__.insert(), new_cards)144 num_cards = min(len(cards), len(card_fields))145 # update cells146 cards = db.session.query(Card_SQL).filter_by(set_id=set_id).all()147 sides = db.session.query(Side_SQL).filter_by(set_id=set_id).all()148 card_index = cards[0].card_ID149 side_index = sides[0].side_id150 cells = []151 for i in range(len(cards)):152 for j in range(len(sides)):153 if i < num_cards and j < num_sides: # update existing cell154 cell = db.session.query(Cell_SQL).filter_by(card_id=cards[i].card_ID, side_id=sides[j].side_id).one()155 cell.info = form['cell[' + str(i+1) + '][' + str(j) + ']']156 db.session.commit()157 else:158 cell = {'card_id': cards[i].card_ID, 'side_id': sides[j].side_id, 'info': form['cell[' + str(i+1) + '][' + str(j) + ']']}159 cells.append(cell)160 if cells:161 db.engine.execute(Cell_SQL.__table__.insert(), cells)162### DELETE163def delete_set(set_id): # deletes a given set from the db164 sides = query_sides(set_id)165 for side in sides:166 db.session.query(Cell_SQL).filter_by(side_id=side).delete()167 db.session.query(Side_SQL).filter_by(set_id=set_id).delete()168 db.session.query(Card_SQL).filter_by(set_id=set_id).delete()169 db.session.query(Set_SQL).filter_by(set_id=set_id).delete()...

Full Screen

Full Screen

sat_solver.py

Source:sat_solver.py Github

copy

Full Screen

1#!/usr/bin/env python32import os3import sys4module_path = os.path.abspath(os.path.join('..'))5if module_path not in sys.path:6 sys.path.append(module_path)7import argparse as ap8from sat.lib.data_processor import InputProcessor, OutputProcessor9from sat.lib.genetic import Genetic10def parse_args():11 parser = ap.ArgumentParser()12 parser.add_argument("set_id", help="id of the data set")13 versions = ["t1", "t2", "c1", "c2", "c3"]14 parser.add_argument(15 "-v", "--version",16 required=True,17 choices=versions,18 help="version of the algorithm run"19 )20 return parser.parse_args()21def tune_params1(set_id, insts, version):22 opts = {"p": 200, "g": 200, "pan": False, "war": False}23 cs = [0.97, 0.99, 0.999]24 ms = [0.01, 0.05, 0.1]25 for c in cs:26 for m in ms:27 opts["c"] = c28 opts["m"] = m29 run(opts, insts, set_id, version)30def tune_params2(set_id, insts, version):31 opts = {"c": 0.999, "m": 0.10, "pan": False, "war": False}32 ps = [200, 350, 500]33 gs = [200, 350, 500]34 for p in ps:35 for g in gs:36 opts["p"] = p37 opts["g"] = g38 run(opts, insts, set_id, version)39def compute1(set_id, insts, version):40 opts = {"p": 500, "g": 200, "c": 0.999, "m": 0.1, "pan": False, "war": False}41 run(opts, insts, set_id, version)42def compute2(set_id, insts, version):43 opts = {"p": 500, "g": 200, "c": 0.999, "m": 0.1, "pan": True, "war": False}44 run(opts, insts, set_id, version)45def compute3(set_id, insts, version):46 opts = {"p": 500, "g": 200, "c": 0.999, "m": 0.1, "pan": False, "war": True}47 run(opts, insts, set_id, version)48def run(opts, insts, set_id, version):49 sols = []50 for inst in insts:51 gen = Genetic(inst, opts)52 gen.run()53 sols.append(gen.sol)54 OutputProcessor(sols, set_id, opts, version).write_sols()55def main():56 args = parse_args()57 set_id = args.set_id58 version = args.version59 insts = InputProcessor(set_id).prepare_instances()60 if version == "t1":61 tune_params1(set_id, insts, version)62 elif version == "t2":63 tune_params2(set_id, insts, version)64 elif version == "c1":65 compute1(set_id, insts, version)66 elif version == "c2":67 compute2(set_id, insts, version)68 elif version == "c3":69 compute3(set_id, insts, version)70if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful