This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| http.HandleFunc("/login", loginHandler) | |
| http.HandleFunc("/logout", logoutHandler) | |
| http.HandleFunc("/register", registerHandler) | |
| http.HandleFunc("/add-book", bookHandler) | |
| http.HandleFunc("/", viewHandler) | |
| http.ListenAndServe(":8080", nil) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // True if there was not an attack | |
| clear := attackChecking(usr.Input) | |
| if(!clear){ | |
| // remove or fix accordingly | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| ) | |
| func handler(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <head> | |
| <br> | |
| <div>{{.UserData}}</div> | |
| <h1>{{.Title}}</h1> | |
| </head> | |
| <sidebar> | |
| {{.Bar}} | |
| </sidebar> | |
| <br> | |
| <body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Page struct, which will contain template | |
| type Page struct { | |
| Title string | |
| Body template.HTML | |
| UserData template.HTML | |
| Bar template.HTML | |
| } | |
| // Loads a page for use | |
| func loadPage(title string, r *http.Request) (*Page, error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Shows a particular page | |
| func viewHandler(w http.ResponseWriter, r *http.Request) { | |
| // Parses URL to obtain title of file to add to .body | |
| title := r.URL.Path[len("/"):] | |
| // Load templatized page, given title | |
| p, err := loadPage(title, r) | |
| // If they do not have a cookie force them to login |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def svd_LeastSquares(A, b): | |
| U, s, V = np.linalg.svd(A) | |
| r = [0.0, 0.0] | |
| r += (1/s[0]) * (U[:,0].T*b) * (V[:,0].T) | |
| r += (1/s[1]) * (U[:,1].T*b) * (V[:,1].T) | |
| return r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fit = [] | |
| for i in range(len(A)): | |
| fit.append([A[i, 0], A[i, 0] * M[0, 0] + M[0, 1]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy.linalg import solve | |
| def jacobi(A, b, x, n): | |
| D = np.diag(A) | |
| R = A - np.diagflat(D) | |
| for i in range(n): | |
| x = (b - np.dot(R,x))/ D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy.linalg import solve | |
| def gauss(A, b, x, n): | |
| L = np.tril(A) | |
| U = A - L | |
| for i in range(n): | |
| x = np.dot(np.linalg.inv(L), b - np.dot(U, x)) | |
| print str(i).zfill(3), |