Skip to content

Instantly share code, notes, and snippets.

View PurpleMyst's full-sized avatar

Nicolò Francesco Maria Spingola PurpleMyst

  • Italy
  • 14:44 (UTC +02:00)
View GitHub Profile
@PurpleMyst
PurpleMyst / intermediate.c
Created February 21, 2018 17:22
Solution to DailyProgrammer Day 351 [Intermediate]
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ever (;;)
typedef struct {
size_t size;
char *names;
@PurpleMyst
PurpleMyst / intermediate.c
Created February 21, 2018 17:22
Solution to DailyProgrammer Day 351 Intermediate. Run with the last input for a cool message!
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ever (;;)
typedef struct {
size_t size;
char *names;
@PurpleMyst
PurpleMyst / Makefile
Created February 23, 2018 17:56
My C Makefile template. (I place headers in the src/ directory)
CC := clang
CFLAGS := -std=c11 -Ofast -Wall -Wextra -Wshadow
SRCDIR := src
OBJDIR := obj
SRC := $(wildcard $(SRCDIR)/*.c)
OBJ := $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
EXEC := foo
@PurpleMyst
PurpleMyst / slow.py
Created February 24, 2018 21:25
Solution to Project Euler #31 in Python and Rust. The Python solution was written while just trying to get something to work and it's very, *very*, slow. The Rust solution was made with a bit more care and some insights from the post-solution forum for the problem. You can guess which code I like best.
#!/usr/bin/env python3
COINS = (200, 100, 50, 20, 10, 5, 2, 1)
COIN_INDEXES = {coin: index for index, coin in enumerate(COINS)}
class CoinsUsed:
def __init__(self, poopyjones=None):
self.poopyjones = poopyjones or ([0] * len(COINS))
@PurpleMyst
PurpleMyst / shit_palindrome.py
Created March 2, 2018 16:01
Creates a RegExp that matches static-length palindromes. Solves Regex Golf badly.
#!/usr/bin/env python3
import math
def build_regex(max_size=13):
parts = []
for half_size in range(1, math.ceil(max_size / 2) + 1):
parts.append("^")
parts.append("(.)" * half_size)
@PurpleMyst
PurpleMyst / linkedlist.c
Created March 4, 2018 21:11
A Linked List written in C.
#include <stdio.h>
#include <stdlib.h>
typedef void (*printer_func)(void*);
struct LinkedList {
void *value;
struct LinkedList *next;
};
@PurpleMyst
PurpleMyst / hashtable.c
Created March 5, 2018 15:15
An HashTable implementation written in C.
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char* Key;
typedef char* Value;
typedef struct BucketValue {
/** The key that matches this entry. */
@PurpleMyst
PurpleMyst / bleso.py
Created March 7, 2018 22:40
An experiment in shitty LISP interpreters.
#!/usr/bin/env python3
from operator import sub, mul, floordiv
from functools import reduce
SHORT_LIST_THRESHOLD = 3
def add_repr(cls):
import inspect
argspec = inspect.getargspec(cls.__init__)
@PurpleMyst
PurpleMyst / bleso.py
Created March 7, 2018 22:40
An experiment in shitty LISP interpreters.
#!/usr/bin/env python3
from operator import sub, mul, floordiv
from functools import reduce
SHORT_LIST_THRESHOLD = 3
def add_repr(cls):
import inspect
argspec = inspect.getargspec(cls.__init__)
@PurpleMyst
PurpleMyst / compiler_12.py
Last active March 9, 2018 17:24
Solve AoC 2016 Day 12.1, 12.2, 25.1 using LLVM
#!/usr/bin/env python3
from llvmlite import ir, binding as llvm
def compile_assembunny(instructions):
instructions = tuple(instructions)
program_size = len(instructions)
char = ir.IntType(8)
int32 = ir.IntType(32)