diff --git a/astro.config.mjs b/astro.config.mjs index 72e4803..759ccbe 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -2,10 +2,11 @@ import { defineConfig } from "astro/config"; import react from "@astrojs/react"; import tailwind from "@astrojs/tailwind"; import vercel from "@astrojs/vercel/serverless"; +import mdx from "@astrojs/mdx"; // https://astro.build/config export default defineConfig({ - integrations: [react(), tailwind()], + integrations: [react(), tailwind(), mdx()], output: "hybrid", adapter: vercel({ webAnalytics: { diff --git a/bun.lockb b/bun.lockb index 1e23e2d..ae6969c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/learning/datastructures/LinkedList.ts b/learning/datastructures/LinkedList.ts index 30fbcfd..580ab06 100644 --- a/learning/datastructures/LinkedList.ts +++ b/learning/datastructures/LinkedList.ts @@ -1,76 +1,95 @@ -type NodeVal = number; -class ListNode { - val: NodeVal; - next: ListNode | null; - constructor(value: NodeVal) { - this.val = value; +class MyNode { + val: number; + next: MyNode | null; + constructor(val: number) { + this.val = val; this.next = null; } } + class MyLinkedList { - list: ListNode | null; + head: MyNode | null; + length: number; constructor() { - this.list = null; - } - valueOf() { - return this.list; + this.head = null; + this.length = 0; } get(index: number): number { - let position = 0; - let currentNode = this.list; - while (position !== index && currentNode !== null) { - currentNode = currentNode.next; - position++; + if (index < 0 || index >= this.length) { + return -1; } - if (position === index && currentNode !== null) { - return currentNode.val; + + let current = this.head; + for (let i = 0; i < index; i++) { + current = current!.next; } - return -1; + + return current!.val; } addAtHead(val: number): void { - let next = this.list; - const newNode = new ListNode(val); - if (next !== null) { - newNode.next = next; - } - this.list = newNode; + const newNode = new MyNode(val); + newNode.next = this.head; + this.head = newNode; + this.length++; } addAtTail(val: number): void { - if (this.list == null) { + const newNode = new MyNode(val); + + if (!this.head) { + this.head = newNode; + } else { + let current = this.head; + while (current.next) { + current = current.next; + } + current.next = newNode; + } + + this.length++; + } + + addAtIndex(index: number, val: number): void { + if (index < 0 || index > this.length) { return; } - let currentNode = this.list; - while (currentNode.next) { - currentNode = currentNode.next; + if (index === 0) { + this.addAtHead(val); + } else if (index === this.length) { + this.addAtTail(val); + } else { + let current = this.head; + for (let i = 0; i < index - 1; i++) { + current = current!.next; + } + + const newNode = new MyNode(val); + newNode.next = current!.next; + current!.next = newNode; + + this.length++; } - currentNode.next = new ListNode(val); } - addAtIndex(index: number, val: number): void {} + deleteAtIndex(index: number): void { + if (index < 0 || index >= this.length) { + return; + } - deleteAtIndex(index: number): void {} -} + if (index === 0) { + this.head = this.head!.next; + } else { + let current = this.head; + for (let i = 0; i < index - 1; i++) { + current = current!.next; + } -/** - * Your MyLinkedList object will be instantiated and called as such: - * var obj = new MyLinkedList() - * var param_1 = obj.get(index) - * obj.addAtHead(val) - * obj.addAtTail(val) - * obj.addAtIndex(index,val) - * obj.deleteAtIndex(index) - */ - -const list = new MyLinkedList(); - -list.addAtHead(2); -list.addAtTail(5); -list.addAtHead(1); -list.addAtTail(7); -list.addAtTail(9); - -console.log(list.get(3)); + current!.next = current!.next!.next; + } + + this.length--; + } +} diff --git a/learning/multithreaded-javascript/ch1-c-threads/happycoin b/learning/multithreaded-javascript/ch1-c-threads/happycoin new file mode 100755 index 0000000..44dbc4c Binary files /dev/null and b/learning/multithreaded-javascript/ch1-c-threads/happycoin differ diff --git a/learning/multithreaded-javascript/ch1-c-threads/happycoin-threads b/learning/multithreaded-javascript/ch1-c-threads/happycoin-threads new file mode 100755 index 0000000..2c7f235 Binary files /dev/null and b/learning/multithreaded-javascript/ch1-c-threads/happycoin-threads differ diff --git a/learning/multithreaded-javascript/ch1-c-threads/happycoin-threads.c b/learning/multithreaded-javascript/ch1-c-threads/happycoin-threads.c new file mode 100644 index 0000000..7b01bf7 --- /dev/null +++ b/learning/multithreaded-javascript/ch1-c-threads/happycoin-threads.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include + +struct happy_result { + size_t count; + uint64_t * nums; +}; + +uint64_t random64(uint32_t * seed) { + uint64_t result; + uint8_t * result8 = (uint8_t *)&result; + for (size_t i = 0; i< sizeof(result); i++) { + result8[i] = rand_r(seed); + } + return result; +} + +uint64_t sum_digits_squared(uint64_t num) { + uint64_t total = 0; + while (num > 0) { + uint64_t num_mod_base = num % 10; + total += num_mod_base * num_mod_base; + num = num / 10; + } + return total; +} + +bool is_happy(uint64_t num) { + while (num != 1 && num != 4) { + num = sum_digits_squared(num); + } + return num == 1; +} + +bool is_happycoin(uint64_t num) { + return is_happy(num) && num % 10000 == 0; +} + +void * get_happycoins(void * arg) { + int attempts = *(int *)arg; + int limit = attempts/10000; + uint32_t seed = time(NULL); + uint64_t * nums = malloc(limit * sizeof(uint64_t)); + struct happy_result * result = malloc(sizeof(struct happy_result)); + result->nums = nums; + result->count = 0; + for(int i = 1; i < attempts; i++) { + if (result->count == limit) { + break; + } + uint64_t random_num = random64(&seed); + if (is_happycoin(random_num)) { + result->nums[result->count++] = random_num; + } + } + return (void *)result; +} + +#define THREAD_COUNT 4 + +int main() { + pthread_t thread [THREAD_COUNT]; + + int attempts = 10000000/THREAD_COUNT; + int count = 0; + for(int i = 0; i < THREAD_COUNT; i++) { + pthread_create(&thread[i], NULL, get_happycoins, &attempts); + } + + for(int j = 0; j < THREAD_COUNT; j++) { + struct happy_result * result; + pthread_join(thread[j], (void **)&result); + count += result->count; + for(int k = 0; k < result->count; k++) { + printf("%" PRIu64 " ", result->nums[k]); + } + free(result->nums); + free(result); + } + printf("\ncount %d\n", count); + return 0; +} \ No newline at end of file diff --git a/learning/multithreaded-javascript/ch1-c-threads/happycoin.c b/learning/multithreaded-javascript/ch1-c-threads/happycoin.c index 662a28a..7d89dd3 100644 --- a/learning/multithreaded-javascript/ch1-c-threads/happycoin.c +++ b/learning/multithreaded-javascript/ch1-c-threads/happycoin.c @@ -11,4 +11,39 @@ uint64_t random64(uint32_t * seed) { result8[i] = rand_r(seed); } return result; +} + +uint64_t sum_digits_squared(uint64_t num) { + uint64_t total = 0; + while (num > 0) { + uint64_t num_mod_base = num % 10; + total += num_mod_base * num_mod_base; + num = num / 10; + } + return total; +} + +bool is_happy(uint64_t num) { + while (num != 1 && num != 4) { + num = sum_digits_squared(num); + } + return num == 1; +} + +bool is_happycoin(uint64_t num) { + return is_happy(num) && num % 10000 == 0; +} + +int main() { + uint32_t seed = time(NULL); + int count = 0; + for (int i = 1; i < 10000000; i++) { + uint64_t random_num = random64(&seed); + if (is_happycoin(random_num)) { + printf("%" PRIu64 " ", random_num); + count++; + } + } + printf("\ncount %d\n", count); + return 0; } \ No newline at end of file diff --git a/learning/multithreaded-javascript/ch1-c-threads/src/env.d.ts b/learning/multithreaded-javascript/ch1-c-threads/src/env.d.ts deleted file mode 100644 index 8c34fb4..0000000 --- a/learning/multithreaded-javascript/ch1-c-threads/src/env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// \ No newline at end of file diff --git a/learning/multithreaded-javascript/ch2-shared-workers/blue.html b/learning/multithreaded-javascript/ch2-shared-workers/blue.html new file mode 100644 index 0000000..a110ce1 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-shared-workers/blue.html @@ -0,0 +1,6 @@ + + + Shared Workers Blue + + + diff --git a/learning/multithreaded-javascript/ch2-shared-workers/blue.js b/learning/multithreaded-javascript/ch2-shared-workers/blue.js new file mode 100644 index 0000000..36b012f --- /dev/null +++ b/learning/multithreaded-javascript/ch2-shared-workers/blue.js @@ -0,0 +1,7 @@ +console.log("blue.js"); + +const worker = new SharedWorker("shared-worker.js"); + +worker.port.onmessage = (event) => { + console.log("EVENT", event.data); +}; diff --git a/learning/multithreaded-javascript/ch2-shared-workers/red.html b/learning/multithreaded-javascript/ch2-shared-workers/red.html new file mode 100644 index 0000000..cd11934 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-shared-workers/red.html @@ -0,0 +1,6 @@ + + + Shared Workers Red + + + diff --git a/learning/multithreaded-javascript/ch2-shared-workers/red.js b/learning/multithreaded-javascript/ch2-shared-workers/red.js new file mode 100644 index 0000000..4bb5f92 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-shared-workers/red.js @@ -0,0 +1,7 @@ +console.log("red.js"); + +const worker = new SharedWorker("shared-worker.js"); + +worker.port.onmessage = (event) => { + console.log("EVENT", event.data); +}; diff --git a/learning/multithreaded-javascript/ch2-shared-workers/shared-worker.js b/learning/multithreaded-javascript/ch2-shared-workers/shared-worker.js new file mode 100644 index 0000000..4f06495 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-shared-workers/shared-worker.js @@ -0,0 +1,18 @@ +const ID = Math.floor(Math.random() * 999999); +console.log("shared-worker.js", ID); + +const ports = new Set(); + +self.onconnect = (event) => { + const port = event.ports[0]; + ports.add(port); + console.log("CONN", ID, ports.size); + + port.onmessage = (event) => { + console.log("MESSAGE", ID, event.data); + + for (let p of ports) { + p.postMessage([ID, event.data]); + } + }; +}; diff --git a/learning/multithreaded-javascript/ch2-web-workers/index.html b/learning/multithreaded-javascript/ch2-web-workers/index.html new file mode 100644 index 0000000..291d464 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-web-workers/index.html @@ -0,0 +1,6 @@ + + + Web Workers Hello World + + + diff --git a/learning/multithreaded-javascript/ch2-web-workers/main.js b/learning/multithreaded-javascript/ch2-web-workers/main.js new file mode 100644 index 0000000..52b30f5 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-web-workers/main.js @@ -0,0 +1,10 @@ +console.log("hello from main.js"); + +const worker = new Worker("worker.js"); +worker.onmessage = (msg) => { + console.log("message received from worker:", msg.data); +}; + +worker.postMessage("message sent to worker"); + +console.log("hello from end of main.js"); diff --git a/learning/multithreaded-javascript/ch2-web-workers/worker.js b/learning/multithreaded-javascript/ch2-web-workers/worker.js new file mode 100644 index 0000000..8d50f69 --- /dev/null +++ b/learning/multithreaded-javascript/ch2-web-workers/worker.js @@ -0,0 +1,6 @@ +console.log("hello from worker.js"); + +self.onmessage = (msg) => { + console.log("message from main:", msg.data); + postMessage("message sent from worker"); +}; diff --git a/package.json b/package.json index 877f2b7..a9bf493 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@astrojs/check": "^0.3.4", + "@astrojs/mdx": "^2.1.0", "@astrojs/react": "^3.0.9", "@astrojs/tailwind": "^5.1.0", "@astrojs/vercel": "^7.0.1", diff --git a/src/components/Header.astro b/src/components/Header.astro new file mode 100644 index 0000000..117a6d0 --- /dev/null +++ b/src/components/Header.astro @@ -0,0 +1,39 @@ +--- +import { Image } from 'astro:assets'; +import myPicture from '../../public/images/me.png' +import Link from './Link.astro'; +--- + + + + \ No newline at end of file diff --git a/src/components/Page.astro b/src/components/Page.astro index 7d01a73..bd27caa 100644 --- a/src/components/Page.astro +++ b/src/components/Page.astro @@ -3,7 +3,7 @@ import Link from "./Link.astro"; ---
-
+
diff --git a/src/layouts/BlogLayout.astro b/src/layouts/BlogLayout.astro new file mode 100644 index 0000000..ed19227 --- /dev/null +++ b/src/layouts/BlogLayout.astro @@ -0,0 +1,27 @@ +--- +import Layout from "./Layout.astro"; + +const { frontmatter: {title, date} } = Astro.props; + +// Assuming you have a Date object +const currentDate = new Date(date); + +// Format the date using toLocaleDateString +const formattedDate = currentDate.toLocaleDateString("en-US", { + year: "numeric", + month: "long", + day: "numeric", + timeZone: "UTC" +}); +--- + + +
+

{title}

+

📝 Published on

+
+ +
+ +
+
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 2989f88..8573b79 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,9 +1,6 @@ --- -import Link from "../components/Link.astro"; import Page from "../components/Page.astro"; -import { Image } from 'astro:assets'; -import myPicture from '../../public/images/me.png' - +import Header from "../components/Header.astro"; interface Props { title: string; } @@ -19,25 +16,10 @@ const { title } = Astro.props; - Dillon Curry - {title} + {title} - dilloncurry.com - +
@@ -79,18 +61,4 @@ const { title } = Astro.props; Courier New, monospace; } - nav { - text-align: right; - margin: 0 auto; - padding: 0 24px; - max-width: 65ch; - display: flex; - justify-content: space-between; - height: 72px; - } - - nav li { - display: inline-block; - padding-left: 4px; - } diff --git a/src/pages/blog.astro b/src/pages/blog.astro index 48b6b4d..2518432 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -1,9 +1,12 @@ --- import Layout from "../layouts/Layout.astro"; +import Link from "../components/Link.astro" ---
-

Maybe I'll write something here soon

+
    +
  • What I'm Currently Learning
  • +
\ No newline at end of file diff --git a/src/pages/blog/what-im-learning.mdx b/src/pages/blog/what-im-learning.mdx new file mode 100644 index 0000000..01834f0 --- /dev/null +++ b/src/pages/blog/what-im-learning.mdx @@ -0,0 +1,14 @@ +--- +layout: ../../layouts/BlogLayout.astro +date: 2024-01-28 +title: What I'm Currently Learning +description: A look at where I'm spending my time to learn new things to help in my career +--- + +This is a look at where I'm spending my time to learn new things to help me +advance my career to a place that is fulfilling. + +- Working on this site, dilloncurry.com +- [Google Tech Dev Guide](https://techdevguide.withgoogle.com/), to improve my knowledge around data structure and algorithms +- [web.dev/learn](https://web.dev/learn), to strengthen my knowledge in the web domain +- 📕 ["Multihreaded JavaScript: Concurrency Beyond the Event Loop"](https://www.oreilly.com/library/view/multithreaded-javascript/9781098104429/), to better my understanding of JavaScript