Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
from ast import (
NodeTransformer,
arguments,
arg,
Lambda,
parse,
In,
Call,
Expression,
fix_missing_locations,
@dhilst
dhilst / bnf.py
Last active December 6, 2020 14:18
import sys
from sly import Lexer, Parser # type: ignore
from collections.abc import Iterable
# lamb -> LAMB ID DOT term
# lamb -> appl
# appl -> appl term
# appl -> term
# term -> LPAR lamb RPAR
# term -> ID
@dhilst
dhilst / bnf.py
Last active December 6, 2020 13:40
Parser BNF and output python module that can parse that grammar using SLY project
import sys
from sly import Lexer, Parser
from collections.abc import Iterable
# lamb -> LAMB ID DOT term
# lamb -> appl
# appl -> appl term
# appl -> term
# term -> LPAR lamb RPAR
# term -> ID
eval((λx.x) 1)
eval((λx.x))
eval(1)
appl((λx.1), 1) => 1
eval((λx.(λy.x)) 1 2)
eval((λx.(λy.x)) 1)
eval((λx.(λy.x)))
eval(1)
appl((λx.(λy.1)), 1) => (λy.1)
#!/Users/gecko/code/deployment/minsible
- debug:
@dhilst
dhilst / minsible
Last active November 27, 2020 19:51
#!/bin/sh
#
# Wrapper over ansible include tasks to make simple executable playbooks
# example https://gist.github.com/e39284344e3fd29b3202571678b6a343
task="${PWD}/$1"
ansible localhost -m include_tasks -a file=$task -c local -i /dev/null
@dhilst
dhilst / Program.cs
Last active November 21, 2020 13:13
Typed primitives in c#
using System;
namespace hello
{
// A typed primitive it narrows the type of primitive
class TypedPrim<T>
{
public T Value { get; set; }
public static implicit operator T(TypedPrim<T> v) => v.Value;
public static explicit operator TypedPrim<T>(T v) => new TypedPrim<T>() { Value = v };
@dhilst
dhilst / gist:858244a7f6b06c6929a0b022c362ff53
Created August 16, 2020 22:27
parse_combinator in python
from typing import *
import re
Result = Tuple[str, Any]
Parser = Callable[[str], Result]
class ParseError(Exception):
pass
def get(obj, attr, default=None):
"""
Fetch an attribute deeply nested on an object or dict, return `default` if not found
>>> class Foo: pass
>>> f = Foo()
>>> f.a = Foo()
>>> f.a.b = Foo()
>>> f.a.b.c = True
# test with `nc -kl 3000`
# write to nc terminal to send data
import socket
import sys
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Socket successfully created")
except socket.error as err:
print("socket creation failed with error %s" %(err))