Skip to content

Instantly share code, notes, and snippets.

View Ramko9999's full-sized avatar
🎯
Focusing

Ramko9999

🎯
Focusing
View GitHub Profile
import (
"log"
"os"
)
/*
os.MkdirTemp takes in the path to make the temporary dir and a pattern.
os.MkdirTemp will make a new directory with a name which is the pattern + a random string.
import (
"log"
"os"
)
func makeDir(){
err := os.Mkdir("newDirectory", 0755);
if err != nil {
log.Fatal(err);
}
import (
"log"
"os
)
func removeFile(){
err := os.Remove("./removeFolder/remove.txt");
if err != nil{
log.Fatal(err);
}
import (
"log"
"os"
)
/*
append.txt initally:
An existing line
append.txt after calling appendToFile:
An existing line
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.
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 */
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.
import (
"log"
"os"
)
/*
Contents of test.txt:
Hello World!
*/
import (
"os"
)
func createFile(){
filePtr, err := os.Create("./test/creating.txt");
if err != nil {
log.Fatal(err);
}
defer filePtr.Close(); // close the file
@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 = {