Skip to content

Instantly share code, notes, and snippets.

View ihavenonickname's full-sized avatar
🔬
Searching

Gabriel ihavenonickname

🔬
Searching
  • The Future
View GitHub Profile
type FiniteAutomaton<'a> = {
InitialState: string
FinalStates: Set<string>
Transitions: Map<string * char, 'a>
}
type DeterministicFiniteAutomaton = FiniteAutomaton<string>
type NondeterministicFiniteAutomaton = FiniteAutomaton<string List>
let private nextState symbol state fa =
fa.Transitions |> Map.tryFind (state, symbol)
class Graph(object):
def __init__(self):
self.g = {}
def add(self, vertex1, vertex2, weight):
if vertex1 not in self.g:
self.g[vertex1] = {}
if vertex2 not in self.g:
self.g[vertex2] = {}
@ihavenonickname
ihavenonickname / Program.fs
Last active October 26, 2016 20:45
fsharp matrix multiplication
let transposeColumn matrix index =
seq { for row in matrix -> Seq.item index row }
let transposeMatrix matrix =
matrix
|> Seq.mapi (fun index _ -> transposeColumn matrix index)
let multiplyRows row1 row2 =
Seq.zip row1 row2
|> Seq.map (fun (a, b) -> a * b)
@ihavenonickname
ihavenonickname / Program.fs
Last active March 15, 2017 02:12
Hello genetic algorithms
let chanceToMutate = 5
let possibleChars = Array.append [|'A'..'Z'|] [|' '|]
let random = new System.Random()
let randomChar () =
let index = random.Next(Array.length possibleChars)
Array.item index possibleChars
@ihavenonickname
ihavenonickname / something-better.peg
Last active December 9, 2017 18:55
i dont know what im doing
Expr0 = Ws expr:(Appl / Expr1) Ws {
return expr
}
Expr1 = expr:(Func / Name / Expr0Parenthesis) {
return expr
}
Expr0Parenthesis = '(' expr:Expr0 ')' {
return expr
@ihavenonickname
ihavenonickname / script.py
Last active January 23, 2018 12:16
r/learnpython 23-01-2018
def none_slice_gabriel(lst, start, stop):
i = start
while i < 0 and i < stop:
yield None
i += 1
while i < len(lst) and i < stop:
yield lst[i]
i += 1
@ihavenonickname
ihavenonickname / space-invaders.java
Created April 25, 2018 00:03
Space Invaders in Processing 3
int pixelsize = 4;
int gridsize = pixelsize * 7 + 5;
Player player;
ArrayList enemies = new ArrayList();
ArrayList bullets = new ArrayList();
int direction = 1;
boolean incy = false;
int score = 0;
PFont f;
@ihavenonickname
ihavenonickname / knn-test.py
Created July 9, 2018 13:44
To be used by reviewers
from review import KNNPoint, predict
dataset = [
KNNPoint([842.0, 2.2, 7.0, 2.0, 2549.0], "medium cost"),
KNNPoint([1021.0, 0.5, 53.0, 3.0, 2631.0], "high cost"),
KNNPoint([563.0, 0.5, 41.0, 5.0, 2603.0], "high cost"),
KNNPoint([615.0, 2.5, 10.0, 6.0, 2769.0], "high cost"),
KNNPoint([1821.0, 1.2, 44.0, 2.0, 1411.0], "medium cost"),
KNNPoint([1859.0, 0.5, 22.0, 1.0, 1067.0], "medium cost"),
KNNPoint([1821.0, 1.7, 10.0, 8.0, 3220.0], "very high cost"),
import requests
from bs4 import BeautifulSoup
import json
import unicodedata
def normalize(text):
nfkd_form = unicodedata.normalize('NFKD', text)
only_ascii = nfkd_form.encode('ASCII', 'ignore')
return only_ascii.lower().decode()
import grequests
import json
import unicodedata
from bs4 import BeautifulSoup
def download(urls):
def catcher(req, ex):
print(ex)
reqs = map(grequests.get, urls)