Skip to content

Instantly share code, notes, and snippets.

View Cxarli's full-sized avatar
🔓
'; DROP TABLE bugs --

Charlie Cxarli

🔓
'; DROP TABLE bugs --
View GitHub Profile
@Cxarli
Cxarli / file-indexer.c
Last active October 24, 2021 18:56
A little script to write an index of all files in the current directory
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
@Cxarli
Cxarli / colorise.py
Created June 19, 2021 16:21
Take a random image and replace all distinct colours with a random other colour
"""Take a random image and replace all distinct colours with
a random other colour
:arg infile: The source image to read from
:arg loop: Whether to loop the list of colours instead of only replacing the N first
:arg upper: The upper bound of colours to replace
"""
from PIL import Image
from collections import defaultdict
#!/usr/bin/env bash
set -eu
set -o pipefail
IFS=$'\n'
source="$HOME/i3"
output="${1:-$HOME/.config/i3/config}"
@Cxarli
Cxarli / indexer.c
Created February 2, 2019 13:00
Make a single file with the filesize, name and modification time of all files in the given directory
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
@Cxarli
Cxarli / enum.php
Created August 9, 2018 22:17
Enum implementation in PHP
<?php
abstract class Enum {
private static $cache = [];
// Helper function to load the required fields into the cache.
private static function loadCache(): void {
// Create cache for enum
self::$cache[static::class] = [];
// Get all constants
@Cxarli
Cxarli / pascal_triangle.c
Created May 31, 2018 20:27
My implementation of the pascal triangle
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
/// Get the n-th row of the pascal triangle
/// NOTE: This is a pure, recursive function without caching
/// n: the nth row to calculate
/// row: the pointer to an array with n+1 elements to store the row in
import sys
from math import sqrt
errors = 0
def is_uniq(lst):
return len(list(set(lst))) is len(lst)
0 4 0 7 0 14 24 0 0 6 0 17 10 19 5 0 0 3 0 0 20 0 23 15 0
13 20 17 10 2 0 0 0 0 0 0 15 0 0 0 6 0 5 0 23 0 0 16 19 18
0 22 0 0 0 17 0 0 25 0 0 0 9 0 11 7 0 12 0 19 3 0 24 8 10
24 12 0 3 0 18 20 0 5 0 0 4 0 0 23 14 10 11 0 22 0 0 0 0 0
0 18 0 0 0 10 22 0 15 21 0 20 3 0 6 2 0 8 0 0 0 0 7 0 12
16 0 15 8 22 0 0 0 9 0 0 0 0 6 0 0 25 0 7 0 0 10 1 17 0
7 0 0 23 11 0 16 6 19 0 4 0 5 24 13 0 12 21 0 20 0 0 0 0 0
0 0 0 0 0 0 18 0 7 0 25 0 2 12 0 0 24 0 5 0 14 11 20 4 16
0 0 20 14 19 11 10 5 0 2 0 0 0 0 0 0 15 4 8 6 0 13 0 0 0
4 0 0 0 13 0 0 0 23 0 20 22 15 11 0 0 0 0 0 0 12 7 6 25 0
@Cxarli
Cxarli / php-toggle-ext.sh
Last active January 9, 2018 22:31
Toggle a PHP extension
#!/bin/bash
###
### MAKE BACK-UPS
### I AM NOT RESPONSIBLE
### MAKE BACK-UPS
### DON'T USE REGEXES
### MAKE BACK-UPS
### D O N O T U S E R E G E X E S
@Cxarli
Cxarli / Makefile
Created December 13, 2017 23:09
Makefile with GCC and Clang, ASAN, Valgrind and some other nice things
# The path of the executable
OUTPUT_EXEC = build/main
# Use clang by default
CC = clang
# Flags for Clang
CFLAGS = -O0 -g -Weverything
# Flags for GCC