Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
馃樆

Daniel Hilst dhilst

馃樆
View GitHub Profile
@dhilst
dhilst / Result.cs
Created May 17, 2021 23:25
Result class in C#
using System;
namespace TodoApi
{
/// <summary>
/// A generic result class that should enough
/// to get rid of exceptions and be general enough
/// for handling all kind of errors.
///
/// User is forced to handle error case to get success
@dhilst
dhilst / object.vim
Created May 15, 2021 03:08
OOP in VimL
function MyClass() abort
let this = {}
function this.setA() dict
let self.a = 1100
endfunc
function this.method() dict
return self.a
endfunc
@dhilst
dhilst / lambda_nums.py
Created May 12, 2021 20:00
Church encoding sketch in python
nums = [
(lambda f, x: x),
(lambda f, x: f(x)),
(lambda f, x: f(f(x))),
]
result = 0
calls = []
def f(x):
class sym:
def __init__(self, name):
self.name = name
def __str__(self):
return f":{self.name}"
def builtin_func(name):
def inner(f):
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