Skip to content

Instantly share code, notes, and snippets.

View cacharle's full-sized avatar

Charles Cabergs cacharle

View GitHub Profile
@cacharle
cacharle / function_ptr_return_function_ptr.c
Created February 22, 2025 13:03
function_ptr_return_function_ptr
#include <stdio.h>
int a(int x,int y){
return 1;
}
double b(int x, int y){
return 1.5;
}
@cacharle
cacharle / assembly.txt
Created December 31, 2024 17:37
string literal vs string array investigation
a.out: file format elf64-x86-64
Disassembly of section .init:
0000000000001000 <_init>:
1000: f3 0f 1e fa endbr64
1004: 48 83 ec 08 sub rsp,0x8
1008: 48 8b 05 c1 2f 00 00 mov rax,QWORD PTR [rip+0x2fc1] # 3fd0 <__gmon_start__@Base>
@cacharle
cacharle / is_prime.c
Last active November 4, 2024 16:21
Primality test benchmark
#define _POSIX_C_SOURCE 199309L
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
bool is_prime(int n)
{
if (n < 2)
return false;
@cacharle
cacharle / main.c
Created October 26, 2024 07:54
Levenshtein distance benchmark
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>
int min(int a, int b, int c)
{
if (a < b && a < c)
@cacharle
cacharle / split.c
Created December 22, 2023 18:04
Split function in C
static size_t count_segment(char const *s, char c)
{
size_t counter = 0;
int i = 0;
while (s[i])
{
if (s[i] == c)
{
i++;
continue;
@cacharle
cacharle / cgit_nginx_conf
Created September 6, 2023 19:53
cgit configuration files
server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/cgit;
try_files $uri @cgit;
location ~ /.+/(info/refs|git-upload-pack) {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
#!/usr/bin/awk -f
# Markov chain exercice from chapter 3 (design) of the book The practice of programming.
BEGIN {
PREFIX_LEN = 2
# need space to detect is the end since other words can't have spaces in them
SUFFIX_END = "< END >"
# maximum number of words in the output
MAX_WORDS = 1000
@cacharle
cacharle / scrape_avatar_comics.py
Created August 15, 2020 09:42
Scrape some website for the avatar comics
#!/usr/bin/python3
import os
import sys
import itertools
import requests
from bs4 import BeautifulSoup
url_fmt = "https://www.omgbeaupeep.com/comics/Avatar_The_Last_Airbender/{:03}/{}/"
dir_name = "avatar_comics"
@cacharle
cacharle / change_remote_ssh.sh
Created July 23, 2020 17:58
Change github.com remote to use ssh
#!/bin/sh
[ $# -eq 0 ] && echo "Usage $0 REPOSITORY ..." && exit 1
for repo in $@; do
if [ ! -d $repo ] || [ ! -d $repo/.git ]; then
echo "$repo: Is not a repository"
continue
fi
@cacharle
cacharle / create_repository.sh
Created July 23, 2020 17:57
Create a repository on my server
#/bin/sh
[ $# -eq 0 ] && echo "Usage: $0 name" && exit 1
repo="/var/www/git/$1.git"
ssh [email protected] <<EOF
mkdir $repo &&
cd $repo &&
git init --bare