Skip to content

Instantly share code, notes, and snippets.

View Hypro999's full-sized avatar

Hemanth V. Alluri Hypro999

View GitHub Profile
@Hypro999
Hypro999 / server_bsd.c
Created November 23, 2023 05:12
Socket programming using just BSD style sockets vs Core Framework. Written mostly using ChatGPT (with some tweaking).
/* compile with: gcc -o server_bsd server_bsd.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#define PORT 8000
package main
import (
"fmt"
"os"
)
// Fetcher implementations must be concurrency-safe
type Fetcher interface {
// Fetch returns the body of URL and a slice of URLs found on that page.
@Hypro999
Hypro999 / stack.go
Last active August 26, 2023 05:22
A quick and dirty implementation of generic Stacks in Golang.
package containers
import (
"fmt"
)
type Stack[T any] []T
func (s *Stack[T]) Push(val T) {
*s = append(*s, val)
@Hypro999
Hypro999 / raceDemo.go
Created April 13, 2023 21:40
Small and simple example demonstrating a race condition. Intended to introduce newcomers to the world of concurrency problems.
package main
import (
"fmt"
"sync"
)
func demoRace() {
race := func() int {
i := -1
@Hypro999
Hypro999 / generics.go
Last active April 11, 2022 09:23
Demonstration of the power of combining generics (introduced in go 1.18) with anonymous functions.
package main
import "fmt"
type Point struct {
x int
y int
}
func (p Point) String() string {
@Hypro999
Hypro999 / container_of.c
Last active March 30, 2022 18:24
Adapted snippet from the Linux source code demonstrating the use of GCC statement expressions to implement intrusive linked lists in C.
#include <stdio.h>
#include <stdlib.h>
#define container_of(type, ptr, member) \
({ \
size_t offset = (size_t)&(((type *)0)->member); \
char *start_addr = (char *)(ptr) - offset; \
(type *)start_addr; \
})
@Hypro999
Hypro999 / click.c
Last active February 7, 2024 06:38
Autoclicker for Minecraft Java edition mob farms (Windows).
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>
#pragma comment(lib, "user32.lib")
// How long to wait between clicks (in ms).
#define TIME_PERIOD 30000
@Hypro999
Hypro999 / middleware_demo.go
Created June 24, 2021 16:37
A simple demonstration of how to write middleware for HTTP handlers in Go.
package main
import (
"log"
"net/http"
)
var (
GREETING = []byte("Hello there!")
)
@Hypro999
Hypro999 / pthreads_cond_demo.c
Last active May 18, 2021 10:11
A demonstration of pthread conditional variables.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#define check(x) fatal(x, __LINE__)
int var = 0;
pthread_t thread;
@Hypro999
Hypro999 / rfc3339.py
Last active March 15, 2021 06:07
A simple library/class for handling conversion between python datetime objects and strings following RFC 3339.
import re
from datetime import datetime, timedelta, timezone
class RFC3339:
class patterns:
# date-fullyear = 4DIGIT
date_fullyear: str = r"[0-9]{4}"
# date-month = 2DIGIT ; 01-12
date_month: str = r"0[0-9]|1[0-2]"