Skip to content

Instantly share code, notes, and snippets.

View afarah1's full-sized avatar

Alef Farah afarah1

View GitHub Profile
@afarah1
afarah1 / perlin.c
Last active December 10, 2015 18:49
A simple Perlin Noise generator using OpenMP for parallelization
/*
* perlin.c - create an image of Perlin (gradient) noise
*
* Compilling:
* gcc perlin.c -std=c99 -O3 -Wall -Wextra -Werror -fopenmp -lgomp
*
* Doc:
* ./a.out --help
*
* Thanks to:
@afarah1
afarah1 / logging.h
Last active October 31, 2016 19:38
A simple logging macro and some wrappers.
/* A simple logging macro and some wrappers */
#pragma once
/*
* The following requirements are for the "DEBUG" mode, which flushes
* everything to disk after each msg and syncs. If you do not wish this
* behaviour, which will incur in significant performance loss for "DEBUG"
* mode, remove these guards and edit the LOGGING macro, removing the fflush
* and fsync calls.
@afarah1
afarah1 / mplayerp
Last active September 17, 2018 19:29
mplayerp - Use mplayer+bash as a full-featured media player
#!/bin/bash
#
# mplayerp - Use mplayer+bash as a full-featured music player
#
# Starts mplayer in slave mode listening to commands from a fifo and reading
# media from a playlist file. There are some extras to make it pleasent to use.
#
# Syntax: mplayerp [OPTIONS] [ACTION | DIR]
#
# Options:
@afarah1
afarah1 / tldr
Last active August 26, 2024 01:56
Extremely simple offline tl;dr pages client
#!/bin/sh
# Simple offline client for tldr pages
#
# Usage:
# tldr command
#
# Updating offline page cache:
# tldr --update
pf=${HOME}/.cache/tldr/pages
@afarah1
afarah1 / dry.h
Created March 31, 2016 19:46
Don't repeat yourself - Go-like parameters for C
/*
* Don't repeat yourself - Go-like parameters for C
*
* Before DRY:
*
* foo(int i, double x, double y, struct planet const *p1, struct planet const
* *p2, struct planet const *p3, int j)
*
* After DRY:
*
@afarah1
afarah1 / Makefile
Created March 31, 2016 21:22
Basic Makefile I start my projects from
CC=gcc
STD=-std=c99
WARN=-Wall -Wextra -Wpedantic -Wformat-security -Wfloat-equal -Wshadow\
-Wconversion -Winline -Wpadded
OPT=-O2 -march=native -ffinite-math-only -fno-signed-zeros
DBG=-O0 -g -ggdb
EXTRA=
LINK=
FLAGS=$(STD) $(WARN) $(OPT) $(EXTRA) $(LINK)
@afarah1
afarah1 / flag.c
Last active August 19, 2017 07:02
Draws a rectangle divided in half
/*
* ./this width height topRGB bottomRGB
* ./this 400 400 FFFF00 000000 | feh -
*/
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
@afarah1
afarah1 / glider.c
Last active August 20, 2017 05:43
Draws a glider flag
/*
* ./this width height topRGB bottomRGB [circleSizeDivFactor=4]
* ./this 800 600 FFFFFF 000000 | feh -
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PRINT(c) do { printf("%d %d %d ", c >> 16, c >> 8 & 0xFF, c & 0xFF); } while(0)
#define IN_CIRCLE(x, y) ((i - y) * (i - y) + (j - x) * (j - x) <= r*r)
@afarah1
afarah1 / puzzle.c
Last active July 23, 2021 03:00
Simple puzzle
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#define N 4
static bool
double_equal(double a, double b, double epsilon)
{