Skip to content

Instantly share code, notes, and snippets.

View nitrix's full-sized avatar

Alex Belanger nitrix

View GitHub Profile
{-# LANGUAGE FlexibleContexts, FlexibleInstances, UndecidableInstances, TypeFamilies, PolyKinds, GADTs, MultiParamTypeClasses, FunctionalDependencies, RankNTypes, DataKinds #-}
import Data.Kind
import Prelude hiding (id, (.), Functor(..), Monad(..), Monoid(..))
-- 'Category k' is a category whose objects are 'Ob k a => a' and whose
-- morphisms (of kind *) are '(Ob k a, Ob k b) => k a b'
class Category (k :: o -> o -> *) where
type Ob (k :: o -> o -> *) (a :: o) :: Constraint
id :: Ob k a => k a a
(.) :: (Ob k a, Ob k b, Ob k c) => k b c -> k a b -> k a c
@nitrix
nitrix / testgp.php
Last active May 17, 2016 03:52
Test genetic programming
<?php
$instructions = ['0', '1', '+', '-', '*', '/', '>', '<', '=', '|', '&', '@', '!', '#', '(', ')', '%', '_'];
$instructionsLength = count($instructions) - 1;
while (true) {
$program = '';
for ($i = 0, $c = rand(0, 10); $i < $c; $i++) {
$program .= $instructions[rand(0, $instructionsLength)];
}
nitrix@pluto ~/projects/ni/boot [develop]$ php vm.php test
Instruction SBNZ [$0=9, $1=0, $2=8, $3=-1]
Enter a character: f
Performing `$8 = $0 - $9`, the values are `-11 = 102 - 113`
Instruction SBNZ [$4=1, $5=1, $6=8, $7=0]
Performing `$8 = $1 - $1`, the values are `0 = 0 - 0`
Result is zero, branching to 0
Instruction SBNZ [$0=9, $1=0, $2=8, $3=-1]
Enter a character: g
Performing `$8 = $0 - $9`, the values are `-10 = 103 - 113`
@nitrix
nitrix / gist:d921de1767bf8fd933a7
Created January 4, 2016 05:15
little_bit's compiler
.global main
.global printf
.text
main:
mov %rsp, base
jmp next
core:
next:
mov ip, %rax
add $8, ip
@nitrix
nitrix / gist:267bc0c42355e6c39983
Last active November 8, 2015 11:00
HashMap attempt in Haskell
import Data.Array
import Data.Maybe
import Data.Bits
type Hash = Integer
type HashMap k v = Array Hash [(k,v)]
hmCreate :: (Eq k, Show k) => HashMap k v -> k -> v -> HashMap k v
hmCreate hm k v = hm // [(hmHash hm k, after)]
where
@nitrix
nitrix / gist:1bd49a09c4a6698dad64
Last active August 29, 2015 14:21
Interesting problem to simulate
##programming
SrPx | As a side question, if a company has an income, and it wants to compute the most it can of a problem in 10 years, is it better to buy computers as you income comes, or wait 9 years, buy faster computers and to do much more on the last year? Hmm. Not sure why I'm asking this here, that is a math question.
@nitrix
nitrix / nn.php
Last active August 29, 2015 14:17
Generic Neural Network
<?php
/******************* CONFIG *******************/
$config_nn_layout = [2, 3, 2, 1];
$config_nn_step = 7;
/******************** MAIN ********************/
$neurons = nn_init_neurons($config_nn_layout);
$weights = nn_init_weights($config_nn_layout);
while (true) {
<?php
$data ='O:8:"stdClass":3:{s:3:"aaa";a:5:{i:0;i:1;i:1;i:2;i:2;s:39:"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";i:3;i:4;i:4;i:5;}s:3:"aaa";i:1;s:3:"ccc";R:5;}';
$x = unserialize($data);
var_dump($x);
?>
P2
# feep.pgm
24 7
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
@nitrix
nitrix / cute.pgm
Created July 1, 2014 18:41
Cute PGM
P2
# CREATOR: GIMP PNM Filter Version 1.1
360 490
255
255
255
255
255
255
255