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 ( | |
"log" | |
"os" | |
) | |
/* | |
append.txt initally: | |
An existing line | |
append.txt after calling appendToFile: | |
An existing line |
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 ( | |
// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified. | |
O_RDONLY int = syscall.O_RDONLY // open the file read-only. | |
O_WRONLY int = syscall.O_WRONLY // open the file write-only. | |
O_RDWR int = syscall.O_RDWR // open the file read-write. | |
// The remaining values may be or'ed in to control behavior. | |
O_APPEND int = syscall.O_APPEND // append data to the file when writing. | |
O_CREATE int = syscall.O_CREAT // create a new file if none exists. | |
O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist. | |
O_SYNC int = syscall.O_SYNC // open for synchronous I/O. |
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 ( | |
"log" | |
"os" | |
) | |
func writeFileContents() { | |
content := "Something to write"; | |
/* os.WriteFile takes in file path, a []byte of the file content, | |
and permission bits in case file doesn't exist */ |
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 readFileChunkWise() { | |
chunkSize := 10 // processing the file 10 bytes at a time | |
b := make([]byte, chunkSize) | |
file, err := os.Open("./folder/test.txt); | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
bytesRead, _ := file.Read(b); | |
if bytesRead == 0 { // bytesRead will be 0 at the end of the file. |
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 ( | |
"log" | |
"os" | |
) | |
/* | |
Contents of test.txt: | |
Hello World! | |
*/ |
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 ( | |
"os" | |
) | |
func createFile(){ | |
filePtr, err := os.Create("./test/creating.txt"); | |
if err != nil { | |
log.Fatal(err); | |
} | |
defer filePtr.Close(); // close the file |
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
@app.route("/projects", methods=["GET"]) | |
def getRepos(): | |
try: | |
url = "https://api.github.com/users/Ramko9999/repos" | |
headers = {"Accept":"application/vnd.github.mercy-preview+json"} | |
repos = requests.get(url, headers=headers, auth=(USERNAME,TOKEN)).json() | |
projects = [] | |
for repo in repos: | |
if repo["homepage"]: | |
project = { |
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
// counts all pairs in arr that sum up to target | |
function twoSumCountMap(arr, target){ | |
let count = 0; | |
let map = new Map(); | |
for(const num of arr){ | |
if(map.has(target - num)){ | |
count += map.get(target - num); | |
} | |
if(!map.has(num)){ | |
map.set(num, 0) |
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
// counts all pairs in arr that sum up to target | |
function twoSumCount(arr, target){ | |
let count = 0; | |
let map = {}; | |
for(const num of arr){ | |
if((target - num) in map){ | |
count += map[target - num]; | |
} | |
if(!(num in map)){ | |
map[num] = 0; |
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
function StringBuilder(){ | |
this.strings = []; | |
this.add = (s) => { | |
this.strings.push(s) | |
} | |
this.concat = () => { | |
return this.strings.join(""); | |
} |