Skip to content

Instantly share code, notes, and snippets.

@gdevanla
gdevanla / parser_combinators.py
Last active Oct 27, 2021
Parser Combinator in Python - Notes
View parser_combinators.py
import operator
import typing as tp
"""
a. Structure of Parser
p = (s -> Any object)
Partially consuming parser
p1 = (s -> (a, remaining))
View haskelline_state.hs
-- Notes on how to wrap InputT over StateT to maintain the environment around a language repl.
type HaskellLineT = InputT (StateT Env IO) ()
runScriptInteractive = runStateT (runInputT defaultSettings loop) (initEnv Nothing)
where
loop :: HaskellLineT
loop = do
minput <- getInputLine "%"
when (isNothing minput) loop
View interface_vs_union_type.py
import typing as tp
class Abstract:
def func1(self, *, x: int, y: str):
raise NotImplementedError()
View Printf.hs
{-# LANGUAGE GADTs, TypeInType, DataKinds, TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
import GHC.TypeLits
import GHC.Types
import Data.Singletons
import Data.Singletons.Prelude
data Format = Lit Symbol | Str | Shown Type
View airflow_context.py
#https://bcb.github.io/airflow/execute-context
from airflow.models import TaskInstance
ti=TaskInstance(task=t, execution_date=datetime.datetime.now())
ti.get_template_context()
@gdevanla
gdevanla / install-python.sh
Created Jun 27, 2018
Install Python 3.6.5 in Ubuntu 16+
View install-python.sh
#!/bin/bash
export PYTHON_VERSION=3.6.5
export PYTHON_DOWNLOAD_URL=https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
sudo apt update
sudo apt install --no-install-recommends -y \
software-properties-common build-essential \
libssl-dev libreadline-dev libbz2-dev libsqlite3-dev zlib1g-dev \
python-minimal
@gdevanla
gdevanla / revset_generator.py
Created May 4, 2018
Using python function call syntax to generated 'revsets' needed by mercurial
View revset_generator.py
'''
Module that can generate revset expressions required by Hg from python function call structures.
'''
def _wrap(outer_fn, *args):
args = args or ''
if args:
args = ", ".join(args)
return '{}({})'.format(outer_fn, args)
View machine_setup.txt
Remapping keys
https://askubuntu.com/questions/149971/how-do-you-remap-a-key-to-the-caps-lock-key-in-xubuntu
sudo vi /etc/default/keyboard
then find the line that starts with XKBOPTIONS, and add ctrl:nocaps to make Caps Lock an additional Control key or ctrl:swapcaps to swap Caps Lock and Control.
For example, mine looks like
View ycombinator.py
# coding: utf-8
# Python code to demonstrate the Y-combinator using
# the working example presented by Jim Weirich.
# https://www.infoq.com/presentations/Y-Combinator
def demo():
fact_1 = lambda n: 1 if n == 0 else (n * fact_1 (n - 1))
@gdevanla
gdevanla / y-combinator-racket.rkt
Created Feb 7, 2018
Y-Combinator description in Racket
View y-combinator-racket.rkt
;; lambda expression do not have any assignments
;; so we will use the form where there is not lambda expressions
((lambda ()
(define (adder n) (+ n 1))
(define (mult3 n) (* n 3))
(mult3 (adder 10))
))
;; create make-adder and compose using higher-order functions