Skip to content

Instantly share code, notes, and snippets.

@mattyhall
mattyhall / counter.rs
Created July 13, 2018 16:32
A Rust version of Python's counter
use std::cmp::Eq;
use std::collections::HashMap;
use std::hash::Hash;
#[derive(Debug)]
struct Counter<V>
where
V: Eq + Hash,
{
map: HashMap<V, i32>,
import Image
# I apologise to the Python Gods. I was in a rush. This should all be one string and therefore one line!
data = '000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000001000000000000000000000000000111 000000000000000000000000000000000000000000000000000000000 000000000000111100000000000000000000001101000000000000000 000000000000000000000000000000000000000000000000000000001 001100000000000000000011001000000000000000000000000000000 000000000000000000000000000000000000000000010001000000111 100000110000100000000000000
struct TestData {
x: int
}
impl TestData {
pub fn addition(&mut self) {
self.x += 10;
}
}
@mattyhall
mattyhall / NeuralNetwork.hs
Created October 23, 2013 19:40
Neural Networks in Haskell with Control.Lens
{-# LANGUAGE TemplateHaskell, Rank2Types #-}
module NeuralNetwork where
import Control.Lens
import Control.Monad (mapM_)
import Control.Monad.State
import qualified Data.Vector as V
import Data.Vector.Lens
type NetworkState a = State Network a
@mattyhall
mattyhall / NBT.hs
Created October 3, 2013 17:32
An NBT parser written in Haskell
module Minecraft.NBT (findTag, indexTag, mapTag, parseNBT, Tag(..)) where
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as BL
import qualified Codec.Compression.Zlib as ZL
import qualified Codec.Compression.GZip as GZ
import qualified Data.Map as M
import Data.Attoparsec.Lazy as AP
import Data.Attoparsec.Binary
import Data.Word