Skip to content

Instantly share code, notes, and snippets.

View PurpleMyst's full-sized avatar

Nicolò Francesco Maria Spingola PurpleMyst

  • Italy
  • 08:27 (UTC +02:00)
View GitHub Profile
@PurpleMyst
PurpleMyst / json_parser.rs
Last active May 17, 2018 23:03
JSON parser in Rust + nom..
//! ```cargo
//! [dependencies.nom]
//! version = "4.0"
//! features = ["verbose-errors"]
//! ```
#[macro_use]
extern crate nom;
#[derive(Clone, Debug, PartialEq)]
@PurpleMyst
PurpleMyst / generic_dynamic_hashtable.c
Last active May 11, 2018 15:21
A very simple dynamically-resized HashTable implementation in C.
/**
* A very simple dynamically-resized HashTable implementation in C.
*/
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define GROWTH_FACTOR 3
#!/usr/bin/env run-cargo-script
// cargo-deps: quickcheck
use std::{borrow::Borrow, io::{self, BufRead}};
#[cfg(test)]
#[macro_use]
extern crate quickcheck;
fn longest_common_prefix_length(x: &str, y: &str) -> usize {
x.chars()
@PurpleMyst
PurpleMyst / hashmap_literal.rs
Created April 15, 2018 14:05
A macro for an HashMap literal written in Rust.
use std::collections::HashMap;
macro_rules! hashmap {
{$($key:expr => $value:expr),*} => {{
let mut __hm = HashMap::new();
$(
__hm.insert($key, $value);
)*
__hm
}}
@PurpleMyst
PurpleMyst / factoid_bot.rs
Created April 5, 2018 23:35
A factoid bot written in Rust.
#!/usr/bin/env run-cargo-script
//! A factoid bot written in Rust, using the irc library.
//! This bot is written to showcase the irc library, however it might also be useful.
//!
//! To utilize, create a `factoid_config.json` file in your working directory defining at least
//! nickname, server and channels.
//!
//! If you want some useful logging, you can set the `RUST_LOG` environment variable equal to
//! `factoid_bot=info`.
//!
@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)
@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 / 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 / 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;
};