├── .gitignore ├── .idea ├── misc.xml ├── modules.xml ├── notebook.iml ├── vcs.xml └── workspace.xml ├── .vscode └── launch.json ├── Algorithms ├── .idea │ ├── algorithms.iml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── Chapter-1 │ ├── 1.1 │ │ ├── codes │ │ │ ├── BinarySearch.class │ │ │ ├── BinarySearch.java │ │ │ ├── In.class │ │ │ ├── In.java │ │ │ ├── Out.java │ │ │ ├── Practice.class │ │ │ ├── Practice.java │ │ │ ├── StdDraw$RetinaImageIcon.class │ │ │ ├── StdDraw.class │ │ │ ├── StdDrawExample.class │ │ │ ├── StdDrawExample.java │ │ │ ├── StdIn.class │ │ │ ├── StdIn.java │ │ │ ├── StdInExample.class │ │ │ ├── StdInExample.java │ │ │ ├── StdOut.class │ │ │ ├── StdOut.java │ │ │ ├── StdOutExample.class │ │ │ ├── StdOutExample.java │ │ │ ├── StdRandom.class │ │ │ └── StdRandom.java │ │ └── practise.md │ ├── 1.2 │ │ ├── codes │ │ │ ├── Accumulator.class │ │ │ ├── Accumulator.java │ │ │ ├── BasicDate.class │ │ │ ├── BasicDate.java │ │ │ ├── Cat.class │ │ │ ├── Cat.java │ │ │ ├── Counter.class │ │ │ ├── Counter.java │ │ │ ├── Flips.class │ │ │ ├── Flips.java │ │ │ ├── FlipsMax.class │ │ │ ├── FlipsMax.java │ │ │ ├── In.class │ │ │ ├── In.java │ │ │ ├── Interval1D$1.class │ │ │ ├── Interval1D$LengthComparator.class │ │ │ ├── Interval1D$MaxEndpointComparator.class │ │ │ ├── Interval1D$MinEndpointComparator.class │ │ │ ├── Interval1D.class │ │ │ ├── Interval1D.java │ │ │ ├── Interval2D.class │ │ │ ├── Interval2D.java │ │ │ ├── Interval2DExample.class │ │ │ ├── Interval2DExample.java │ │ │ ├── Out.class │ │ │ ├── Out.java │ │ │ ├── Point2D$1.class │ │ │ ├── Point2D$Atan2Order.class │ │ │ ├── Point2D$DistanceToOrder.class │ │ │ ├── Point2D$PolarOrder.class │ │ │ ├── Point2D$ROrder.class │ │ │ ├── Point2D$XOrder.class │ │ │ ├── Point2D$YOrder.class │ │ │ ├── Point2D.class │ │ │ ├── Point2D.java │ │ │ ├── Practice.java │ │ │ ├── Rolls.class │ │ │ ├── Rolls.java │ │ │ ├── SmallDate.class │ │ │ ├── SmallDate.java │ │ │ ├── StaticSETofInts.class │ │ │ ├── StaticSETofInts.java │ │ │ ├── StdDraw$RetinaImageIcon.class │ │ │ ├── StdDraw.class │ │ │ ├── StdDraw.java │ │ │ ├── StdIn.class │ │ │ ├── StdIn.java │ │ │ ├── StdOut.class │ │ │ ├── StdOut.java │ │ │ ├── StdRandom.class │ │ │ ├── StdRandom.java │ │ │ ├── TestAccumulator.class │ │ │ ├── TestAccumulator.java │ │ │ ├── TestDate.class │ │ │ ├── TestDate.java │ │ │ ├── TestVisualAccumulator.class │ │ │ ├── TestVisualAccumulator.java │ │ │ ├── VisualAccumulator.class │ │ │ ├── VisualAccumulator.java │ │ │ ├── Whitelist.class │ │ │ └── Whitelist.java │ │ └── practise.md │ └── 1.3 │ │ └── codes │ │ ├── Bag$1.class │ │ ├── Bag$ListIterator.class │ │ ├── Bag$Node.class │ │ ├── Bag.class │ │ ├── Bag.java │ │ ├── Evaluate.class │ │ ├── Evaluate.java │ │ ├── FixedCapacityStack.class │ │ ├── FixedCapacityStack.java │ │ ├── FixedCapacityStackOfString.class │ │ ├── FixedCapacityStackOfString.java │ │ ├── Reverse.class │ │ ├── Reverse.java │ │ ├── Stack$1.class │ │ ├── Stack$ListIterator.class │ │ ├── Stack$Node.class │ │ ├── Stack.class │ │ ├── Stack.java │ │ ├── Stats.class │ │ ├── Stats.java │ │ ├── StdIn.class │ │ ├── StdIn.java │ │ ├── StdOut.class │ │ ├── StdOut.java │ │ ├── TestFixedStack.class │ │ └── TestFixedStack.java └── common │ └── StdDraw.java ├── Birdboard ├── 1-Birdboard.md └── readme.md ├── Laravel Series └── 1.Laravel 5.7 From Scratch │ ├── 1.The Laravel Sell.md │ ├── 2.Initial Setup Requirements.md │ └── readme.md ├── Laravel-Authentication-Techniques ├── 2-Authentication-With-GitHub.md └── readme.md ├── README.md ├── Refactoring:Improving the Design of Existing Code └── Chapter 1 │ ├── .gitignore │ ├── Customer.java │ ├── Movie.java │ └── Rental.java ├── forum ├── Chapter-0.md ├── Chapter-1.md ├── Chapter-10.md ├── Chapter-11.md ├── Chapter-12.md ├── Chapter-13.md ├── Chapter-14.md ├── Chapter-15.md ├── Chapter-16.md ├── Chapter-17.md ├── Chapter-18.md ├── Chapter-19.md ├── Chapter-2.md ├── Chapter-20.md ├── Chapter-21.md ├── Chapter-3.md ├── Chapter-4.md ├── Chapter-5.md ├── Chapter-7.md ├── Chapter-8.md ├── Chapter-9.md ├── Chapter-template.md ├── chapter-6.md ├── homestead.rb.bak └── laravel 命令.txt ├── geek-time └── spring-core-coding │ ├── 13-IoC发展简介.md │ └── readme.md ├── how-to-read-code ├── 1-Get-It-Running-Locally.md ├── 2-Finding-The-Documentation-Page.md ├── 3-Markdown-Parsing.md ├── 4-Rendering-The-Documentation.md └── readme.md ├── images ├── .DS_Store ├── authentication-techniques │ ├── .DS_Store │ ├── 2-1.png │ ├── 2-2.png │ ├── 2-3.png │ ├── 2-4.png │ ├── 2-5.png │ └── 2-6.png ├── learn-redis │ ├── 3-1.png │ └── 4-1.png ├── learn-vue │ ├── 18-1.png │ ├── 18-2.png │ ├── 19-1.png │ ├── 19-10.gif │ ├── 19-2.png │ ├── 19-3.png │ ├── 19-4.png │ ├── 19-5.png │ ├── 19-6.png │ ├── 19-7.gif │ ├── 19-8.gif │ ├── 19-9.gif │ ├── 20-1.gif │ ├── 21-1.png │ └── 21-2.png ├── queue-it-up │ ├── 10-1.png │ ├── 2-1.png │ ├── 3-1.png │ ├── 5-1.png │ ├── 5-2.png │ ├── 6-1.png │ ├── 7-1.png │ ├── 7-2.png │ ├── 7-3.png │ ├── 7-4.png │ ├── 7-5.png │ ├── 8-1.png │ ├── 9-1.png │ └── 9-2.png └── testing-laravel │ ├── 11-1.png │ ├── 11-10.png │ ├── 11-2.png │ ├── 11-3.png │ ├── 11-4.png │ ├── 11-5.png │ ├── 11-6.png │ ├── 11-7.png │ ├── 11-8.png │ └── 11-9.png ├── katas ├── 1.Prime Factors.md ├── 2.Roman Numerals.md ├── 3.Bowling Game.md └── readme.md ├── learn-redis ├── 1-Installation-and-a-Visitor-Counter.md ├── 2-Counters-and-Namespacing.md ├── 3-Trending-Articles-with-Sorted-Sets.md ├── 4-Hashes-and-Caching.md ├── 5-Caching-With-Redis.md └── readme.md ├── learn-vue ├── episode1-Basic Data Binding.md ├── episode10-Modal.md ├── episode11-Tabs.md ├── episode12-Custom Event.md ├── episode13-Event Dispatcher.md ├── episode14-Named Slots in Nutshell.md ├── episode15-Inline Templates.md ├── episode16-Webpack & Vue-CLI.md ├── episode17-HRM.md ├── episode18-Vue Ajax Requests With Axios.md ├── episode19-Object-Oriented-Forms-Part-1.md ├── episode2-Setup Vue Devtools.md ├── episode20-Object-Oriented-Forms-Part-2.md ├── episode21-Object-Oriented-Forms-Part-3.md ├── episode3-Lists.md ├── episode4-Vue Event Listener.md ├── episode5-Attributes and Class Name Binding.md ├── episode6-The Need For Computed Properties.md ├── episode7-Components 101.md ├── episode8-Components Within Components.md ├── episode9-Message.md └── readme.md ├── queue-it-up ├── 1-Pizza-Time.md ├── 10-Source-Diving-the-Dispatcher.md ├── 11-Source-Diving-the-Queue-Worker.md ├── 2-Dispatch-Your-First-Job.md ├── 3-Job-Classes-and-Daemons.md ├── 4-Dispatchable.md ├── 5-Failed-Jobs.md ├── 6-A-Dashboard-For-Your-Redis-Backed-Queues.md ├── 7-Multiple-Queues-and-Workers.md ├── 8-Storing-Jobs-in-the-Database.md ├── 9-Take-a-Ride-on-the Laravel-Pipeline.md └── readme.md └── testing-laravel ├── 1.Introduction to Application Testing.md ├── 10.Test Method Refactoring.md ├── 11.Design a Fluent API With TDD.md ├── 2.Begin Unit Test.md ├── 3.More Unit Testing Review.md ├── 4.Testing Eloquent Models.md ├── 5.A Testing Database Connection.md ├── 6.Hands On Workflow.md ├── 7.Homework Solutions.md ├── 8.Regression Tests.md ├── 9.Liking A Model With TDD.md └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Algorithms/Chapter-1/1.1/files/ 3 | Algorithms/Chapter-1/1.2/files/ 4 | Algorithms/Chapter-1/1.3/files/ 5 | .idea/* 6 | .vscode/* -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/notebook.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "type": "java", 5 | "name": "CodeLens (Launch) - Rolls", 6 | "request": "launch", 7 | "mainClass": "Rolls", 8 | "projectName": "notebook_fcc970ce" 9 | }, 10 | { 11 | "type": "java", 12 | "name": "CodeLens (Launch) - Filps", 13 | "request": "launch", 14 | "mainClass": "Filps", 15 | "projectName": "notebook_fcc970ce" 16 | }, 17 | { 18 | "type": "java", 19 | "name": "CodeLens (Launch) - Counter", 20 | "request": "launch", 21 | "mainClass": "Counter", 22 | "projectName": "notebook_fcc970ce" 23 | }, 24 | { 25 | "type": "java", 26 | "name": "CodeLens (Launch) - Practice", 27 | "request": "launch", 28 | "mainClass": "Practice", 29 | "projectName": "notebook_fcc970ce" 30 | }, 31 | { 32 | "type": "java", 33 | "name": "CodeLens (Launch) - StdDrawExample", 34 | "request": "launch", 35 | "mainClass": "StdDrawExample", 36 | "projectName": "notebook_fcc970ce" 37 | }, 38 | { 39 | "type": "java", 40 | "name": "CodeLens (Launch) - BinarySearch", 41 | "request": "launch", 42 | "mainClass": "BinarySearch" 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /Algorithms/.idea/algorithms.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /Algorithms/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/BinarySearch.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/BinarySearch.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/BinarySearch.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Compilation: javac BinarySearch.java 3 | * Execution: java BinarySearch whitelist.txt < input.txt 4 | * Dependencies: In.java StdIn.java StdOut.java 5 | * Data files: https://algs4.cs.princeton.edu/11model/tinyW.txt 6 | * https://algs4.cs.princeton.edu/11model/tinyT.txt 7 | * https://algs4.cs.princeton.edu/11model/largeW.txt 8 | * https://algs4.cs.princeton.edu/11model/largeT.txt 9 | * 10 | * % java BinarySearch tinyW.txt < tinyT.txt 11 | * 50 12 | * 99 13 | * 13 14 | * 15 | * % java BinarySearch largeW.txt < largeT.txt | more 16 | * 499569 17 | * 984875 18 | * 295754 19 | * 207807 20 | * 140925 21 | * 161828 22 | * [367,966 total values] 23 | * 24 | ******************************************************************************/ 25 | 26 | import java.util.Arrays; 27 | 28 | /** 29 | * The {@code BinarySearch} class provides a static method for binary 30 | * searching for an integer in a sorted array of integers. 31 | *

32 | * The indexOf operations takes logarithmic time in the worst case. 33 | *

34 | * For additional documentation, see Section 1.1 of 35 | * Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne. 36 | * 37 | * @author Robert Sedgewick 38 | * @author Kevin Wayne 39 | */ 40 | public class BinarySearch { 41 | 42 | /** 43 | * This class should not be instantiated. 44 | */ 45 | private BinarySearch() { } 46 | 47 | /** 48 | * Returns the index of the specified key in the specified array. 49 | * 50 | * @param a the array of integers, must be sorted in ascending order 51 | * @param key the search key 52 | * @return index of key in array {@code a} if present; {@code -1} otherwise 53 | */ 54 | public static int indexOf(int[] a, int key) { 55 | int lo = 0; 56 | int hi = a.length - 1; 57 | while (lo <= hi) { 58 | // Key is in a[lo..hi] or not present. 59 | int mid = lo + (hi - lo) / 2; 60 | if (key < a[mid]) hi = mid - 1; 61 | else if (key > a[mid]) lo = mid + 1; 62 | else return mid; 63 | } 64 | return -1; 65 | } 66 | 67 | /** 68 | * Returns the index of the specified key in the specified array. 69 | * This function is poorly named because it does not give the rank 70 | * if the array has duplicate keys or if the key is not in the array. 71 | * 72 | * @param key the search key 73 | * @param a the array of integers, must be sorted in ascending order 74 | * @return index of key in array {@code a} if present; {@code -1} otherwise 75 | * @deprecated Replaced by {@link #indexOf(int[], int)}. 76 | */ 77 | @Deprecated 78 | public static int rank(int key, int[] a) { 79 | return indexOf(a, key); 80 | } 81 | 82 | /** 83 | * Reads in a sequence of integers from the whitelist file, specified as 84 | * a command-line argument; reads in integers from standard input; 85 | * prints to standard output those integers that do not appear in the file. 86 | * 87 | * @param args the command-line arguments 88 | */ 89 | public static void main(String[] args) { 90 | 91 | // read the integers from a file 92 | In in = new In(args[0]); 93 | int[] whitelist = in.readAllInts(); 94 | 95 | // sort the array 96 | Arrays.sort(whitelist); 97 | 98 | // read integer key from standard input; print if not in whitelist 99 | while (!StdIn.isEmpty()) { 100 | int key = StdIn.readInt(); 101 | if (BinarySearch.indexOf(whitelist, key) == -1) 102 | StdOut.println(key); 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/In.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/In.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/Practice.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/Practice.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/Practice.java: -------------------------------------------------------------------------------- 1 | // import java.util.Arrays; 2 | 3 | public class Practice 4 | { 5 | public static void main(String[] args) { 6 | StdOut.print("xxx"); 7 | } 8 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdDraw$RetinaImageIcon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdDraw$RetinaImageIcon.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdDraw.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdDraw.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdDrawExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdDrawExample.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdDrawExample.java: -------------------------------------------------------------------------------- 1 | public class StdDrawExample 2 | { 3 | public static void main(String[] args) 4 | { 5 | int N = 50; 6 | StdDraw.setXscale(0,N); 7 | StdDraw.setYscale(0,N*N); 8 | StdDraw.setPenRadius(.01); 9 | 10 | for(int i = 1;i <= N; i++) 11 | { 12 | StdDraw.point(i, i); 13 | StdDraw.point(i,i*i); 14 | StdDraw.point(i, i*Math.log(i)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdIn.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdIn.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdInExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdInExample.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdInExample.java: -------------------------------------------------------------------------------- 1 | public class StdInExample 2 | { 3 | public static void main(String[] args) 4 | { 5 | double sum = 0.0; 6 | int cnt = 0; 7 | 8 | while(! StdIn.isEmpty()) 9 | { 10 | sum += StdIn.readDouble(); 11 | cnt++; 12 | } 13 | double avg = sum / cnt; 14 | StdOut.printf("Average is %.5f\n", avg); 15 | } 16 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdOut.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdOut.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdOutExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdOutExample.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdOutExample.java: -------------------------------------------------------------------------------- 1 | 2 | public class StdOutExample 3 | { 4 | public static void main(String[] args) 5 | { 6 | int n = Integer.parseInt(args[0]); 7 | 8 | double lo = Double.parseDouble(args[1]); 9 | double hi = Double.parseDouble(args[2]); 10 | 11 | for (int i = 1;i < n;i++) 12 | { 13 | double x = StdRandom.uniform(lo,hi); 14 | 15 | StdOut.printf("%.2f\n", x); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/codes/StdRandom.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.1/codes/StdRandom.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.1/practise.md: -------------------------------------------------------------------------------- 1 | * 1.1.1 2 | a:`7` 3 | b:`200.0000002` 4 | c:`true` 5 | 6 | * 1.1.2 7 | a:`float 1.618` 8 | b:`float 10.0` 9 | c:`bool true` 10 | d:`string 33` 11 | 12 | * 1.1.3 13 | ``` 14 | public static void main(String[] args) { 15 | // practice 3 16 | int[] params = StdIn.readAllInts(); 17 | int one = params[0]; 18 | int two = params[1]; 19 | int three = params[2]; 20 | 21 | if(one == two && two == three){ 22 | StdOut.print("equal"); 23 | }else { 24 | StdOut.print(" not equal"); 25 | } 26 | } 27 | ``` 28 | 29 | * 1.1.4 30 | a:`格式错误,then` 31 | b:`格式错误,if` 32 | c:`正确` 33 | d:`格式错误,c=0;` 34 | 35 | * 1.1.5 36 | 37 | ``` 38 | public static void main(String[] args) { 39 | double x = 0.5,y = 7.7887667; 40 | 41 | if(InZeroAndOne(x,y)) { 42 | StdOut.print(true); 43 | }else { 44 | StdOut.print(false); 45 | } 46 | } 47 | 48 | public static boolean InZeroAndOne(double x,double y) { 49 | if(x > 0 && x < 1 && y > 0 && y < 1) return true; 50 | 51 | return false; 52 | } 53 | ``` 54 | 55 | * 1.1.6 56 | 会输出斐波那契数列,因为 `g`的值就是上一个`f`的值,实际就是 `f(n) = f(n-1) + f(n-2)`。 57 | ``` 58 | 0 59 | 1 60 | 1 61 | 2 62 | 3 63 | 5 64 | 8 65 | 13 66 | 21 67 | 34 68 | 55 69 | 89 70 | 144 71 | 233 72 | 377 73 | 610 74 | ``` 75 | 76 | * 1.1.7 77 | 78 | a:3.00009155413138 79 | b:499500 80 | c:1023 81 | 82 | * 1.1.8 83 | 84 | a:b,单纯输出字符 85 | b:197,b 的 ASCII 值是 98,c 是 99 86 | c:e,a 的 ASCII 值是 97,101 转换后对应 e 87 | 88 | * 1.1.9 89 | ``` 90 | String s = ""; 91 | 92 | for (int n = N;n > 0; n /= 2) 93 | s = (n % 2) + s; 94 | ``` 95 | 96 | * 1.1.10 97 | 98 | 略 99 | 100 | * 1.1.11 -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Accumulator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Accumulator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Accumulator.java: -------------------------------------------------------------------------------- 1 | public class Accumulator 2 | { 3 | private double total; 4 | private int N; 5 | 6 | public void addDataValue(double val) { 7 | N++; 8 | total += val; 9 | } 10 | 11 | public double mean() { 12 | return total / N; 13 | } 14 | 15 | public String toString() { 16 | return "Mean (" + N + " values): " + String.format("%7.5f", mean()); 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/BasicDate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/BasicDate.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/BasicDate.java: -------------------------------------------------------------------------------- 1 | public class BasicDate 2 | { 3 | private final int month; 4 | private final int day; 5 | private final int year; 6 | 7 | public BasicDate(int m, int d, int y){ 8 | month = m; 9 | day = d; 10 | year = y; 11 | } 12 | 13 | public int month(){ 14 | return month; 15 | } 16 | 17 | public int day() { 18 | return day; 19 | } 20 | 21 | public int year() { 22 | return year; 23 | } 24 | 25 | public String toString(){ 26 | return month + "/" + day + "/" + year; 27 | } 28 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Cat.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Cat.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Cat.java: -------------------------------------------------------------------------------- 1 | public class Cat 2 | { 3 | public static void main(String[] args) 4 | { 5 | Out out = new Out(args[args.length-1]); 6 | 7 | for (int i = 0; i < args.length - 1; i++) 8 | { 9 | In in = new In(args[i]); 10 | String s = in.readAll(); 11 | out.println(s); 12 | in.close(); 13 | } 14 | 15 | out.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Counter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Counter.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Counter.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Compilation: javac Counter.java 3 | * Execution: java Counter n trials 4 | * Dependencies: StdRandom.java StdOut.java 5 | * 6 | * A mutable data type for an integer counter. 7 | * 8 | * The test clients create n counters and performs trials increment 9 | * operations on random counters. 10 | * 11 | * java Counter 6 600000 12 | * 100140 counter0 13 | * 100273 counter1 14 | * 99848 counter2 15 | * 100129 counter3 16 | * 99973 counter4 17 | * 99637 counter5 18 | * 19 | ******************************************************************************/ 20 | 21 | // package edu.princeton.cs.algs4; 22 | 23 | /** 24 | * The {@code Counter} class is a mutable data type to encapsulate a counter. 25 | *

26 | * For additional documentation, 27 | * see Section 1.2 of 28 | * Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne. 29 | * 30 | * @author Robert Sedgewick 31 | * @author Kevin Wayne 32 | */ 33 | public class Counter implements Comparable { 34 | 35 | private final String name; // counter name 36 | private int count = 0; // current value 37 | 38 | /** 39 | * Initializes a new counter starting at 0, with the given id. 40 | * 41 | * @param id the name of the counter 42 | */ 43 | public Counter(String id) { 44 | name = id; 45 | } 46 | 47 | /** 48 | * Increments the counter by 1. 49 | */ 50 | public void increment() { 51 | count++; 52 | } 53 | 54 | /** 55 | * Returns the current value of this counter. 56 | * 57 | * @return the current value of this counter 58 | */ 59 | public int tally() { 60 | return count; 61 | } 62 | 63 | /** 64 | * Returns a string representation of this counter. 65 | * 66 | * @return a string representation of this counter 67 | */ 68 | public String toString() { 69 | return count + " " + name; 70 | } 71 | 72 | /** 73 | * Compares this counter to the specified counter. 74 | * 75 | * @param that the other counter 76 | * @return {@code 0} if the value of this counter equals 77 | * the value of that counter; a negative integer if 78 | * the value of this counter is less than the value of 79 | * that counter; and a positive integer if the value 80 | * of this counter is greater than the value of that 81 | * counter 82 | */ 83 | @Override 84 | public int compareTo(Counter that) { 85 | if (this.count < that.count) return -1; 86 | else if (this.count > that.count) return +1; 87 | else return 0; 88 | } 89 | 90 | 91 | /** 92 | * Reads two command-line integers n and trials; creates n counters; 93 | * increments trials counters at random; and prints results. 94 | * 95 | * @param args the command-line arguments 96 | */ 97 | public static void main(String[] args) { 98 | int n = Integer.parseInt(args[0]); 99 | int trials = Integer.parseInt(args[1]); 100 | 101 | // create n counters 102 | Counter[] hits = new Counter[n]; 103 | for (int i = 0; i < n; i++) { 104 | hits[i] = new Counter("counter" + i); 105 | } 106 | 107 | // increment trials counters at random 108 | for (int t = 0; t < trials; t++) { 109 | hits[StdRandom.uniform(n)].increment(); 110 | } 111 | 112 | // print results 113 | for (int i = 0; i < n; i++) { 114 | StdOut.println(hits[i]); 115 | } 116 | } 117 | } 118 | 119 | /****************************************************************************** 120 | * Copyright 2002-2018, Robert Sedgewick and Kevin Wayne. 121 | * 122 | * This file is part of algs4.jar, which accompanies the textbook 123 | * 124 | * Algorithms, 4th edition by Robert Sedgewick and Kevin Wayne, 125 | * Addison-Wesley Professional, 2011, ISBN 0-321-57351-X. 126 | * http://algs4.cs.princeton.edu 127 | * 128 | * 129 | * algs4.jar is free software: you can redistribute it and/or modify 130 | * it under the terms of the GNU General Public License as published by 131 | * the Free Software Foundation, either version 3 of the License, or 132 | * (at your option) any later version. 133 | * 134 | * algs4.jar is distributed in the hope that it will be useful, 135 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 136 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 137 | * GNU General Public License for more details. 138 | * 139 | * You should have received a copy of the GNU General Public License 140 | * along with algs4.jar. If not, see http://www.gnu.org/licenses. 141 | ******************************************************************************/ -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Flips.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Flips.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Flips.java: -------------------------------------------------------------------------------- 1 | public class Flips 2 | { 3 | public static void main(String[] args) { 4 | int T = Integer.parseInt(args[0]); 5 | Counter heads = new Counter("heads"); 6 | Counter tails = new Counter("tails"); 7 | 8 | for (int t = 0; t < T; t++) 9 | if (StdRandom.bernoulli(0.5)) 10 | heads.increment(); 11 | else tails.increment(); 12 | 13 | StdOut.println(heads); 14 | StdOut.println(tails); 15 | 16 | int d = heads.tally() - tails.tally(); 17 | 18 | StdOut.println("delta: " + Math.abs(d)); 19 | } 20 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/FlipsMax.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/FlipsMax.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/FlipsMax.java: -------------------------------------------------------------------------------- 1 | // import org.w3c.dom.css.Counter; 2 | 3 | public class FlipsMax 4 | { 5 | public static Counter max(Counter x, Counter y) 6 | { 7 | if(x.tally() > y.tally()) return x; 8 | 9 | return y; 10 | } 11 | 12 | public static void main(String[] args) 13 | { 14 | int T = Integer.parseInt(args[0]); 15 | 16 | Counter heads = new Counter("heads"); 17 | Counter tails = new Counter("tails"); 18 | 19 | for(int t = 0; t < T; t++) 20 | if (StdRandom.bernoulli(0.5)) 21 | heads.increment(); 22 | else tails.increment(); 23 | 24 | if(heads.tally() == tails.tally()) 25 | StdOut.println("Tie"); 26 | else StdOut.println(max(heads, tails) + " wins"); 27 | } 28 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/In.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/In.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval1D$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval1D$1.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval1D$LengthComparator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval1D$LengthComparator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval1D$MaxEndpointComparator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval1D$MaxEndpointComparator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval1D$MinEndpointComparator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval1D$MinEndpointComparator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval1D.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval1D.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval2D.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval2D.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval2DExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Interval2DExample.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Interval2DExample.java: -------------------------------------------------------------------------------- 1 | public class Interval2DExample 2 | { 3 | public static void main(String[] args) 4 | { 5 | double xlo = Double.parseDouble(args[0]); 6 | double xhi = Double.parseDouble(args[1]); 7 | double ylo = Double.parseDouble(args[2]); 8 | double yhi = Double.parseDouble(args[3]); 9 | int T = Integer.parseInt(args[4]); 10 | 11 | Interval1D xinterval = new Interval1D(xlo, xhi); 12 | Interval1D yinterval = new Interval1D(ylo, yhi); 13 | Interval2D box = new Interval2D(xinterval, yinterval); 14 | box.draw(); 15 | 16 | Counter c = new Counter("hits"); 17 | 18 | for (int t = 0; t < T; t++) 19 | { 20 | double x = Math.random(); 21 | double y = Math.random(); 22 | Point2D p = new Point2D(x, y); 23 | 24 | if (box.contains(p)) c.increment(); 25 | else p.draw(); 26 | } 27 | 28 | StdOut.println(c); 29 | StdOut.println(box.area()); 30 | } 31 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Out.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Out.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$1.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$Atan2Order.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$Atan2Order.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$DistanceToOrder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$DistanceToOrder.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$PolarOrder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$PolarOrder.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$ROrder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$ROrder.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$XOrder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$XOrder.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D$YOrder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D$YOrder.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Point2D.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Point2D.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Practice.java: -------------------------------------------------------------------------------- 1 | // import java.util.Arrays; 2 | 3 | public class Practice 4 | { 5 | public static void main(String[] args) { 6 | StdOut.print("xxx"); 7 | } 8 | 9 | /** 10 | * 判断字符串是否是回文字符 11 | */ 12 | public static boolean isPalindrome(String s) 13 | { 14 | int N = s.length(); 15 | 16 | for (int i = 0;i < N/2; i++) 17 | { 18 | if(s.charAt(i) != s.charAt(N-1-i)) 19 | return false; 20 | } 21 | 22 | return true; 23 | } 24 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Rolls.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Rolls.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Rolls.java: -------------------------------------------------------------------------------- 1 | public class Rolls 2 | { 3 | public static void main(String[] args) 4 | { 5 | int T = Integer.parseInt(args[0]); 6 | int SIDES = 6; 7 | Counter[] rolls = new Counter[SIDES+1]; 8 | 9 | for (int i = 1;i <= SIDES; i ++) 10 | rolls[i] = new Counter(i + "'s'"); 11 | 12 | for (int t = 0; t < T; t++) 13 | { 14 | int result = StdRandom.uniform(1, SIDES+1); 15 | rolls[result].increment(); 16 | } 17 | 18 | for (int i = 1; i <= SIDES; i++) 19 | StdOut.println(rolls[i]); 20 | } 21 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/SmallDate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/SmallDate.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/SmallDate.java: -------------------------------------------------------------------------------- 1 | public class SmallDate 2 | { 3 | private final int value; 4 | 5 | public SmallDate(int m, int d, int y){ 6 | value = y*512 + m*32 + d; 7 | } 8 | 9 | public int month(){ 10 | return (value / 32) % 16; 11 | } 12 | 13 | public int day() { 14 | return value % 32; 15 | } 16 | 17 | public int year() { 18 | return value / 512; 19 | } 20 | 21 | public String toString(){ 22 | return month() + "/" + day() + "/" + year(); 23 | } 24 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StaticSETofInts.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/StaticSETofInts.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StaticSETofInts.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class StaticSETofInts 4 | { 5 | private int[] a; 6 | 7 | public StaticSETofInts(int[] keys) 8 | { 9 | a = new int[keys.length]; 10 | 11 | for(int i = 0; i < keys.length; i++) { 12 | a[i] = keys[i]; 13 | } 14 | 15 | Arrays.sort(a); 16 | } 17 | 18 | public boolean contains(int key) 19 | { 20 | return rank(key) != -1; 21 | } 22 | 23 | private int rank(int key) 24 | { 25 | // 二分查找 26 | int lo = 0; 27 | int hi = a.length - 1; 28 | while (lo <= hi) { 29 | // 键要么存在于 a[lo],a[hi] 中,要么不存在 30 | int mid = lo + (hi - lo) / 2; 31 | if (key < a[mid]) hi = mid -1; 32 | else if (key > a[mid]) lo = mid + 1; 33 | else return mid; 34 | } 35 | 36 | return -1; 37 | } 38 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StdDraw$RetinaImageIcon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/StdDraw$RetinaImageIcon.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StdDraw.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/StdDraw.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StdIn.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/StdIn.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StdOut.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/StdOut.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/StdRandom.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/StdRandom.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/TestAccumulator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/TestAccumulator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/TestAccumulator.java: -------------------------------------------------------------------------------- 1 | public class TestAccumulator 2 | { 3 | public static void main(String[] args) 4 | { 5 | int T = Integer.parseInt(args[0]); 6 | Accumulator a = new Accumulator(); 7 | 8 | for (int t = 0; t < T; t++){ 9 | a.addDataValue(StdRandom.uniform()); 10 | } 11 | 12 | StdOut.println(a); 13 | } 14 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/TestDate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/TestDate.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/TestDate.java: -------------------------------------------------------------------------------- 1 | public class TestDate 2 | { 3 | public static void main(String[] args) 4 | { 5 | int m1 = Integer.parseInt(args[0]); 6 | int d1 = Integer.parseInt(args[1]); 7 | int y1 = Integer.parseInt(args[2]); 8 | int m2 = Integer.parseInt(args[3]); 9 | int d2 = Integer.parseInt(args[4]); 10 | int y2 = Integer.parseInt(args[5]); 11 | 12 | BasicDate date1 = new BasicDate(m1, d1, y1); 13 | SmallDate date2 = new SmallDate(m2, d2, y2); 14 | 15 | StdOut.println(date1); 16 | StdOut.println(date2); 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/TestVisualAccumulator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/TestVisualAccumulator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/TestVisualAccumulator.java: -------------------------------------------------------------------------------- 1 | public class TestVisualAccumulator 2 | { 3 | public static void main(String[] args) 4 | { 5 | int T = Integer.parseInt(args[0]); 6 | VisualAccumulator a = new VisualAccumulator(T, 1.0); 7 | 8 | for (int t = 0; t < T; t++){ 9 | a.addDataValue(StdRandom.uniform()); 10 | } 11 | 12 | StdOut.println(a); 13 | } 14 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/VisualAccumulator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/VisualAccumulator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/VisualAccumulator.java: -------------------------------------------------------------------------------- 1 | public class VisualAccumulator 2 | { 3 | private double total; 4 | private int N; 5 | 6 | public VisualAccumulator(int trials, double max) 7 | { 8 | StdDraw.setXscale(0, trials); 9 | StdDraw.setYscale(0, max); 10 | StdDraw.setPenRadius(.005); 11 | } 12 | 13 | public void addDataValue(double val) 14 | { 15 | N++; 16 | total += val; 17 | StdDraw.setPenColor(StdDraw.DARK_GRAY); 18 | StdDraw.point(N,val); 19 | StdDraw.setPenColor(StdDraw.RED); 20 | StdDraw.point(N, total / N); 21 | } 22 | 23 | public double mean() { 24 | return total / N; 25 | } 26 | 27 | public String toString() { 28 | return "Mean (" + N + " values): " + String.format("%7.5f", mean()); 29 | } 30 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Whitelist.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/codes/Whitelist.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/codes/Whitelist.java: -------------------------------------------------------------------------------- 1 | public class Whitelist 2 | { 3 | public static void main(String[] args) 4 | { 5 | In in = new In(args[0]); 6 | int[] white = in.readAllInts(); 7 | 8 | StaticSETofInts set = new StaticSETofInts(white); 9 | 10 | while (!StdIn.isEmpty()) 11 | { 12 | int key = StdIn.readInt(); 13 | if(set.contains(key)) 14 | StdOut.println(key); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.2/practise.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.2/practise.md -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Bag$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Bag$1.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Bag$ListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Bag$ListIterator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Bag$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Bag$Node.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Bag.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Bag.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Evaluate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Evaluate.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Evaluate.java: -------------------------------------------------------------------------------- 1 | public class Evaluate 2 | { 3 | public static void main(String[] args) 4 | { 5 | Stack ops = new Stack(); 6 | Stack vals = new Stack(); 7 | 8 | while(! StdIn.isEmpty()) 9 | { 10 | // 读取字符,如果是操作符则压入操作符栈 11 | String s = StdIn.readString(); 12 | if(s.equals("(")){ 13 | 14 | }else if(s.equals("+")) { 15 | ops.push(s); 16 | }else if(s.equals("-")) { 17 | ops.push(s); 18 | }else if(s.equals("*")) { 19 | ops.push(s); 20 | }else if(s.equals("/")) { 21 | ops.push(s); 22 | }else if(s.equals("sqrt")) { 23 | ops.push(s); 24 | }else if(s.equals(")")) { 25 | // 如果是 ),弹出运算符和操作数,计算结果并压入栈 26 | String op = ops.pop(); 27 | double v = vals.pop(); 28 | 29 | if(op.equals("+")) v = vals.pop() + v; 30 | else if(op.equals("-")) v = vals.pop() - v; 31 | else if(op.equals("*")) v = vals.pop() * v; 32 | else if(op.equals("/")) v = vals.pop() / v; 33 | else if(op.equals("sqrt")) v = Math.sqrt(v); 34 | 35 | vals.push(v); 36 | }else{ // 其他则视为数字压入操作符栈 37 | vals.push(Double.parseDouble(s)); 38 | } 39 | } 40 | 41 | StdOut.println(vals.pop()); 42 | } 43 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/FixedCapacityStack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/FixedCapacityStack.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/FixedCapacityStack.java: -------------------------------------------------------------------------------- 1 | public class FixedCapacityStack 2 | { 3 | private Item[] a; 4 | private int N; 5 | 6 | public FixedCapacityStack(int cap) 7 | { 8 | a = (Item[]) new Object[cap]; 9 | } 10 | 11 | public boolean isEmpty() 12 | { 13 | return N ==0; 14 | } 15 | 16 | public int size() 17 | { 18 | return N; 19 | } 20 | 21 | public void push(Item item) 22 | { 23 | a[N++] = item; 24 | } 25 | 26 | public Item pop() 27 | { 28 | return a[--N]; 29 | } 30 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/FixedCapacityStackOfString.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/FixedCapacityStackOfString.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/FixedCapacityStackOfString.java: -------------------------------------------------------------------------------- 1 | public class FixedCapacityStackOfString 2 | { 3 | private String[] a; 4 | private int N; 5 | 6 | public FixedCapacityStackOfString(int cap) 7 | { 8 | a = new String[cap]; 9 | } 10 | 11 | public boolean isEmpty() 12 | { 13 | return N == 0; 14 | } 15 | 16 | public int size() 17 | { 18 | return N; 19 | } 20 | 21 | public void push(String item) 22 | { 23 | a[N++] = item; 24 | } 25 | 26 | public String pop() 27 | { 28 | return a[--N]; 29 | } 30 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Reverse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Reverse.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Reverse.java: -------------------------------------------------------------------------------- 1 | public class Reverse 2 | { 3 | public static void main(String[] args) 4 | { 5 | Stack stack; 6 | 7 | stack = new Stack(); 8 | 9 | while(!StdIn.isEmpty()) 10 | stack.push(StdIn.readInt()); 11 | 12 | for (int i : stack) 13 | StdOut.println(i); 14 | } 15 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Stack$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Stack$1.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Stack$ListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Stack$ListIterator.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Stack$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Stack$Node.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Stack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Stack.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Stats.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/Stats.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/Stats.java: -------------------------------------------------------------------------------- 1 | public class Stats 2 | { 3 | public static void main(String[] args) 4 | { 5 | Bag numbers = new Bag(); 6 | 7 | while(!StdIn.isEmpty()) 8 | numbers.add(StdIn.readDouble()); 9 | 10 | int N = numbers.size(); 11 | 12 | double sum = 0.0; 13 | for (double x : numbers) 14 | sum += x; 15 | 16 | double mean = sum/N; 17 | 18 | sum = 0.0; 19 | for (double x : numbers) 20 | sum += (x - mean)*(x - mean); 21 | 22 | double std = Math.sqrt(sum/(N-1)); 23 | 24 | StdOut.printf("Mean: %.2f\n", mean); 25 | StdOut.printf("Std dev: %.2f\n", std); 26 | } 27 | } -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/StdIn.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/StdIn.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/StdOut.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/StdOut.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/TestFixedStack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qianhuihuiji/notebook/c57f00778a250a9187c30c518d3a8fbe93ef928c/Algorithms/Chapter-1/1.3/codes/TestFixedStack.class -------------------------------------------------------------------------------- /Algorithms/Chapter-1/1.3/codes/TestFixedStack.java: -------------------------------------------------------------------------------- 1 | public class TestFixedStack 2 | { 3 | public static void main(String[] args) 4 | { 5 | FixedCapacityStack s = new FixedCapacityStack(100); 6 | 7 | while(! StdIn.isEmpty()) 8 | { 9 | String item = StdIn.readString(); 10 | 11 | if(! item.equals("-")) { 12 | s.push(item); 13 | }else if (! s.isEmpty()) { 14 | StdOut.print(s.pop() + " "); 15 | } 16 | } 17 | 18 | StdOut.println("(" + s.size() + " left on stack)"); 19 | } 20 | } -------------------------------------------------------------------------------- /Birdboard/1-Birdboard.md: -------------------------------------------------------------------------------- 1 | ### 本节说明 2 | 3 | * 对应第 1 小节 4 | 5 | ### 本节内容 6 | 7 | 8 | 9 | 首先我们新建项目: 10 | ``` 11 | $ laravel new queues-series 12 | ``` 13 | >使用的 `Laravel` 版本是 `5.8.16` 14 | 15 | 在下一节我们正式开启旅程! 16 | 17 | -------------------------------------------------------------------------------- /Birdboard/readme.md: -------------------------------------------------------------------------------- 1 | ### 0.写在前面 2 | * 本系列文章为`laracasts.com` 的系列视频教程——[Build A Laravel App With TDD](https://laracasts.com/series/build-a-laravel-app-with-tdd) 的学习笔记。若喜欢该系列视频,可去该网站订阅后下载该系列视频,**支持正版**。 -------------------------------------------------------------------------------- /Laravel Series/1.Laravel 5.7 From Scratch/1.The Laravel Sell.md: -------------------------------------------------------------------------------- 1 | ### 本节说明 2 | * 对应第 1 小节:The Laravel Sell 3 | 4 | ### 本节内容 5 | 6 | 为什么选择 `Laravel` ?相信大部分人是被它“优雅”的名头吸引而来,那就从现在开始深入地了解它吧! -------------------------------------------------------------------------------- /Laravel Series/1.Laravel 5.7 From Scratch/2.Initial Setup Requirements.md: -------------------------------------------------------------------------------- 1 | ### 本节说明 2 | * 对应第 2 小节:Initial Setup Requirements 3 | 4 | ### 本节内容 5 | 6 | -------------------------------------------------------------------------------- /Laravel Series/1.Laravel 5.7 From Scratch/readme.md: -------------------------------------------------------------------------------- 1 | ### 0.写在前面 2 | * 本系列文章为`laracasts.com` 的系列视频教程——[Laravel 5.7 From Scratch](https://laracasts.com/series/laravel-from-scratch-2018) 的学习笔记。若喜欢该系列视频,可去该网站订阅后下载该系列视频,**支持正版**。 3 | * 此系列我们将一步步地深入探索 `Laravel 5.7` 。 -------------------------------------------------------------------------------- /Laravel-Authentication-Techniques/2-Authentication-With-GitHub.md: -------------------------------------------------------------------------------- 1 | ### 本节说明 2 | * 对应第 2 小节:Authentication With GitHub 3 | * 注:使用的版本为 `Laravel 5.8` 4 | 5 | ### 本节内容 6 | 本节我们来学习第三方登录,我们将以 GitHub 登录作为示例。首先我们需要安装 `laravel/socialite` 包到项目中: 7 | ``` 8 | composer require laravel/socialite 9 | ``` 10 | 在使用 Socialite 之前,我们还需要为应用程序使用的 OAuth 服务添加凭据。 这些凭证应该放在你的 `config/services.php` 配置文件中,并且应该使用密钥 11 | 。以 GitHub 为例: 12 | ``` 13 | 'github' => [ 14 | 'client_id' => env('GITHUB_CLIENT_ID'), 15 | 'client_secret' => env('GITHUB_CLIENT_SECRET'), 16 | 'redirect' => env('GITHUB_CALLBACK_URL'), 17 | ], 18 | ``` 19 | 从以上代码可知,我们需要在 `.env` 文件中维护配置值: 20 | 21 | *.env* 22 | 23 | ``` 24 | GITHUB_CLIENT_ID= 25 | GITHUB_CLIENT_SECRET= 26 | GITHUB_CALLBACK_URL= 27 | ``` 28 | 29 | 我们要从 GitHub 上获取相关配置,按如下步骤所示操作: 30 | 31 | ![file](../images/authentication-techniques/2-1.png) 32 | 33 | 点击注册按钮: 34 | 35 | ![file](../images/authentication-techniques/2-2.png) 36 | 37 | 填写以下内容: 38 | 39 | ![file](../images/authentication-techniques/2-3.png) 40 | 41 | 然后我们就可以得到相关配置的值了: 42 | 43 | ![file](../images/authentication-techniques/2-4.png) 44 | 45 | 然后我们来配置路由: 46 | 47 | ``` 48 | Route::get('auth/github', 'Auth\LoginController@redirectToProvider'); 49 | Route::get('auth/github/callback', 'Auth\LoginController@handleProviderCallback'); 50 | ``` 51 | 52 | 添加控制器方法: 53 | 54 | *app/Http/Controllers/Auth/LoginController.php* 55 | 56 | ``` 57 | . 58 | . 59 | /** 60 | * Redirect the user to the GitHub authentication page. 61 | * 62 | * @return \Illuminate\Http\Response 63 | */ 64 | public function redirectToProvider() 65 | { 66 | return Socialite::driver('github')->redirect(); 67 | } 68 | 69 | /** 70 | * Obtain the user information from GitHub. 71 | * 72 | * @return \Illuminate\Http\Response 73 | */ 74 | public function handleProviderCallback() 75 | { 76 | $user = Socialite::driver('github')->user(); 77 | 78 | dd($user); 79 | // $user->token; 80 | } 81 | . 82 | . 83 | ``` 84 | 现在当我们访问 `login/github` 路由时,就会重定向到 GitHub 网站,进行授权验证。如下图所示: 85 | 86 | ![file](../images/authentication-techniques/2-5.png) 87 | 88 | 注意 uri 中带的参数 `redirect_uri`,当授权通过时,将通过该地址重定向回我们的应用。现在我们点击授权按钮: 89 | 90 | ![file](../images/authentication-techniques/2-6.png) 91 | 92 | 已经成功获取到用户的信息!接下来我们就可以将获取到的用户信息保存到系统当中,并进行登录。示例代码如下: 93 | 94 | ``` 95 | public function handleProviderCallback() 96 | { 97 | $githubUser = Socialite::driver('github')->user(); 98 | // dd($githubUser); 99 | $user = $this->findOrCreate($githubUser); 100 | 101 | Auth::login($user); 102 | } 103 | 104 | public function findOrCreate($githubUser) 105 | { 106 | $user = User::firstOrCreate( 107 | ['email' => $githubUser->email], 108 | ['name' => $githubUser->nickname] 109 | ); 110 | 111 | return $user; 112 | } 113 | ``` 114 | 115 | 要保存的信息字段以实际设计为准,至此,GitHub 登录的流程已经完成了! -------------------------------------------------------------------------------- /Laravel-Authentication-Techniques/readme.md: -------------------------------------------------------------------------------- 1 | ### 0.写在前面 2 | * 本系列文章为`laracasts.com` 的系列视频教程——[Laravel Authentication Techniques](https://laracasts.com/series/laravel-authentication-techniques) 的学习笔记。若喜欢该系列视频,可去该网站订阅后下载该系列视频,**支持正版**。 3 | * 此系列我们将学习到一些 Laravel 的认证方式,包括 email 登录、第三方登录(如 Github)。 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # notebook 2 | 不同项目/教程的总结笔记 3 | ## 1.forum 4 | 一个基于 Laravel 5.5 的论坛教程,使用 TDD 的开发理念,包含测试,重构,Vue 等内容 5 | 6 | ## 2.learn-vue 7 | Vue 2 教程的学习笔记,Learn vue 2 step by step 8 | 9 | ## 3.testing-laravel 10 | Testing Laravel 教程的学习笔记 11 | 12 | ## 4.how-to-read-code 13 | How to Read Code 教程的学习笔记 14 | 15 | ## 5.Authentication-Techniques 16 | Laravel Authentication Techniques 的学习笔记 17 | 18 | ## 6.Queue-It-Up 19 | Laravel Queue It Up 的学习笔记 20 | 21 | ## 7.Birdboard 22 | 23 | [Build A Laravel App With TDD](https://laracasts.com/series/build-a-laravel-app-with-tdd) 视频教程的学习笔记 24 | 25 | ## Algorithms 26 | 27 | 《算法-第四版》 的算法代码和课后习题。 -------------------------------------------------------------------------------- /Refactoring:Improving the Design of Existing Code/Chapter 1/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/* 3 | .vscode/* -------------------------------------------------------------------------------- /Refactoring:Improving the Design of Existing Code/Chapter 1/Customer.java: -------------------------------------------------------------------------------- 1 | class Customer { 2 | private String _name; 3 | private Vector _rentals = new Vector(); 4 | 5 | public Customer (String name) { 6 | _name = name; 7 | } 8 | 9 | public void addRental(Rental arg) { 10 | _rentals.addElement(arg); 11 | } 12 | 13 | public String getName() { 14 | return _name; 15 | } 16 | 17 | public String statement() { 18 | double totalAmount = 0; 19 | int frequentRenterPoints = 0; 20 | Enumeration rentals = _rentals.elements(); 21 | String result = "Rental Record for " + getName() + "\n"; 22 | 23 | while (rentals.hasMoreElements()) { 24 | double thisAmount = 0; 25 | Rental each = (Rental) rentals.nextElement(); 26 | 27 | thisAmount = amountFor(each); 28 | 29 | // add frequent renter points 30 | frequentRenterPoints++; 31 | // add bonus for a two day new release retal 32 | if((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && 33 | each.getDaysRented() > 1) frequentRenterPoints++; 34 | 35 | // show figures for this rental 36 | result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n"; 37 | totalAmount += thisAmount; 38 | } 39 | // add footer lines 40 | result += "Amount owed is " + String.valueOf(totalAmount) + "\n"; 41 | result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points"; 42 | 43 | return result; 44 | } 45 | 46 | private double amountFor(Rental aRental) { 47 | double result = 0; 48 | // determine amounts for each line 49 | switch (aRental.getMovie().getPriceCode()) { 50 | case Movie.REGULAR: 51 | result += 2; 52 | if (aRental.getDaysRented() > 2) 53 | result += (aRental.getDaysRented() - 2) * 1.5; 54 | break; 55 | case Movie.NEW_RELEASE: 56 | result += aRental.getDaysRented() * 3; 57 | break; 58 | case Movie.CHILDRENS: 59 | result += 1.5; 60 | if (aRental.getDaysRented() > 3) 61 | result += (aRental.getDaysRented() - 3) * 1.5; 62 | break; 63 | } 64 | return result; 65 | } 66 | } -------------------------------------------------------------------------------- /Refactoring:Improving the Design of Existing Code/Chapter 1/Movie.java: -------------------------------------------------------------------------------- 1 | public class Movie { 2 | public static final int CHILDRENS = 2; 3 | public static final int REGULAR = 0; 4 | public static final int NEW_RELEASE = 1; 5 | 6 | private String _title; 7 | private int _priceCode; 8 | 9 | public Movie(String title, int priceCode) { 10 | _title = title; 11 | _priceCode = priceCode; 12 | } 13 | 14 | public int getPriceCode() { 15 | return _priceCode; 16 | } 17 | 18 | public void setPriceCode(int arg) { 19 | _priceCode = arg; 20 | } 21 | 22 | public String getTitle() { 23 | return _title; 24 | } 25 | } -------------------------------------------------------------------------------- /Refactoring:Improving the Design of Existing Code/Chapter 1/Rental.java: -------------------------------------------------------------------------------- 1 | class Rental { 2 | private Movie _movie; 3 | private int _daysRented; 4 | 5 | public Rental(Movie movie, int daysRented) { 6 | _movie = movie; 7 | _daysRented = daysRented; 8 | } 9 | 10 | public int getDaysRented() { 11 | return _daysRented; 12 | } 13 | 14 | public Movie getMovie() { 15 | return _movie; 16 | } 17 | } -------------------------------------------------------------------------------- /forum/Chapter-1.md: -------------------------------------------------------------------------------- 1 | ### 0.写在前面 2 | * 本系列文章为`laracasts.com` 的系列视频教程——[Let's Build A Forum with Laravel and TDD](https://laracasts.com/series/lets-build-a-forum-with-laravel) 的学习笔记。若喜欢该系列视频,可去该网站订阅后下载该系列视频,*** 支持正版 ***。 3 | * 视频源码地址:[https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel](http://https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel) 4 | * 本项目为一个 forum(论坛)项目,与本站的第二本实战教程 [Laravel 教程 - Web 开发实战进阶 ( Laravel 5.5 )](https://laravel-china.org/courses/laravel-intermediate-training-5.5) 类似,可互相参照 5 | * 项目开发模式为`TDD`开发,教程简介为: 6 | > A forum is a deceptively complex thing. Sure, it's made up of threads and replies, but what else might exist as part of a forum? What about profiles, or thread subscriptions, or filtering, or real-time notifications? As it turns out, a forum is the perfect project to stretch your programming muscles. In this series, we'll work together to build one with tests from A to Z. 7 | * 项目版本为`laravel 5.4`,教程后面会进行升级到`laravel 5.5`的教学 8 | * 视频教程共计 102 个小节,笔记章节与视频教程一一对应 9 | 10 | ### 1.本节说明 11 | 12 | * 对应视频教程第 1 小节:Initial Database Setup With Seeding 13 | 14 | ### 2.本节内容 15 | #### 开发环境 16 | * 开发环境与本站推荐开发环境统一,详见:[Laravel 开发环境部署](https://laravel-china.org/docs/laravel-development-environment/5.5) 17 | * 编辑器选用 PHP storm 18 | 19 | #### 新建项目 20 | 首先开启虚拟机: 21 | ``` 22 | > cd ~/Homestead && vagrant up 23 | > vagrant ssh 24 | ``` 25 | 新建一个名为 forum 的项目: 26 | ``` 27 | $ cd ~/Code 28 | $ composer create-project laravel/laravel forum --prefer-dist "5.4.*" 29 | ``` 30 | 31 | #### 构建模型 32 | 在本项目中,最基本的模型为 Thread , Reply , User : 33 | 34 | ``` 35 | # forum 36 | 37 | 1.Thread 38 | 2.Reply 39 | 3.User 40 | 41 | A.Thread is created by a user 42 | B.A reply belongs to a thread,and belongs to a user. 43 | ``` 44 | 建立`Thread`模型、迁移文件与控制器: 45 | ``` 46 | $ php artisan make:model Thread -mr 47 | ``` 48 | 会同时生成`app\Thread.php`模型文件,`app\Http\Controllers\ThreadController.php`控制器,`database\migrations\{timestamp}_create_threads_table.php`迁移。 49 | ``` 50 | 注:该命令生成控制器时,应修改为复数形式,如 app\Http\Controllers\ThreadsController.php 51 | ``` 52 | 修改``app\Thread.php``文件: 53 | ```php 54 | . 55 | . 56 | class Thread extends Model 57 | { 58 | protected $guarded = []; // 意味所有属性均可更新,后期会修复此安全隐患 59 | . 60 | . 61 | ``` 62 | 修改`database\migrations\{timestamp}_create_threads_table.php`文件: 63 | 64 | ```php 65 | . 66 | . 67 | public function up() 68 | { 69 | Schema::create('threads', function (Blueprint $table) { 70 | $table->increments('id'); 71 | $table->integer('user_id'); 72 | $table->string('title'); 73 | $table->text('body'); 74 | $table->timestamps(); 75 | }); 76 | } 77 | . 78 | . 79 | ``` 80 | 修改`.env`文件: 81 | ``` 82 | APP_NAME=forum 83 | . 84 | . 85 | APP_URL=http://forum.test 86 | . 87 | . 88 | DB_DATABASE=forum 89 | . 90 | . 91 | ``` 92 | 建立`forum`数据库,并运行迁移: 93 | ``` 94 | $ php artisan migrate 95 | ``` 96 | 建立`Reply`模型、迁移文件与控制器: 97 | ``` 98 | $ php artisan make:model Reply -mr 99 | ``` 100 | 修改``app\Reply.php``文件: 101 | ```php 102 | . 103 | . 104 | class Reply extends Model 105 | { 106 | protected $guarded = []; 107 | . 108 | . 109 | ``` 110 | 修改`database\migrations\{timestamp}_create_replies_table.php`文件 111 | ```php 112 | . 113 | . 114 | public function up() 115 | { 116 | Schema::create('replies', function (Blueprint $table) { 117 | $table->increments('id'); 118 | $table->integer('thread_id'); 119 | $table->integer('user_id'); 120 | $table->text('body'); 121 | $table->timestamps(); 122 | }); 123 | } 124 | . 125 | . 126 | ``` 127 | 再次运行迁移: 128 | ``` 129 | $ php artisan migrate 130 | ``` 131 | 132 | #### 模型工厂 133 | 134 | 修改`database\factories\ModelFactory.php`如下: 135 | ```php 136 | define(App\User::class, function (Faker\Generator $faker) { 151 | static $password; 152 | 153 | return [ 154 | 'name' => $faker->name, 155 | 'email' => $faker->unique()->safeEmail, 156 | 'password' => $password ?: $password = bcrypt('123456'), 157 | 'remember_token' => str_random(10), 158 | ]; 159 | }); 160 | 161 | $factory->define(App\Thread::class,function ($faker){ 162 | return [ 163 | 'user_id' => function () { 164 | return factory('App\User')->create()->id; 165 | }, 166 | 'title' => $faker->sentence, 167 | 'body' => $faker->paragraph, 168 | ]; 169 | }); 170 | 171 | $factory->define(App\Reply::class,function ($faker){ 172 | return [ 173 | 'thread_id' => function () { 174 | return factory('App\Thread')->create()->id; 175 | }, 176 | 'user_id' => function () { 177 | return factory('App\User')->create()->id; 178 | }, 179 | 'body' => $faker->paragraph, 180 | ]; 181 | }); 182 | 183 | ``` 184 | #### 数据填充 185 | 进入`tinker`环境: 186 | ``` 187 | $ php artisan tinker 188 | ``` 189 | 依次执行以下语句,填充假数据: 190 | ``` 191 | >>> factory('App\Thread',50)->create() 192 | >>> $threads = factory('App\Thread',50)->create() 193 | >>> $threads->each(function ($thread){ factory('App\Reoly',10)->create(['thread_id' => $thread->id]);}); 194 | ``` 195 | 196 | ### 3.笔记心得 197 | * Git 相关操作略去不表 198 | * 自己动手写笔记才更体会到本站实战教程撰写的用心,给编者大大们大大的赞! 199 | 200 | ### 4.写在后面 201 | * 如有建议或意见,欢迎指出~ 202 | * 如果觉得文章写的不错,请点赞鼓励下哈,你的鼓励将是我的动力! -------------------------------------------------------------------------------- /forum/Chapter-11.md: -------------------------------------------------------------------------------- 1 | ## 0.写在前面 2 | 3 | * 本系列文章为`laracasts.com` 的系列视频教程——[Let's Build A Forum with Laravel and TDD](https://laracasts.com/series/lets-build-a-forum-with-laravel) 的学习笔记。若喜欢该系列视频,可去该网站订阅后下载该系列视频,*** 支持正版 ***。 4 | * 视频源码地址:[https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel](http://https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel) 5 | * 本项目为一个 forum(论坛)项目,与本站的第二本实战教程 [Laravel 教程 - Web 开发实战进阶 ( Laravel 5.5 )](https://laravel-china.org/courses/laravel-intermediate-training-5.5) 类似,可互相参照 6 | * 项目开发模式为`TDD`开发,教程简介为: 7 | > A forum is a deceptively complex thing. Sure, it's made up of threads and replies, but what else might exist as part of a forum? What about profiles, or thread subscriptions, or filtering, or real-time notifications? As it turns out, a forum is the perfect project to stretch your programming muscles. In this series, we'll work together to build one with tests from A to Z 8 | * 项目版本为`laravel 5.4`,教程后面会进行升级到`laravel 5.5`的教学 9 | * 视频教程共计 102 个小节,笔记章节与视频教程一一对应 10 | 11 | ### 1.本节说明 12 | * 对应视频第 10 小节:How To Test Validation Errors 13 | 14 | ### 2.本节内容 15 | 我们引入了`Channel`的概念:一个`Thread`属于一个`Channel`,一个`Channel`拥有多个`Thread`。现在我们来实现根据`Channel`筛选`Thread`的功能。 16 | 首先新建测试: 17 | `forum\tests\Feature\ReadThreadsTest.php` 18 | ``` 19 | . 20 | . 21 | /** @test */ 22 | public function a_user_can_filter_threads_according_to_a_tag() 23 | { 24 | $channel = create('App\Channel'); 25 | $threadInChannel = create('App\Thread',['channel_id' => $channel->id]); 26 | $threadNotInChanne = create('App\Thread'); 27 | 28 | $this->get('/threads/' . $channel->slug) 29 | ->assertSee($threadInChannel->title) 30 | ->assertDontSee($threadNotInChanne->title); 31 | } 32 | . 33 | . 34 | ``` 35 | 在测试用例中,我们新建了一个`Channel`两个`Thread`,其中一个`Thread`的`channel_id`是我们新建`Channel`的`id`。我们的测试是,当我们通过该`Channle`来筛选`Thread`,我们希望看到与该`Channel`相关的`Thread`,并且不看到与该`Channel`无关的`Thread`。 36 | 运行测试: 37 | ![file](https://lccdn.phphub.org/uploads/images/201805/02/19192/Y0DYIxsJyd.png?imageView2/2/w/1240/h/0) 38 | 让我们来修复它: 39 | `forum\routes\web.php` 40 | ``` 41 | . 42 | . 43 | Route::get('/home', 'HomeController@index')->name('home'); 44 | Route::get('threads/{channel}','ThreadsController@index'); -->修改此处路由 45 | Route::get('threads/create','ThreadsController@create'); 46 | Route::get('threads/{channel}/{thread}','ThreadsController@show'); 47 | Route::post('threads','ThreadsController@store'); 48 | Route::post('/threads/{channel}/{thread}/replies','RepliesController@store'); 49 | . 50 | . 51 | ``` 52 | `forum\app\Http\Controllers\ThreadsController.php` 53 | ``` 54 | . 55 | . 56 | public function index($channelSlug = null) 57 | { 58 | if($channelSlug){ 59 | $channelId = Channel::where('slug',$channelSlug)->first()->id; 60 | 61 | $threads = Thread::where('channel_id',$channelId)->latest()->get(); 62 | }else{ 63 | $threads = Thread::latest()->get(); 64 | } 65 | 66 | return view('threads.index',compact('threads')); 67 | } 68 | . 69 | . 70 | ``` 71 | 可以看到,我们在控制器中的代码是很粗糙的。我们这么做的原因是为了先让测试通过,稍后进行修改。现在来运行测试: 72 | ``` 73 | $ APP_ENV=testing phpunit --filter a_user_can_filter_threads_according_to_a_tag 74 | ``` 75 | 测试通过: 76 | ![file](https://lccdn.phphub.org/uploads/images/201805/02/19192/9Rw1URAid3.png?imageView2/2/w/1240/h/0) 77 | ### 3.写在后面 78 | * 如有建议或意见,欢迎指出~ 79 | * 如果觉得文章写的不错,请点赞鼓励下哈,你的鼓励将是我的动力! -------------------------------------------------------------------------------- /forum/Chapter-12.md: -------------------------------------------------------------------------------- 1 | ## 0.写在前面 2 | 3 | * 本系列文章为`laracasts.com` 的系列视频教程——[Let's Build A Forum with Laravel and TDD](https://laracasts.com/series/lets-build-a-forum-with-laravel) 的学习笔记。若喜欢该系列视频,可去该网站订阅后下载该系列视频,*** 支持正版 ***。 4 | * 视频源码地址:[https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel](http://https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel) 5 | * *本项目为一个 forum(论坛)项目,与本站的第二本实战教程 [Laravel 教程 - Web 开发实战进阶 ( Laravel 5.5 )](https://laravel-china.org/courses/laravel-intermediate-training-5.5) 类似,可互相参照 6 | * 项目开发模式为`TDD`开发,教程简介为: 7 | > A forum is a deceptively complex thing. Sure, it's made up of threads and replies, but what else might exist as part of a forum? What about profiles, or thread subscriptions, or filtering, or real-time notifications? As it turns out, a forum is the perfect project to stretch your programming muscles. In this series, we'll work together to build one with tests from A to Z. 8 | * 项目版本为 **laravel 5.4**,教程后面会进行升级到 **laravel 5.5** 的教学 9 | * 视频教程共计 102 个小节,笔记章节与视频教程一一对应 10 | 11 | ### 1.本节说明 12 | * 对应视频第 12 小节:Validation Errors And Old Data 13 | 14 | ### 2.本节内容 15 | 现在我们通过访问 [http://forum.test/threads/create](http://forum.test/threads/create) 可以创建新的话题,但我们在主页面无法进入到创建页面。让我们来加上这一功能: 16 | `forum\resources\views\layouts\app.blade.php` 17 | ``` 18 | . 19 | . 20 |