Skip to content

Instantly share code, notes, and snippets.

View Ramko9999's full-sized avatar
🎯
Focusing

Ramko9999

🎯
Focusing
View GitHub Profile
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 = {
// 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)
// 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;
function StringBuilder(){
this.strings = [];
this.add = (s) => {
this.strings.push(s)
}
this.concat = () => {
return this.strings.join("");
}