Skip to content

Instantly share code, notes, and snippets.

@nsreeen
nsreeen / shell.py
Created August 12, 2022 21:49
A tiny toy shell
import os
# deafult file descriptor values of standard in and standard out
STDIN_FD_DEFAULT = 0
STDOUT_FD_DEFAULT = 1
def execute_pipe(pipe_1_tokens, pipe_2_tokens):
pipe_read, pipe_write = os.pipe()
import Data.Char
-- what a palindrome is
isPalindrome :: String -> Maybe Bool
isPalindrome string =
isOwnReverseMaybe (rejectEmpty (normalise string))
normalise :: String -> String
normalise string =
import Data.Char
spell :: Integer -> String
spell int =
case int of
1 -> "one"
_ -> "I don't know this number!"
idk :: (Num a, Ord a) => a -> a
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 CONSTANT SIZE
VARIABLE ARR SIZE CELLS ALLOT
: INDEX ( index# -- addr )
CELLS
ARR
+
;
"""
Each node is an instance of node class. It has data, and the nodes before and after.
"""
class Node(object):
def __init__(self, data, prev, next):
self.data = data
self.prev = prev
self.next = next
if prev: prev.update_next(self) #in if statement to account for start
def update_next(self, next):
a_list = [5, 1, 3, 8, 7, 1, 30, 6, -4, 20, 9]
b_list = [5, 1, 3, 8, 7, 1, 30, 6, -4, 20, 9]
#options 0 for swap, options 1 for shift
def insertion_sort(the_list, options=0):
x = None #x is to store the item currently being sorted
i = 1 #index of currently being sorted, start at second to left most item
while i < len(the_list): # move right along the list
j = i - 1 #store position to move to as j
@nsreeen
nsreeen / board.py
Created January 26, 2017 03:22
Tic Tac Toe game
class Square(object):
def __init__(self):
self.empty = True
self.player = ''
class Board(object):
winning_combinations = [[0, 1, 2], [3, 4, 5], [6, 7, 8],
[0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6]]