This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char rotate_left(unsigned char b) | |
{ | |
unsigned char first = b & 0x80; | |
b <<= 1; | |
b |= first >> 7; | |
return b; | |
} | |
unsigned char rotate_right(unsigned char b) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PRINT_BYTE(x) (print_bits((x), 8)) | |
#define PRINT_WORD(x) (print_bits((x), 16)) | |
#define PRINT_DWORD(x) (print_bits((x), 32)) | |
#define PRINT_QWORD(x) (print_bits((x), 64)) | |
void print_bits(unsigned long long int n, int s) | |
{ | |
if (s == 0) | |
return; | |
print_bits(n >> 1, s - 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nom=didier age=43,xp=65,hp=100 | |
nom=dupond age=12,xp=34,hp=110 | |
nom=jean age=1,xp=2,hp=110 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Reverse Polish Notation parser | |
-- from: http://learnyouahaskell.com/functionally-solving-problems | |
rpn :: String -> Float | |
rpn expr = head $ foldl foldFunc [] (words expr) | |
where foldFunc acc op | |
| head op `elem` ['1'..'9'] = (read op :: Float) : acc | |
| otherwise = applyOp op (acc !! 1) (head acc) : drop 2 acc | |
applyOp op a b = case op of "+" -> a + b | |
"-" -> a - b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isPrime :: Int -> Bool | |
isPrime 2 = True | |
isPrime 3 = True | |
isPrime x | |
| x < 2 = False | |
| x `mod` 2 == 0 || x `mod` 3 == 0 = False | |
| otherwise = divCheck 5 | |
where divCheck d | |
| d * d > x = True | |
| x `mod` d == 0 || x `mod` (d + 2) == 0 = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
union Color | |
{ | |
int hexcode; | |
struct | |
{ | |
unsigned char b; | |
unsigned char g; | |
unsigned char r; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAME = name | |
CC = gcc | |
CCFLAGS = -Wall -Wextra | |
LDFLAGS = | |
HEADER = header.h | |
SRC = main.c | |
OBJ = $(SRC:.c=.o) | |
RM = rm -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "sdl_boilerplate.h" | |
int main(void) | |
{ | |
GState *gstate = graphics_init(400, 400); | |
graphics_run(gstate); | |
graphics_quit(gstate); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <SDL2/SDL.h> | |
#define WINDOW_TITLE "Title" | |
#define WINDOW_X 20 | |
#define WINDOW_Y 20 | |
static void update(GState *state); | |
static void event_handler(GState *state); | |
static void destroy_state(GState *state); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
split :: Eq a => a -> [a] -> [[a]] | |
split _ [] = [[]] | |
split delim str = | |
let (before, remainder) = span (/= delim) str | |
in before:case remainder of | |
[] -> [] | |
x -> split delim $ tail x |