Skip to content

Instantly share code, notes, and snippets.

View xdevelnet's full-sized avatar
🤔
THONKING. It's like "thinking" but thonking.

xdevelnet

🤔
THONKING. It's like "thinking" but thonking.
View GitHub Profile
@ForeverZer0
ForeverZer0 / url_match.c
Created February 8, 2021 19:34
Validate URL in C (POSIX)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
printf("Enter the website URL:\n");
fgets(str, 100, stdin);
if (!strcmp(str, "\n")) {
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active November 8, 2024 20:02
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@zekefast
zekefast / move_postgres_data_to_ram.bash
Last active September 26, 2023 14:37
Move Postgres data_directory to RAM to improve IO speed and test performance. Run as root/sudo.
#!/bin/bash
# It is probably redundant if you set settings mentioned in https://gist.github.com/zekefast/42273658939724ba7c7a .
# But anyway it will not hurt anybody (sure if you are not putting your production database to RAM :)).
#
# Look for more detailed description in follow articles:
# - http://blog.vergiss-blackjack.de/2011/02/run-postgresql-in-a-ram-disk/
#
# ATTENTION:
# DO NOT apply this approach if you store important data in postgresql cluster, because that could cause
@dermesser
dermesser / libfcgi-example.c
Created July 3, 2014 11:14
In case anyone wants to see a multi-threaded FastCGI application written with the fcgiapp library.
# include <stdlib.h>
# include <stdio.h>
# include <sys/stat.h>
# include <pthread.h>
# include <fcgiapp.h>
const char* const sockpath = "/tmp/fcgicpp.sock";