Skip to content

Commit 79a642c

Browse files
committed
Update Spring Boot JSP
1 parent 3d6656f commit 79a642c

31 files changed

Lines changed: 993 additions & 16 deletions

File tree

‎golang-examples/golang-core/go.mod‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
)
6+
7+
var sem = make(chan int, 100)
8+
9+
func Serve(queue chan *Request) {
10+
for req := range queue {
11+
sem <- 1
12+
go func(req *http.Request) {
13+
process(req)
14+
<- sem
15+
}(req)
16+
}
17+
18+
http.HandleFunc()
19+
}
20+
17.3 MB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module system-design
2+
3+
go 1.13
4+
5+
require golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w=
2+
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"log"
7+
8+
"golang.org/x/time/rate"
9+
)
10+
11+
var limiter = rate.NewLimiter(2, 5)
12+
13+
func throttle(next http.Handler) http.Handler {
14+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15+
if !limiter.Allow() {
16+
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
17+
log.Fatalln(http.StatusText(http.StatusTooManyRequests))
18+
return
19+
}
20+
21+
next.ServeHTTP(w, r)
22+
})
23+
}
24+
25+
func handler(w http.ResponseWriter, r *http.Request) {
26+
fmt.Fprintf(w, "Hello, World!")
27+
}
28+
29+
func main() {
30+
mux := http.NewServeMux()
31+
32+
mux.HandleFunc("/", handler)
33+
34+
err := http.ListenAndServe(":8080", throttle(mux))
35+
if err != nil {
36+
panic(err)
37+
}
38+
}
332 KB
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.hellokoding.java.collections;
2+
3+
import java.util.*;
4+
5+
public class ArrayListIterationExample {
6+
public static void main(String[] args) {
7+
List<Integer> arrayList1 = new ArrayList<>(List.of(1, 2, 3));
8+
9+
// Iterate forward with for-index loop
10+
for(int i=0; i<arrayList1.size(); i++){
11+
int ele = arrayList1.get(i);
12+
System.out.printf("%d ", ele); // 1 2 3
13+
}
14+
15+
System.out.println();
16+
17+
// Iterate backward with for-index loop
18+
for(int i=arrayList1.size()-1; i>=0; i--){
19+
int ele = arrayList1.get(i);
20+
System.out.printf("%d ", ele); // 3 2 1
21+
}
22+
23+
System.out.println();
24+
25+
// Iterate forward with for-each loop
26+
for(int ele : arrayList1){
27+
System.out.printf("%d ", ele); // 1 2 3
28+
}
29+
30+
System.out.println();
31+
32+
// Iterate forward with forEach(Consumer) method
33+
arrayList1.forEach(e -> System.out.printf("%d ", e)); // 1 2 3
34+
35+
System.out.println();
36+
37+
// Iterate forward with iterator() method
38+
Iterator<Integer> iterator = arrayList1.iterator();
39+
while (iterator.hasNext()){
40+
System.out.printf("%d ", iterator.next()); // 1 2 3
41+
}
42+
43+
System.out.println();
44+
45+
// Iterate backward with listIterator() method
46+
ListIterator<Integer> listIterator = arrayList1.listIterator(arrayList1.size());
47+
while (listIterator.hasPrevious()){
48+
System.out.printf("%d ", listIterator.previous()); // 3 2 1
49+
}
50+
}
51+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.hellokoding.java.collections;
2+
3+
import java.time.LocalDate;
4+
import java.util.*;
5+
6+
public class ArrayListSortExample {
7+
public static void main(String[] args) {
8+
List<Integer> arrayList1 = new ArrayList<>(List.of(3, 1, 2));
9+
10+
// sort an ArrayList of numbers in ascending order with Collections.sort()
11+
Collections.sort(arrayList1);
12+
System.out.println(arrayList1); // [1, 2, 3]
13+
14+
// sort an ArrayList of numbers in descending order with Collections.sort()
15+
Collections.sort(arrayList1, Comparator.reverseOrder());
16+
System.out.println(arrayList1); // [3, 2, 1]
17+
18+
List<String> arrayList2 = new ArrayList<>(List.of("c", "a", "b"));
19+
20+
// sort an ArrayList of Strings in alphabetical order with sort()
21+
arrayList2.sort(Comparator.naturalOrder());
22+
System.out.println(arrayList2); // [a, b, c]
23+
24+
// sort an ArrayList of Strings in reverse alphabetical order with sort()
25+
arrayList2.sort(Comparator.reverseOrder());
26+
System.out.println(arrayList2); // [c, b, a]
27+
28+
LocalDate ld1 = LocalDate.of(2019, 3, 1);
29+
LocalDate ld2 = LocalDate.of(2019, 1, 1);
30+
LocalDate ld3 = LocalDate.of(2019, 2, 1);
31+
List<LocalDate> arrayList3 = new ArrayList<>(List.of(ld1, ld2, ld3));
32+
33+
// sort an ArrayList of Dates in chronological order
34+
arrayList3.sort(Comparator.naturalOrder());
35+
System.out.println(arrayList3); // [2019-01-01, 2019-02-01, 2019-03-01]
36+
37+
// sort an ArrayList of Dates in reverse chronological order
38+
arrayList3.sort(Comparator.reverseOrder());
39+
System.out.println(arrayList3); // [2019-03-01, 2019-02-01, 2019-01-01]
40+
}
41+
42+
static class Employee implements Comparable<Employee> {
43+
private final Integer id;
44+
private final String name;
45+
46+
public Employee(Integer id, String name) {
47+
this.id = id;
48+
this.name = name;
49+
}
50+
51+
public Integer getId() {
52+
return id;
53+
}
54+
55+
public String getName() {
56+
return name;
57+
}
58+
59+
@Override
60+
public boolean equals(Object o) {
61+
if (this == o) return true;
62+
if (o == null || getClass() != o.getClass()) return false;
63+
Employee employee = (Employee) o;
64+
return Objects.equals(id, employee.id) &&
65+
Objects.equals(name, employee.name);
66+
}
67+
68+
@Override
69+
public int hashCode() {
70+
return Objects.hash(id, name);
71+
}
72+
73+
@Override
74+
public int compareTo(Employee o) {
75+
return Comparator.comparing(Employee::getName)
76+
.compare(this, o);
77+
}
78+
}
79+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.hellokoding.java.collections;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Objects;
6+
7+
public class ArrayListUserDefinedObjectsExample {
8+
public static void main(String[] args) {
9+
Book book1 = new Book(1, "Spring Boot In Practice");
10+
Book book2 = new Book(2, "Algorithms Bootcamp");
11+
List<Book> books = new ArrayList<>();
12+
books.add(book1);
13+
books.add(book2);
14+
15+
System.out.println(books.contains(book1)); // true
16+
System.out.println(books.contains(book2)); // true
17+
}
18+
19+
static class Book {
20+
private final int id;
21+
private final String title;
22+
23+
public Book(int id, String title) {
24+
this.id = id;
25+
this.title = title;
26+
}
27+
28+
public int getId() {
29+
return id;
30+
}
31+
32+
public String getTitle() {
33+
return title;
34+
}
35+
36+
@Override
37+
public boolean equals(Object o) {
38+
if (this == o) return true;
39+
if (o == null || getClass() != o.getClass()) return false;
40+
Book book = (Book) o;
41+
return id == book.id &&
42+
Objects.equals(title, book.title);
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return Objects.hash(id, title);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)