Skip to content

Instantly share code, notes, and snippets.

View jsphbtst's full-sized avatar
💭
DND, doing thesis.

Joseph J. Bautista jsphbtst

💭
DND, doing thesis.
View GitHub Profile
@jsphbtst
jsphbtst / main.go
Last active April 21, 2024 21:52
Go 1.22 HTTP
package main
import (
"fmt"
"net/http"
)
func main() {
mux := http.NewServeMux()
@jsphbtst
jsphbtst / server.c
Last active January 22, 2024 09:53
HTTP Server MVP in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
const char *HTTP_200_OK = "HTTP/1.1 200 OK";
const char *HTTP_404_NOT_FOUND = "HTTP/1.1 404 Not Found";
@jsphbtst
jsphbtst / fetch-event-source.ts
Last active January 17, 2024 04:48
Client Fetch-Based SSE Listener
class FetchEventSource {
private url: string
private headers: HeadersInit
private controller: AbortController
private reader?: ReadableStreamDefaultReader<Uint8Array>
constructor(url: string, headers: HeadersInit) {
this.url = url
this.headers = headers
this.controller = new AbortController()
@jsphbtst
jsphbtst / fan-out-in.go
Created July 31, 2023 13:27
Fan-Out/In Go Concurrency Pattern
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"sync"
"time"
@jsphbtst
jsphbtst / go-style-error-handling.ts
Last active November 29, 2023 08:52
Go-style Error Handling Using TypeScript Discriminated Unions
type ErrorObject = {
statusCode: number
message: string
}
const standardErrorObj: ErrorObject = {
statusCode: 401,
message: 'lol'
}
@jsphbtst
jsphbtst / main.rs
Created March 19, 2023 14:44
Linked List in Rust
enum List {
Empty,
Node(Box<Node>),
}
struct Node {
elem: i32,
next: List,
}
@jsphbtst
jsphbtst / avl-tree.c
Last active March 5, 2023 16:56
AVL Tree in C
#include <stdio.h>
#include <stdlib.h>
typedef struct TNode {
int value;
int height;
struct TNode *left;
struct TNode *right;
} TNode;
@jsphbtst
jsphbtst / longest-palindromic-substring.c
Created March 5, 2023 15:07
Longest Palindromic Substring in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* longest_palindromic_substring(char *string);
int main() {
char *inputs[] = {
"xyzzyx",
"abaxyzzyxf",
@jsphbtst
jsphbtst / avl-tree.ts
Last active March 5, 2023 15:30
AVL Tree in TypeScript
class TNode<T> {
height: number = 0
value: T
left?: TNode<T>
right?: TNode<T>
constructor(value: T) {
this.value = value
}
@jsphbtst
jsphbtst / main.rs
Created February 12, 2023 16:18
Binary Search in Rust
fn binary_search(array: &[i32], target: i32) -> i32 {
let mut left = 0;
let mut right = array.len();
while left < right {
let midpoint = left + (right - left) / 2;
let current_number = array[midpoint];
if current_number < target {
left = midpoint + 1;
} else if current_number > target {