Skip to content

Instantly share code, notes, and snippets.

View twitu's full-sized avatar

Ishan Bhanuka twitu

View GitHub Profile
@twitu
twitu / tickety_tackety.py
Created October 4, 2023 10:50
Ticcy Taccy Toey
import random
class Board:
def __init__(self) -> None:
self.turn = random.choice(['x', 'o'])
self.len = 3
self.state = ['_' for _ in range(self.len * self.len)]
self.patterns = self.check_patterns()
def __str__(self):
@twitu
twitu / crackle_pop.py
Last active September 17, 2023 15:30
Pop those crackles
# Crackle pop game for numbers
# Print Crackle for multiple of 3
# Print Pop for multiple of 5
# Print CracklePop if multiple of both
# Print the number if not multiple of either
def cracklepop(n):
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
print("CracklePop")
elif i % 3 == 0:
@twitu
twitu / distributed-protocol-combinators.md
Last active March 30, 2021 03:48
Summary of distributed protocol combinators

This paper demonstrates a framework for distributed protocols. The framework makes it possible to:

  • walk through the states of system
  • verify invariants of the system
  • derive/verify implementations directly from the specifications

Point 3 separates it from other such proof assistants like TLA+ or Coq, which fall short on ensuring that the implementation follows specifications. The paper introduces a few fundamental distributed protocols which can then be combined to create more complex protocols. It uses type classes to make the implementation flexible and extensible.

@twitu
twitu / how-to-architect-a-query-compiler.md
Last active October 27, 2022 14:37
Summary of how to architect a query compiler

This paper describes the various techniques that are used to create a query compiler that converts high-level (declarative) logic into low-level optimized (imperative) logic. The paper argues that conventional methods for compiling queries i.e. template expanders have the following weaknesses -

  • Everything is compiled in a single big stage which makes the logic complex and difficult to modify/expand
  • Combinations cause an explosion of possible cases because each combination has to be checked with all others making it O(n^2)

The paper argues that having multiple stages that gradually lower the query through multiple DSLs each performing a specific type of transformation is a scalable and effective approach. The paper defines the two types of transformations.

  • Optimizations - when the transformation occurs at the same level i.e. the construct in a DSL is expressed differently but within the same DSL.
@twitu
twitu / minizinc.docker
Created July 14, 2020 06:13
Running MiniZincIDE AppImage in a Docker container
FROM ubuntu:16.04
RUN apt-get -y upgrade
RUN apt-get -y update
RUN apt-get install -y libglib2.0-dev libx11-dev libglu1-mesa-dev libfontconfig1 libasound2 libegl1-mesa dbus x11-xserver-utils wget dbus
RUN dbus-uuidgen > /var/lib/dbus/machine-id
RUN wget -c https://github.com/MiniZinc/MiniZincIDE/releases/download/2.4.3/MiniZincIDE-2.4.3-x86_64.AppImage -O minizinc.AppImage
RUN chmod +x minizinc.AppImage
RUN ./minizinc.AppImage --appimage-extract
@twitu
twitu / pad_file_name.py
Created March 18, 2020 18:24
Pad numeral part in file name to correctly order files
#!/usr/bin/python3
import os
import re
import sys
import argparse
def match_files(regex):
return [name for name in os.listdir() if regex.match(name)]
@twitu
twitu / Parser.hs
Last active March 18, 2020 14:37
Functional Parsers implementation
-- Parser.hs
module Parser
( token
)
where
import Prelude hiding ( (<*>)
, fail
, (*>)
, (<*)