Skip to content

Instantly share code, notes, and snippets.

gdevanla /
Last active Oct 27, 2021
Parser Combinator in Python - Notes
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)
loop :: HaskellLineT
loop = do
minput <- getInputLine "%"
when (isNothing minput) loop
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
from airflow.models import TaskInstance
gdevanla /
Created Jun 27, 2018
Install Python 3.6.5 in Ubuntu 16+
export PYTHON_VERSION=3.6.5
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 \
gdevanla /
Created May 4, 2018
Using python function call syntax to generated 'revsets' needed by mercurial
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
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
# coding: utf-8
# Python code to demonstrate the Y-combinator using
# the working example presented by Jim Weirich.
def demo():
fact_1 = lambda n: 1 if n == 0 else (n * fact_1 (n - 1))
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