Skip to content

Instantly share code, notes, and snippets.

View snahor's full-sized avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
// Array of [continent code, country code, country name]
// Source: https://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent_(data_file)
// let rows = Array.from(document.querySelectorAll('table.sortable tr'))
// let data = rows.slice(1).map(row => [row.cells[0].textContent, row.cells[1].textContent, row.cells[4].textContent])
// data
[
[
"AS",
"AF",
"Afghanistan, Islamic Republic of"
16 (0,0,0)
17 (0,0,95)
18 (0,0,135)
19 (0,0,175)
20 (0,0,215)
21 (0,0,255)
22 (0,95,0)
23 (0,95,95)
24 (0,95,135)
25 (0,95,175)
@snahor
snahor / caesar.py
Created October 16, 2017 20:06
Caesar Cipher
from functools import wraps
a_ord = ord('a')
class NonAlphaException(Exception):
pass
@snahor
snahor / forth.sml
Last active November 21, 2017 00:22
structure Parser =
struct
exception ParsingError of string
datatype cmd = Push of int
| Add
| Sub
| Mul
| Div
| Dup
@snahor
snahor / pascal.sml
Last active September 21, 2017 03:50
structure Pascal =
struct
local
fun nextrow row =
let
val (ns, _) =
foldl
(fn (x, (acc, prev)) => ((prev + x) :: acc, x))
([], 0)
row
package main
import (
"sort"
)
func partition(xs []int, left, right, pivotIndex int) int {
pivot := xs[pivotIndex]
partitionIndex := left
xs[pivotIndex], xs[right] = xs[right], xs[pivotIndex]
@snahor
snahor / hofstadter.sml
Last active September 10, 2017 09:19
Hofstadter sequences
(*
* Hofstadter sequences
* https://en.wikipedia.org/wiki/Hofstadter_sequence
*)
signature QUEUE =
sig
type 'a queue = 'a list * 'a list
val empty: 'a queue
val enqueue: 'a -> 'a queue -> 'a queue
def fib():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
import random
import curses
import sys
import time
class Board(object):
WINNING_COMBOS = (
(0, 1, 2),
(3, 4, 5),