👨💻 I'm a Software Engineer.
This file contains 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
#!/usr/bin/env bash | |
echo -e "\n[Cloning repos...]" | |
user=$1 | |
count=0 | |
while read repo | |
do | |
echo "Cloning $repo..." |
This file contains 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
// MDN Docs | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | |
/** | |
* @param {string[]} value as array | |
* @param {any} val1 | |
* @param {any} val2 | |
*/ | |
function templateExample(string, val1, val2) { | |
console.log('string\n', string); |
This file contains 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 express = require("express"); | |
const app = express(); | |
app.use("/static", express.static("static")); | |
app.get("/", (req, res) => { | |
res.sendFile("views/index.html", { root: __dirname }); | |
}); | |
app.get("/events", async (req, res) => { |
This file contains 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 { Worker, isMainThread } = require("node:worker_threads"); | |
const worker = new Worker("./report.js", { | |
workerData: { message: "hello from app.js" }, | |
}); | |
console.log("Running worker: ", worker.threadId); | |
console.log("is main thread (app.js) => ", isMainThread); | |
worker.on("error", (err) => |
This file contains 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 { appendFile } from "node:fs/promises"; | |
const url = "https://jsonplaceholder.typicode.com/posts"; | |
let times = 5; | |
async function* getData() { | |
while (times > 0) { | |
times--; | |
const response = await fetch(url); | |
yield await response.arrayBuffer(); |
This file contains 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 { writeFile, readfile } = require("node:fs/promises"); | |
const isObject = (value) =› typeof value = "object"; | |
const isArray = (value) = Boolean (value?. Length) ; | |
const fileName = "file.json" | |
(async () = { | |
const file = await readFile(fileName, { encoding: "utf-8"}); | |
const data = JSON.parse (file); | |
let result = “”; |
This file contains 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
class List { | |
constructor(size) { | |
this.buffer = new ArrayBuffer(size); | |
this.array = new Uint8Array(this.buffer); | |
} | |
push(value) { | |
this.array[this.array.length - 1] = value; | |
} |
This file contains 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
// standard function to loop through our range | |
function range(start = 0, end = 10, increment = 1) { | |
for (let i = start; i <= end; i += increment) { | |
console.log(i) | |
} | |
} | |
range() // 0, 1, 2... | |
range(2, 6, 2) // 2, 4, 6 |
This file contains 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 { createServer } from "http"; | |
const PORT = 3000; | |
createServer((request, response) => { | |
if (request.method !== "POST" || request.url !== "/stream") { | |
response.status = 404; | |
response.end("method or url not found"); | |
return; | |
} |
NewerOlder