-
DNS lookup
-
TCP connection Open
-
TLS handshake
-
HTML parsing
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
| fn read_vec(infile: &str) -> Vec<u8> { | |
| fs::read(infile) | |
| .expect("Failed to read file to vector") | |
| } | |
| // Or using '?' operator | |
| fn read_byte(fname: &str) -> io::Result<Vec<u8>> { | |
| let v = fs::read(fname)?; | |
| Ok(v) | |
| } |
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 | |
| /* Encoding/decoding byte buffer to hex */ | |
| import( | |
| "io" | |
| "os" | |
| "bytes" | |
| "encoding/hex" | |
| ) |
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
| let arr = [ | |
| { "name": "apple", "price": 10 }, | |
| { "name": "banana", "price": 20 }, | |
| { "name": "orange", "price": 30 } | |
| ]; | |
| // basic iteration | |
| for (let i = 0; i < arr.length; i++) { | |
| console.log(`name: ${arr[i].name}, price: ${arr[i].price}`); | |
| }; |
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 React from "react" | |
| class Clock extends React.Component { | |
| state = { | |
| date: new Date() | |
| } | |
| componentDidMount() { | |
| this.timerId = setInterval(() => { |
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 React, {useState, useEffect} from 'react' | |
| export default function ToDo() { | |
| const [todo, setTodo] = useState(""); | |
| // const [todos, setTodos] = useState([{id: 0, text: "default task"}]); | |
| // Now it remembers saved Todo list | |
| const [todos, setTodos] = useState(() => { | |
| const savedTodos = localStorage.getItem("todos"); | |
| if (savedTodos) { |
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
| /* Spread: expands array into elements */ | |
| arr = [1, 2, 3]; | |
| arr1 = [...arr, 4]; // [1, 2, 3, 4] | |
| /* Rest: condenses elements into array */ | |
| function multiply(multiplier, ...args) { | |
| return args.map(num => num * multiplier); | |
| } | |
| multiply(2, 3, 4); // [6, 8] |
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 | |
| /* The many ways to read/write files in Go */ | |
| import ( | |
| "bytes" | |
| "io" | |
| "os" | |
| "fmt" // For performance testing |
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
| const arr = ["abc", "def", "xyz"]; | |
| function reverseArray(inArr) { | |
| const result = new Array; | |
| for (let i = inArr.length - 1; i >= 0; i--) { | |
| result.push(inArr[i]); | |
| } | |
| return result; | |
| } |
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 ( | |
| "crypto/rand" | |
| "crypto/rsa" | |
| "crypto/sha256" | |
| "crypto/x509" | |
| "encoding/base64" | |
| "encoding/pem" |
OlderNewer